BvS Thousand Separator

Adds thousand separators to numbers

目前為 2014-09-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           BvS Thousand Separator
// @namespace      BvS
// @version        1.0
// @description    Adds thousand separators to numbers
// @include        http://*animecubed.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);