UniCyrConv

By Eugeni Dodonov Last update May 7, 2006 — Installed 357 times.
// UniCyrConv
// version 0.1 BETA!
// 2006-05-06
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script that converts bad unicode cyrillic
// characters to correct ones.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "DumbQuotes", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          UniCyrConv
// @namespace     http://eugeni.dodonov.net/projects/unicyrconv/
// @description   Transforms bad russian unicode into valid characters
// @include       http://www.google.com/bookmarks/*
// ==/UserScript==
//
// --------------------------------------------------------------------
//
//

/* BEGIN LICENSE BLOCK
Copyright (C) 2006 Eugeni Dodonov

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You can download a copy of the GNU General Public License at
http://diveintomark.org/projects/greasemonkey/COPYING
or get a free printed copy by writing to the Free Software Foundation,
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
END LICENSE BLOCK */

(function() {
    var replacements, regex, key, textnodes, node, i, s;

    replacements = {
	"%u0410":"А",
	"%u0430":"а",
	"%u0411":"Б",
	"%u0431":"б",
	"%u0412":"В",
	"%u0432":"в",
	"%u0413":"Г",
	"%u0433":"г",
	"%u0414":"Д",
	"%u0434":"д",
	"%u0415":"Е",
	"%u0435":"е",
	"%u0416":"Ж",
	"%u0436":"ж",
	"%u0417":"З",
	"%u0437":"з",
	"%u0418":"И",
	"%u0438":"и",
	"%u0419":"Й",
	"%u0439":"й",
	"%u041A":"К",
	"%u043A":"к",
	"%u041B":"Л",
	"%u043B":"л",
	"%u041C":"М",
	"%u043C":"м",
	"%u041D":"Н",
	"%u043D":"н",
	"%u041E":"О",
	"%u043E":"о",
	"%u041F":"П",
	"%u043F":"п",
	"%u0420":"Р",
	"%u0440":"р",
	"%u0421":"С",
	"%u0441":"с",
	"%u0422":"Т",
	"%u0442":"т",
	"%u0423":"У",
	"%u0443":"у",
	"%u0424":"Ф",
	"%u0444":"ф",
	"%u0425":"Ð¥",
	"%u0445":"х",
	"%u0426":"Ц",
	"%u0446":"ц",
	"%u0427":"Ч",
	"%u0447":"ч",
	"%u0428":"Ш",
	"%u0448":"ш",
	"%u0429":"Щ",
	"%u0449":"щ",
	"%u042A":"Ъ",
	"%u044A":"ъ",
	"%u042B":"Ы",
	"%u044B":"ы",
	"%u042C":"Ь",
	"%u044C":"ь",
	"%u042D":"Э",
	"%u044D":"э",
	"%u042E":"Ю",
	"%u044E":"ю",
	"%u042F":"Я",
	"%u044F":"я"
        };
    regex = {};
    for (key in replacements) {
        regex[key] = new RegExp(key, 'gi');
    }

    textnodes = document.evaluate(
        "//body//text()",
        document,
        null,
        XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
        null);
    for (i = 0; i < textnodes.snapshotLength; i += 1) {
        node = textnodes.snapshotItem(i);
        s = node.data;
        for (key in replacements) {
            s = s.replace(regex[key], replacements[key]);
        }
        node.data = s;
    }
})();

//
// ChangeLog
// 2006-05-06 - 0.1 - First version
//