// ==UserScript==
// @name Gamespot screenshot windows fix
// @namespace http://www.gamepsot.com/fix
// @description Fixes Gamespot's screenshot window when it's too small.
// @include http://www.gamespot.com/*
// ==/UserScript==
reIsScreenshot = /^http:\/\/www\.gamespot\.com\/pages\/image_viewer/;
//1st part: If in screenshot page, enlarge image container. + enlarge Window (this usually
// won't work because FF doesn't allow JS to change window's size. Hence the original
// difficulty -- Gamespot's own script (resizing window) simply didn't work. see 2nd part for true fix.)
if (reIsScreenshot.test(location.href)) {
//GM_log("active in a screenshot page");
var thisElement = document.getElementById("main_image_wrapper");
if (thisElement) {
thisElement.style.height = "1000px";
}
thisElement = document.getElementById("main_image");
if (thisElement) {
thisElement.onload = "";
thisElement.addEventListener('load', function(event) {
var screenwidth = screen.availWidth;
var screenheight = screen.availHeight;
var newwidth = screenwidth;
var newheight = screenheight - 10;
var topPos = (window.screenTop) ? window.screenTop : window.screenY;
var leftPos = (window.screenLeft) ? window.screenLeft : window.screenX;
var moveWin = false;
if (newwidth > (screenwidth - leftPos)) {
leftPos = 0;
moveWin = true;
}
if (newheight > (screenheight - topPos)) {
topPos = 0;
moveWin = true;
}
if(moveWin){
window.moveTo(leftPos,topPos);
}
resizeTo(newwidth,newheight);
var thisElement = document.getElementById("main_image_wrapper");
if (thisElement) {
thisElement.style.height = "1000px";
}
}, true);
}
} else { //********** if not a screenshot page:
//2nd part: inside pages which contain Gallery thumbnails, hook into their <A>s and
// replace their function of opening a new window with my own.
// My own will simply open a window which is the largest possible. Thus solving
// the difficulty of not being able to resize it later on.
// (I actually believe Gamespot should adopt this fix, and change their JS accordingly -- making my hack redundant. - Lior)
//GM_log("active on non-screenshot page");
var MyXPath = "//a[contains(@href,'open_image_viewer')]";
//## Run the loop on all appropriate links.
var allElements = document.evaluate(MyXPath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (f = 0; f < allElements.snapshotLength; f++) {
thisElement = allElements.snapshotItem(f);
//GM_log("ITEMS <A> were found");
thisElement.addEventListener('click', function(event) {
///////////////////////////////////////////
//javascript:open_image_viewer('934690',2)
reMatches = /open_image_viewer\(\'(\d{4,})\'\,(\d{1,})/.exec(this.href); //THIS WORKS.
if (reMatches == null) {/*GM_log("No Matches.");*/ return true;} //if no correct parameters found -- open link as usual.
//GM_log("Matches! are: "+reMatches[1]+" and "+reMatches[2]);
//The hacked function:
// FROM http://www.gamespot.com/js/global.js?10 FUNCTION function open_image_viewer
//pid,img,sid,path,caption,numimg,rgroup
var pid=reMatches[1];
var img=reMatches[2];
var sid="undefined";
var rgroup = '';
var page = '/pages/image_viewer/frame_lead.php?pid=' + pid + '&img=' + img + '&sid=' + sid + rgroup;
/*if(path) {
page += '&path=' + path;
}
if(caption) {
page += '&caption=' + caption;
}
if(numimg) {
page += '&numimg=' + numimg;
}*/
var screenwidth = screen.availWidth;
var screenheight = screen.availHeight;
var newwidth = screenwidth;
var newheight = screenheight - 10;
//GM_log("Open fabulous window: "+newwidth+" and "+newheight);
var x = window.open(page, '_blank', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width='+newwidth+',height='+newheight+',left=0,top=0');
//this.href = reMatches[0];
event.preventDefault();
return false;
///////////////////////////////////////////
}, true); //end function.
}//end for all <A>
}//end if