autoSpurdo

Convert text on every page into spurdo

目前為 2015-11-16 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name autoSpurdo
// @description Convert text on every page into spurdo
// @namespace installgen2
// @include *
// @version 5
// @grant none
// ==/UserScript==
(function(){
	var replacements = [
		["wh", "w"],
		["th", "d"],
		["af", "ab"],
		["ap", "ab"],
		["ca", "ga"],
		["ck", "gg"],
		["co", "go"],
		["ev", "eb"],
		["ex", "egz"],
		["et", "ed"],
		["iv", "ib"],
		["it", "id"],
		["ke", "ge"],
		["nt", "nd"],
		["op", "ob"],
		["ot", "od"],
		["po", "bo"],
		["pe", "be"],
		["pi", "bi"],
		["up", "ub"],
		["va", "ba"],
		["ck", "gg"],
		["cr", "gr"],
		["kn", "gn"],
		["lt", "ld"],
		["mm", "m"],
		["nt", "dn"],
		["pr", "br"],
		["ts", "dz"],
		["tr", "dr"],
		["bs", "bz"],
		["ds", "dz"],
		["es", "es"],
		["fs", "fz"],
		["gs", "gz"],
		[" is", " iz"],
		["ls", "lz"],
		["ms", "mz"],
		["ns", "nz"],
		["rs", "rz"],
		["ss", "sz"],
		["ts", "tz"],
		["us", "uz"],
		["ws", "wz"],
		["ys", "yz"],
		["alk", "olk"],
		["ing", "ign"],
		["ic", "ig"],
		["ng", "nk"],
		["kek", "geg"],
		["epic", "ebin"],
		["some", "sum"],
		["meme", "maymay"],
	];
	
	var ebinFaces = [
		":D",
		":DD",
		":DDD",
		":-D",
		"XD",
		"XXD",
		"XDD",
		"XXDD"
	];
	
	function getEbinFace() {
		return ebinFaces[Math.floor(Math.random() * ebinFaces.length)];
	}
	
	walk(document.body);

	function walk(node) {
		// I stole this function from here:
		// http://is.gd/mwZp7E
		var child,
		next;
		switch (node.nodeType) {
			case 1: // Element
			case 9: // Document
			case 11: // Document fragment
			child = node.firstChild;
			while (child) {
				next = child.nextSibling;
				walk(child);
				child = next;
			}
			break;
			case 3: // Text node
			spurdoNode(node);
			break;
		}
	}

	function spurdoNode(node) {
		var text = node.nodeValue;		
		
		text = text.toLowerCase();
		replacements.forEach(function (filter) {
			var replaceFrom = new RegExp(filter[0], "gm"),
			replaceTo = filter[1];
			text = text.replace(replaceFrom, replaceTo);
		});
		
		while (text.match(/\.|,(?=\s|$)/m)) {
			text = text.replace(/\.|,(?=\s|$)/m, " " + getEbinFace());
		}
		
		node.nodeValue = text;
	}
})();