By Lior Zur
—
Last update
Apr 6, 2007
—
Installed
1,916 times.
// ==UserScript==// @name Gamespot screenshot view-as-image// @namespace http://www.gamepsot.com/fix// @description Lets you see Gamespot's screenshots as plain images.// @include http://www.gamespot.com/*// @include http://uk.gamespot.com/*// @include http://www.uk.gamespot.com/*//// Released under the GPL license.// Copyright: Lior Zur, 2007. //// (This was a hell to write.)// ==/UserScript==// Functions:function $(id) { return document.getElementById(id);}function $x(p, context) { if (!context) context = document; var i, arr = [], xpr = document.evaluate(p, context, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); for (i = 0; item = xpr.snapshotItem(i); i++) arr.push(item); return arr;}//End functionsreIsScreenshot = /^http:\/\/www\.gamespot\.com\/pages\/image_viewer/;var allElements, thisElement;if (!reIsScreenshot.test(location.href)) {allElements = $x("//a[contains(@href,'open_image_viewer')]");if (allElements.length > 0){ //Construct screenshot viewer page query: var sampleImageURL = allElements[0].href; var reMatches = /open_image_viewer\(\'(\d{4,})\'\,(\d{1,})/.exec(sampleImageURL); //THIS WORKS. if (!reMatches) return false; var pid=reMatches[1]; var img=reMatches[2]; var sid="undefined"; var rgroup = ''; var pageRequest = 'http://www.gamespot.com/pages/image_viewer/frame_lead.php?pid=' + pid + '&img=' + img + '&sid=' + sid + rgroup; //Insert "please wait" var newElement = document.createElement('div'); newElement.innerHTML = "<div id = 'gmpleasewait' style='vertical-align: middle; font-size: 12px; display: block; position: absolute; right: 0; top: 0; color = white; text-align: center; background: green; border: white 1px solid; width: 200px; height: 20px;'>Parsing screenshot links...</div>"; thisElement = $("gnenav"); if (thisElement){ thisElement.parentNode.insertBefore(newElement, thisElement); } //Request screenshot viewer page: GM_xmlhttpRequest({ method: 'GET', url: pageRequest, headers: {'User-agent': 'Mozilla/4.0 (compatible)', 'Accept': 'application/atom+xml,application/xml,text/xml',}, onload: function(responseDetails) { /////////////////////////////////////////// var response = responseDetails.responseText; var screenPath = new Array (); // Look through the response for the screen paths' array. // Put it into our own array, screenPath. //screens[18]['screen_path'] = gs_img_url + '2006/270/935084_20060928_screen008.jpg'; var reScreenshotLink = /\[(\d{1,3})\]\[[\"\']screen_path[\"\'][^\"\']*[\"\']([^\"\']+)[\"\']/gi; //The loop depends on the RegEx being a variable! ALSO on set to __/gi__ (exec stores in this variable "LastIndex". see http://www.webreference.com/js/column5/methods.html) for (var i = 1; i < 1000; i++){ var reMatches = reScreenshotLink.exec(response); if (reMatches){ screenPath[parseInt(reMatches[1],10)] = reMatches[2]; } else break; } // Run the loop on all appropriate links. // For each link, get its image number, and assign the corresponding URL from the array. allElements = $x("//a[contains(@href,'open_image_viewer')]"); for (f = 0; f < allElements.length; f++) { thisElement = allElements[f]; reMatches = /open_image_viewer\(\'(\d{4,})\'\,(\d{1,})/.exec(thisElement.href); //THIS WORKS. thisElement.href = "http://img.gamespot.com/gamespot/images/" + screenPath[parseInt(reMatches[2],10)]; thisElement.style.border = "#87B52A 1px solid"; thisElement.style.background = "#87B52A"; } //Remove "please wait" thisElement = $('gmpleasewait'); if (thisElement){ thisElement.parentNode.removeChild(thisElement); } /////////////////////////////////////////// } // End function. }); //End xmlHttpRequest} //End if -- A screenshot link exists.}//end global if