GameFAQs post numberer

Numbers posts on gameFAQs.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        GameFAQs post numberer
// @version     1
// @author      King of Cats
// @namespace   Cats
// @description Numbers posts on gameFAQs.
// @include     http://www.gamefaqs.com/boards/*
// @grant       none
// ==/UserScript==

// The script assumes you have GameFAQs' numbering disabled; probably doubles up on post numbers or breaks otherwise.

var postNumbers = document.evaluate('//td[contains(@class,"author")]//a[@name]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

if (postNumbers.snapshotItem(0) != null) {
	
	function padMe(num) {
		var pad = num + '';
		while(pad.length < 3) {
				pad = "0" + pad;
			}
		return pad;
	}
	
	for (var i = 0; i < postNumbers.snapshotLength; i++) {
		var number = postNumbers.snapshotItem(i).getAttribute("name");
		
		var leftOfMessage = (document.getElementsByClassName("msg_stats_left")[0] != null);
		if (!leftOfMessage) {
			var appendedDivider = document.createTextNode(" | ");
			postNumbers.snapshotItem(i).parentNode.appendChild(appendedDivider);
			
			var appendedNumber = document.createTextNode("#"+padMe(number));
			postNumbers.snapshotItem(i).parentNode.appendChild(appendedNumber);
		} else {
			var appendedNumber = document.createTextNode("#"+padMe(number));
			var lineBreak = document.createElement("br");
			postNumbers.snapshotItem(i).parentNode.insertBefore(lineBreak,postNumbers.snapshotItem(i).parentNode.childNodes[0]);
			postNumbers.snapshotItem(i).parentNode.insertBefore(appendedNumber,postNumbers.snapshotItem(i).parentNode.childNodes[0]);
		}
	}
}