Shift-JIS Letter Fixer

Replaces Shift-JIS encoded Latin letters with Unicode equivalents, making pages a bit more searchable

目前为 2016-01-05 提交的版本。查看 最新版本

// ==UserScript==
// @name          Shift-JIS Letter Fixer
// @namespace     DoomTay
// @description   Replaces Shift-JIS encoded Latin letters with Unicode equivalents, making pages a bit more searchable
// @version       1.0.1
// @grant         none

// ==/UserScript==

var replacementTable = [
	["A","A"],
	["B","B"],
	["C","C"],
	["D","D"],
	["E","E"],
	["F","F"],
	["G","G"],
	["H","H"],
	["I","I"],
	["J","J"],
	["K","K"],
	["L","L"],
	["M","M"],
	["N","N"],
	["O","O"],
	["P","P"],
	["Q","Q"],
	["R","R"],
	["S","S"],
	["T","T"],
	["U","U"],
	["V","V"],
	["W","W"],
	["X","X"],
	["Y","Y"],
	["Z","Z"],
	["a","a"],
	["b","b"],
	["c","c"],
	["d","d"],
	["e","e"],
	["f","f"],
	["g","g"],
	["h","h"],
	["i","i"],
	["j","j"],
	["k","k"],
	["l","l"],
	["m","m"],
	["n","n"],
	["o","o"],
	["p","p"],
	["q","q"],
	["r","r"],
	["s","s"],
	["t","t"],
	["u","u"],
	["v","v"],
	["w","w"],
	["x","x"],
	["y","y"],
	["z","z"],
	["0","0"],
	["1","1"],
	["2","2"],
	["3","3"],
	["4","4"],
	["5","5"],
	["6","6"],
	["7","7"],
	["8","8"],
	["9","9"]
	];
	
function replaceText(node, scan, replacement) {
	var nodes = node.childNodes;
	for (var n=0; n<nodes.length; n++) {				
		if(nodes[n].nodeType == Node.TEXT_NODE && nodes[n].textContent.trim().indexOf(scan) > -1)
		{
			while(nodes[n].textContent.indexOf(scan) > -1) nodes[n].textContent = nodes[n].textContent.replace(scan,replacement);
		}
		
		//Nothing in this node. Look at the children of this node.
		else
		{
			replaceText(nodes[n],scan,replacement);
		}
	}
}

for(var i = 0; i < replacementTable.length; i++)
{
	replaceText(document.body,replacementTable[i][0], replacementTable[i][1]);
}