User:地球发动机/monobook.js
出自維基百科,自由嘅百科全書
< User:地球发动机
注意:喺儲存之後,你可能要先略過你嘅瀏覽器快取去睇到更改。Mozilla / Firefox / Safari: 㩒住Shift掣再撳重新載入,又或者㩒Ctrl-Shift-R(喺蘋果Mac中㩒Cmd-Shift-R掣); IE: 㩒住Ctrl掣再撳重新整理,又或者㩒Ctrl-F5掣; Konqueror: 就咁以撳個重載掣,又或者㩒F5; Opera嘅用戶可能需要先喺工具→喜好設定之中清佢哋嘅快取。
//<div><pre><nowiki> function MyaddLoadEvent(func) { if (window.addEventListener) window.addEventListener("load", func, false); else if (window.attachEvent) window.attachEvent("onload", func); } function checkpath(url) { var reg=/^\/w(\/|iki\/).*/; if(reg.test(url))return true; } function getpathfromurl(url) { var ret=new String(url); var path3=/^([A-Za-z0-9_]+):\/\/([^\/]*)\/(.*)/; return ret.replace(path3,"$3"); } function getpath(olink){ if(is_gecko){ return olink.pathname; } var reg=/^.*href="([^"]+)".*$/; return getpathfromurl(olink.outerHTML.replace(reg,"$1")); } function getpath1(url) { var ret=new String(url); var path1=/^([A-Za-z0-9_]+):\/\/([^\/]*)\/([^\/]*)\/(.*)/; var tmp=new String(url); ret=ret.replace(path1,"$3"); if(ret==tmp) { return ret.replace(/^([A-Za-z0-9_]+):\/\/([^\/]*)\/(.*)/,"$3"); } return ret; } function getpath2(url) { var ret=new String(url); var path2=/^([A-Za-z0-9_]+):\/\/([^\/]*)\/([^\/]*)\/([^\/]*)\/(.*)/; var tmp=new String(url); ret=ret.replace(path2,"$4"); if(ret==tmp){ return ret.replace(/^([A-Za-z0-9_]+):\/\/([^\/]*)\/([^\/]*)\/(.*)/,"$4"); }; return ret; } function update(url) { var ret=new String(url); var ud=/^http:\/\/([^\.\/]*).(wikimedia|wikipedia|wiktionary|wikibooks|wikiquote|wikisource|wikinews).org\/(.*)/; return ret.replace(ud,"https://secure.wikimedia.org/$2/$1/$3"); } function updateurl(olink) { if(is_gecko) { return update(olink.href); } var reg=/^.*href="([^"]+)".*$/; return update(olink.outerHTML.replace(reg,"$1")); } function fixup(obj) { var path=getpath(obj); if(obj.protocol=="https:" && checkpath(path)) obj.href="/"+getpath1(location)+"/"+getpath2(location)+path; else obj.href=updateurl(obj); obj.onmouseover=obj.oldfun; } function checklink(olink) { if(olink.hostname=="upload.wikimedia.org")return; if(olink.hostname=="mail.wikipedia.org")return; if(olink.protocol=="https:") { if(olink.hostname=="secure.wikimedia.org") { if(!checkpath(olink.pathname))return; } } olink.oldfun=olink.onmouseover; if(olink.oldfun) { olink.onmouseover=function(){this.oldfun();fixup(this);} } else olink.onmouseover=function(){fixup(this);} } function updatehook() { for(i=0;i+document.links.length;++i) { checklink(document.links[i]); } } if(location.hostname=="secure.wikimedia.org") { MyaddLoadEvent(updatehook); }//</nowiki></pre></div>