// ==UserScript== // @name Switch Traditional Chinese and Simplified Chinese // @name:zh-CN 简繁自由切换 // @name:zh-TW 繁簡自由切換 // @namespace hoothin // @version 0.3 // @description Just Switch Traditional Chinese and Simplified Chinese // @description:zh-CN 通过快捷键快速转换网页中的简体中文与繁体中文 // @description:zh-TW 通過快捷鍵快速轉換網頁中的簡體中文與繁體中文 // @author hoothin // @include * // @grant GM_setValue // @grant GM_getValue // @grant GM_registerMenuCommand // @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=rixixi@sina.com&item_name=Greasy+Fork+donation // @contributionAmount 1 // @downloadURL none // ==/UserScript== (function() { 'use strict'; var auto=true;//是否自動切換至OS使用的默認語言 var shortcutKey=119;//快捷鍵keyCode,禁用設爲0 var lang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage; lang = lang.toLowerCase(); var isSimple = (lang === "zh-cn" || lang === "zh-hans" || lang === "zh-sg" || lang === "zh-my"); var action = 0;//1:noChange, 2:showSimplified, 3:showTraditional function stranText(txt){ if(!txt)return ""; if(action == 2){return simplized(txt);} else if(action == 3){return traditionalized(txt);} } function stranBody(pNode){ var childs; if(pNode){ childs=pNode.childNodes; }else{ childs=document.documentElement.childNodes; } if(childs) for(var i=0;i 10000 && index != -1) str+=tcStr.charAt(index); else str+=char; } return str; } function simplized(orgStr){ var str='', index, char; for(var i=0;i 10000 && index != -1) str+=scStr.charAt(index); else str+=char; } return str; } function setLanguage(){ GM_setValue("action" + location.hostname.toString().replace(/\./g,""), action); switch(action){ case 1: alert("已切换至原始字符集"); location.reload(); break; case 2: alert("已切换至简体中文"); break; case 3: alert("已切換至繁體中文"); break; } if(action > 1){ stranBody(); } } function switchLanguage(){ if(isSimple){ action++; action=action>3?1:action; }else{ action--; action=action<1?3:action; } setLanguage(); } var saveAction=GM_getValue("action" + location.hostname.toString().replace(/\./g,"")); action=saveAction?saveAction:(isSimple?2:3); if(auto && action > 1){ setTimeout(stranBody,50); } document.addEventListener("keydown", function(e) { if(e.keyCode == shortcutKey && e.ctrlKey) { action=action==2?3:2; setLanguage(); } }); GM_registerMenuCommand("繁簡切換", switchLanguage); })();