BvS Thousand Separator

Adds thousand separators to numbers

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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           BvS Thousand Separator
// @namespace      BvS
// @version        1.2
// @history        1.2 New domain - animecubedgaming.com - Channel28
// @history        1.1 Now https compatible (Updated by Channel28)
// @description    Adds thousand separators to numbers
// @include        http*://*animecubed.com/billy/bvs/*
// @include        http*://*animecubedgaming.com/billy/bvs/*
// @grant          none
// ==/UserScript==

// "\u00a0" = non-breaking space
const separator = ",";

function separate(txt)
{
	return txt.replace(/((\b\d{1,3})|(\d))(?=(\d)+\b)/g, "$&" + separator);
}

function replace()
{
	var parents = ['b', 'i', 'center', 'div', 'font', 'form', 'label', 'li', 'span', 'td'];
	var eval = "//text()[(parent::" + parents.join(" or parent::") + ")]";
	var textnodes = document.evaluate(eval, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
	var i = 0;
	for (var node = textnodes.snapshotItem(i); node; node = textnodes.snapshotItem(++i))
		node.textContent = separate(node.textContent);
}

window.addEventListener("load", replace, false);