Gamefaqs - Screenshotgallery pagelinks

By GFuser Last update Jul 6, 2011 — Installed 257 times.

There are 8 previous versions of this script.

// ==UserScript==
// @name		Gamefaqs - Screenshotgallery pagelinks
// @namespace	http://userscripts.org/users/63277
// @description	This script will place links to all pages on a screenshotgallery.
// @include		http://www.gamefaqs.com/*/images*
// @exclude		http://www.gamefaqs.com/*/images/gs_screen*
// @exclude		http://www.gamefaqs.com/*/images/screen*
// @exclude		http://www.gamefaqs.com/*/images/box*
// @version		2.2 2011-07-06
// ==/UserScript==

function getNrOfPics()
{
	var totalPics = 0;
	var gsPics = document.evaluate('//a[contains(attribute::href,"screenindex.html")]',document,null,XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
	if (gsPics)
		totalPics += parseInt(gsPics.innerHTML.match(/\d+/));
	var userPics = document.querySelector('meta[name=description]');
	if (userPics)
		var userPics2 = userPics.getAttribute('content').match(/\d+(?=\suser)/i);
	if (userPics2)
		totalPics += parseInt(userPics2);
	return totalPics;
}
function writeLinks(pics)
{
	var pages = Math.ceil(pics/20)-1;
	if (pages>1)
	{
		var div = document.querySelector('div[class="pod game_imgs"]');
		if (div)
		{
			var newDiv = document.createElement('div');
			newDiv.style.textAlign = 'center';
			var place = location.href.replace(/\?page=\d+/i,'');
			addLink(newDiv,place,'first');
			var nrOfPages = pages-1;
			for (var i=0; i<nrOfPages; ++i)
				addLink(newDiv,place+'?page='+(i+1),i+2);
			addLink(newDiv,place+'?page='+pages,'last');
			div.appendChild(newDiv);
		}
	}
}
function addLink(d,url,text)
{
	var a = document.createElement('a');
	a.href = url;
	a.innerHTML = text;
	a.style.padding = '0px 2px';
	a.style.fontSize = '10pt';
	if (location.href==url)
		a.style.fontWeight = 'normal';
	d.appendChild(a);
	if (!isNaN(text) && ((text/20)==Math.round(text/20)))
		d.appendChild(document.createElement('br'));
}
writeLinks(getNrOfPics());