GameFAQs post numberer

Numbers posts on gameFAQs.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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]);
		}
	}
}