GameFAQs post numberer

Numbers posts on gameFAQs.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

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

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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