📄 wikibits.js
字号:
// MediaWiki JavaScript support functionsvar clientPC = navigator.userAgent.toLowerCase(); // Get client infovar is_gecko = /gecko/.test( clientPC ) && !/khtml|spoofer|netscape\/7\.0/.test(clientPC);var webkit_match = clientPC.match(/applewebkit\/(\d+)/);if (webkit_match) { var is_safari = clientPC.indexOf('applewebkit') != -1 && clientPC.indexOf('spoofer') == -1; var is_safari_win = is_safari && clientPC.indexOf('windows') != -1; var webkit_version = parseInt(webkit_match[1]);}var is_khtml = navigator.vendor == 'KDE' || ( document.childNodes && !document.all && !navigator.taintEnabled );// For accesskeys; note that FF3+ is included here!var is_ff2 = /firefox\/[2-9]|minefield\/3/.test( clientPC );// These aren't used here, but some custom scripts rely on themvar is_ff2_win = is_ff2 && clientPC.indexOf('windows') != -1;var is_ff2_x11 = is_ff2 && clientPC.indexOf('x11') != -1;if (clientPC.indexOf('opera') != -1) { var is_opera = true; var is_opera_preseven = window.opera && !document.childNodes; var is_opera_seven = window.opera && document.childNodes; var is_opera_95 = /opera\/(9.[5-9]|[1-9][0-9])/.test( clientPC );}// Global external objects used by this script./*extern ta, stylepath, skin */// add any onload functions in this hook (please don't hard-code any events in the xhtml source)var doneOnloadHook;if (!window.onloadFuncts) { var onloadFuncts = [];}function addOnloadHook(hookFunct) { // Allows add-on scripts to add onload functions if(!doneOnloadHook) { onloadFuncts[onloadFuncts.length] = hookFunct; } else { hookFunct(); // bug in MSIE script loading }}function hookEvent(hookName, hookFunct) { if (window.addEventListener) { window.addEventListener(hookName, hookFunct, false); } else if (window.attachEvent) { window.attachEvent("on" + hookName, hookFunct); }}function importScript(page) { return importScriptURI(wgScript + '?action=raw&ctype=text/javascript&title=' + encodeURIComponent(page.replace(/ /g,'_')));} var loadedScripts = {}; // included-scripts trackerfunction importScriptURI(url) { if (loadedScripts[url]) { return null; } loadedScripts[url] = true; var s = document.createElement('script'); s.setAttribute('src',url); s.setAttribute('type','text/javascript'); document.getElementsByTagName('head')[0].appendChild(s); return s;} function importStylesheet(page) { return importStylesheetURI(wgScript + '?action=raw&ctype=text/css&title=' + encodeURIComponent(page.replace(/ /g,'_')));} function importStylesheetURI(url) { return document.createStyleSheet ? document.createStyleSheet(url) : appendCSS('@import "' + url + '";');} function appendCSS(text) { var s = document.createElement('style'); s.type = 'text/css'; s.rel = 'stylesheet'; if (s.styleSheet) s.styleSheet.cssText = text //IE else s.appendChild(document.createTextNode(text + '')) //Safari sometimes borks on null document.getElementsByTagName('head')[0].appendChild(s); return s;}// special stylesheet linksif (typeof stylepath != 'undefined' && typeof skin != 'undefined') { if (is_opera_preseven) { importStylesheetURI(stylepath+'/'+skin+'/Opera6Fixes.css'); } else if (is_opera_seven && !is_opera_95) { importStylesheetURI(stylepath+'/'+skin+'/Opera7Fixes.css'); } else if (is_khtml) { importStylesheetURI(stylepath+'/'+skin+'/KHTMLFixes.css'); }}if (wgBreakFrames) { // Un-trap us from framesets if (window.top != window) { window.top.location = window.location; }}// for enhanced RecentChangesfunction toggleVisibility(_levelId, _otherId, _linkId) { var thisLevel = document.getElementById(_levelId); var otherLevel = document.getElementById(_otherId); var linkLevel = document.getElementById(_linkId); if (thisLevel.style.display == 'none') { thisLevel.style.display = 'block'; otherLevel.style.display = 'none'; linkLevel.style.display = 'inline'; } else { thisLevel.style.display = 'none'; otherLevel.style.display = 'inline'; linkLevel.style.display = 'none'; }}function showTocToggle() { if (document.createTextNode) { // Uses DOM calls to avoid document.write + XHTML issues var linkHolder = document.getElementById('toctitle'); if (!linkHolder) { return; } var outerSpan = document.createElement('span'); outerSpan.className = 'toctoggle'; var toggleLink = document.createElement('a'); toggleLink.id = 'togglelink'; toggleLink.className = 'internal'; toggleLink.href = 'javascript:toggleToc()'; toggleLink.appendChild(document.createTextNode(tocHideText)); outerSpan.appendChild(document.createTextNode('[')); outerSpan.appendChild(toggleLink); outerSpan.appendChild(document.createTextNode(']')); linkHolder.appendChild(document.createTextNode(' ')); linkHolder.appendChild(outerSpan); var cookiePos = document.cookie.indexOf("hidetoc="); if (cookiePos > -1 && document.cookie.charAt(cookiePos + 8) == 1) { toggleToc(); } }}function changeText(el, newText) { // Safari work around if (el.innerText) { el.innerText = newText; } else if (el.firstChild && el.firstChild.nodeValue) { el.firstChild.nodeValue = newText; }}function toggleToc() { var toc = document.getElementById('toc').getElementsByTagName('ul')[0]; var toggleLink = document.getElementById('togglelink'); if (toc && toggleLink && toc.style.display == 'none') { changeText(toggleLink, tocHideText); toc.style.display = 'block'; document.cookie = "hidetoc=0"; } else { changeText(toggleLink, tocShowText); toc.style.display = 'none'; document.cookie = "hidetoc=1"; }}var mwEditButtons = [];var mwCustomEditButtons = []; // eg to add in MediaWiki:Common.jsfunction escapeQuotes(text) { var re = new RegExp("'","g"); text = text.replace(re,"\\'"); re = new RegExp("\\n","g"); text = text.replace(re,"\\n"); return escapeQuotesHTML(text);}function escapeQuotesHTML(text) { var re = new RegExp('&',"g"); text = text.replace(re,"&"); re = new RegExp('"',"g"); text = text.replace(re,"""); re = new RegExp('<',"g"); text = text.replace(re,"<"); re = new RegExp('>',"g"); text = text.replace(re,">"); return text;}/** * Set the accesskey prefix based on browser detection. */var tooltipAccessKeyPrefix = 'alt-';if (is_opera) { tooltipAccessKeyPrefix = 'shift-esc-';} else if (!is_safari_win && is_safari && webkit_version > 526) { tooltipAccessKeyPrefix = 'ctrl-alt-';} else if (!is_safari_win && (is_safari || clientPC.indexOf('mac') != -1 || clientPC.indexOf('konqueror') != -1 )) { tooltipAccessKeyPrefix = 'ctrl-';} else if (is_ff2) { tooltipAccessKeyPrefix = 'alt-shift-';}var tooltipAccessKeyRegexp = /\[(ctrl-)?(alt-)?(shift-)?(esc-)?(.)\]$/;/** * Add the appropriate prefix to the accesskey shown in the tooltip. * If the nodeList parameter is given, only those nodes are updated; * otherwise, all the nodes that will probably have accesskeys by * default are updated. * * @param Array nodeList -- list of elements to update */function updateTooltipAccessKeys( nodeList ) { if ( !nodeList ) { // skins without a "column-one" element don't seem to have links with accesskeys either var columnOne = document.getElementById("column-one"); if ( columnOne ) updateTooltipAccessKeys( columnOne.getElementsByTagName("a") ); // these are rare enough that no such optimization is needed updateTooltipAccessKeys( document.getElementsByTagName("input") ); updateTooltipAccessKeys( document.getElementsByTagName("label") ); return; } for ( var i = 0; i < nodeList.length; i++ ) { var element = nodeList[i]; var tip = element.getAttribute("title"); if ( tip && tooltipAccessKeyRegexp.exec(tip) ) { tip = tip.replace(tooltipAccessKeyRegexp, "["+tooltipAccessKeyPrefix+"$5]"); element.setAttribute("title", tip ); } }}/** * Add a link to one of the portlet menus on the page, including: * * p-cactions: Content actions (shown as tabs above the main content in Monobook) * p-personal: Personal tools (shown at the top right of the page in Monobook) * p-navigation: Navigation * p-tb: Toolbox * * This function exists for the convenience of custom JS authors. All * but the first three parameters are optional, though providing at * least an id and a tooltip is recommended. * * By default the new link will be added to the end of the list. To * add the link before a given existing item, pass the DOM node of * that item (easily obtained with document.getElementById()) as the * nextnode parameter; to add the link _after_ an existing item, pass * the node's nextSibling instead. * * @param String portlet -- id of the target portlet ("p-cactions", "p-personal", "p-navigation" or "p-tb") * @param String href -- link URL * @param String text -- link text (will be automatically lowercased by CSS for p-cactions in Monobook) * @param String id -- id of the new item, should be unique and preferably have the appropriate prefix ("ca-", "pt-", "n-" or "t-") * @param String tooltip -- text to show when hovering over the link, without accesskey suffix * @param String accesskey -- accesskey to activate this link (one character, try to avoid conflicts) * @param Node nextnode -- the DOM node before which the new item should be added, should be another item in the same list * * @return Node -- the DOM node of the new item (an LI element) or null */function addPortletLink(portlet, href, text, id, tooltip, accesskey, nextnode) { var node = document.getElementById(portlet); if ( !node ) return null; node = node.getElementsByTagName( "ul" )[0]; if ( !node ) return null; var link = document.createElement( "a" ); link.appendChild( document.createTextNode( text ) ); link.href = href; var item = document.createElement( "li" ); item.appendChild( link ); if ( id ) item.id = id; if ( accesskey ) { link.setAttribute( "accesskey", accesskey ); tooltip += " ["+accesskey+"]"; } if ( tooltip ) { link.setAttribute( "title", tooltip ); } if ( accesskey && tooltip ) { updateTooltipAccessKeys( new Array( link ) ); } if ( nextnode && nextnode.parentNode == node ) node.insertBefore( item, nextnode ); else node.appendChild( item ); // IE compatibility (?) return item;}/** * Set up accesskeys/tooltips from the deprecated ta array. If doId * is specified, only set up for that id. Note that this function is * deprecated and will not be supported indefinitely -- use * updateTooltipAccessKey() instead. * * @param mixed doId string or null */function akeytt( doId ) { // A lot of user scripts (and some of the code below) break if // ta isn't defined, so we make sure it is. Explictly using // window.ta avoids a "ta is not defined" error. if (!window.ta) window.ta = new Array; // Make a local, possibly restricted, copy to avoid clobbering // the original. var ta; if ( doId ) { ta = [doId]; } else { ta = window.ta; } // Now deal with evil deprecated ta var watchCheckboxExists = document.getElementById( 'wpWatchthis' ) ? true : false; for (var id in ta) { var n = document.getElementById(id); if (n) { var a = null; var ak = ''; // Are we putting accesskey in it if (ta[id][0].length > 0) { // Is this object a object? If not assume it's the next child. if (n.nodeName.toLowerCase() == "a") { a = n; } else { a = n.childNodes[0]; } // Don't add an accesskey for the watch tab if the watch // checkbox is also available. if (a && ((id != 'ca-watch' && id != 'ca-unwatch') || !watchCheckboxExists)) { a.accessKey = ta[id][0]; ak = ' ['+tooltipAccessKeyPrefix+ta[id][0]+']'; } } else { // We don't care what type the object is when assigning tooltip a = n; ak = ''; } if (a) { a.title = ta[id][1]+ak; } } }}var checkboxes;var lastCheckbox;function setupCheckboxShiftClick() { checkboxes = []; lastCheckbox = null; var inputs = document.getElementsByTagName('input'); addCheckboxClickHandlers(inputs);}function addCheckboxClickHandlers(inputs, start) { if ( !start) start = 0; var finish = start + 250; if ( finish > inputs.length ) finish = inputs.length; for ( var i = start; i < finish; i++ ) { var cb = inputs[i]; if ( !cb.type || cb.type.toLowerCase() != 'checkbox' ) continue; var end = checkboxes.length; checkboxes[end] = cb; cb.index = end; cb.onclick = checkboxClickHandler; } if ( finish < inputs.length ) { setTimeout( function () { addCheckboxClickHandlers(inputs, finish); }, 200 ); }}function checkboxClickHandler(e) { if (typeof e == 'undefined') { e = window.event; } if ( !e.shiftKey || lastCheckbox === null ) { lastCheckbox = this.index; return true; } var endState = this.checked; var start, finish; if ( this.index < lastCheckbox ) { start = this.index + 1; finish = lastCheckbox; } else { start = lastCheckbox; finish = this.index - 1; } for (var i = start; i <= finish; ++i ) { checkboxes[i].checked = endState; } lastCheckbox = this.index; return true;}function toggle_element_activation(ida,idb) { if (!document.getElementById) { return; } document.getElementById(ida).disabled=true; document.getElementById(idb).disabled=false;}function toggle_element_check(ida,idb) { if (!document.getElementById) { return; } document.getElementById(ida).checked=true; document.getElementById(idb).checked=false;}/* Written by Jonathan Snook, http://www.snook.ca/jonathan Add-ons by Robert Nyman, http://www.robertnyman.com Author says "The credit comment is all it takes, no license. Go crazy with it!:-)" From http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/*/function getElementsByClassName(oElm, strTagName, oClassNames){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -