MediaWiki:Gadget-DotsSyntaxHighlighter.js
来自希灵百科
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
!function(){"use strict";function e(e){return new RegExp("("+e+")\n*|"+p,"gm")}function t(){function r(e,t){t!=a&&(H+="'}#s"+z,E?(H+=":before{",E=!1):(H+=":after{",E=!0,++z),t&&(H+="background-color:"+t+";"),H+="content:'",a=t),H+=e}function n(t,o,i,a){var l;for(o.lastIndex=p;l=o.exec(s);o.lastIndex=p){if(l[1])return r(s.substring(p,o.lastIndex),t),void(p=o.lastIndex);var g=o.lastIndex-l[0].length;switch(g>p&&r(s.substring(p,g),t),p=o.lastIndex,l[0].charAt(0)){case"[":"["==l[0].charAt(1)?(r("[[",syntaxHighlighterConfig.wikilinkColor||t),n(syntaxHighlighterConfig.wikilinkColor||t,y)):(r(l[0],syntaxHighlighterConfig.externalLinkColor||t),n(syntaxHighlighterConfig.externalLinkColor||t,C));break;case"{":"{"==l[0].charAt(1)?3==l[0].length?(r("{{{",syntaxHighlighterConfig.parameterColor||t),n(syntaxHighlighterConfig.parameterColor||t,x)):(r("{{",syntaxHighlighterConfig.templateColor||t),n(syntaxHighlighterConfig.templateColor||t,b)):(r("{|",syntaxHighlighterConfig.tableColor||t),n(syntaxHighlighterConfig.tableColor||t,v));break;case"<":if("!"==l[0].charAt(1)){r(l[0],syntaxHighlighterConfig.commentColor||t);break}var h=s.indexOf(">",p)+1;if(0==h){r("<",t),p=p-l[0].length+1;break}if("/"==s.charAt(h-2))r(s.substring(p-l[0].length,h),syntaxHighlighterConfig.tagColor||t),p=h;else{var d=l[0].substring(1);if(/^(?:nowiki|pre|math|syntaxhighlight|source|timeline|hiero)$/.test(d)){var u="</"+d+">",c=s.indexOf(u,p);-1==c?c=s.length:c+=u.length,r(s.substring(p-l[0].length,c),syntaxHighlighterConfig.tagColor||t),p=c}else r(s.substring(p-l[0].length,h),syntaxHighlighterConfig.tagColor||t),p=h,k[d]||(k[d]=e("</"+d+">")),n(syntaxHighlighterConfig.tagColor||t,k[d])}break;case"h":case"f":case"m":r(l[0],syntaxHighlighterConfig.externalLinkColor||t);break;case"=":/[^=]=+$/.test(s.substring(p,s.indexOf("\n",p)))?(r("=",syntaxHighlighterConfig.headingColor||t),n(syntaxHighlighterConfig.headingColor||t,w)):r("=",t);break;case"*":case"#":case":":r(l[0],syntaxHighlighterConfig.listOrIndentColor||t);break;case";":r(";",syntaxHighlighterConfig.headingColor||t),n(syntaxHighlighterConfig.headingColor||t,w);break;case"-":r(l[0],syntaxHighlighterConfig.hrColor||t);break;case"\\":if(r(l[0],syntaxHighlighterConfig.boldOrItalicColor||t),6==l[0].length)if(i){if(!a)return;i=!1}else a?i=!0:n(syntaxHighlighterConfig.boldOrItalicColor||t,f,!0,!1);else if(a){if(!i)return;a=!1}else i?a=!0:n(syntaxHighlighterConfig.boldOrItalicColor||t,f,!1,!0);break;case"&":r(l[0],syntaxHighlighterConfig.entityColor||t);break;case"~":r(l[0],syntaxHighlighterConfig.signatureColor||t)}}}d=g.value;var a,s=d.replace(/['\\]/g,"\\$&")+"\n",p=0,H="",z=0,E=!0,$=Date.now();n("",f),p<s.length&&r(s.substring(p),"");var S=Date.now();if(S-$>syntaxHighlighterConfig.timeout){clearInterval(u),g.removeEventListener("input",t),g.removeEventListener("scroll",o),g.removeEventListener("scroll",i),c.disconnect(),h.nodeValue="";F=mw.config.get("wgUserLanguage");return L=L[F]||L[F.substring(0,F.indexOf("-"))]||L.en,g.style.backgroundColor="",g.style.position="",l.removeAttribute("dir"),l.removeAttribute("lang"),l.style="color:red; font-size:small",void(l.textContent=L.replace("$1",syntaxHighlighterConfig.timeout).replace("$2",S-$))}if(z>m){var I=document.createDocumentFragment();do I.appendChild(document.createElement("span")).id="s"+ ++m;while(z>m);l.appendChild(I)}h.nodeValue=H.substring(2).replace(/\n/g,"\\A ")+"'}"}function o(){l.scrollLeft=g.scrollLeft}function i(){l.scrollTop=g.scrollTop}function r(){l.dir=g.dir}function n(){g.value!=d&&t(),g.scrollLeft!=l.scrollLeft&&o(),g.scrollTop!=l.scrollTop&&i(),g.offsetHeight!=l.offsetHeight&&(l.style.height=g.offsetHeight+"px")}function a(){function e(e,t){if("normal"==syntaxHighlighterConfig[e])syntaxHighlighterConfig[e]=t;else{if("undefined"!=typeof syntaxHighlighterConfig[e])return;syntaxHighlighterConfig[e]="undefined"!=typeof syntaxHighlighterConfig.defaultColor?syntaxHighlighterConfig.defaultColor:t}}window.syntaxHighlighterConfig=window.syntaxHighlighterConfig||{},e("boldOrItalicColor","#EEE"),e("commentColor","#EFE"),e("entityColor","#DFD"),e("externalLinkColor","#EFF"),e("headingColor","#EEE"),e("hrColor","#EEE"),e("listOrIndentColor","#EFE"),e("parameterColor","#FC6"),e("signatureColor","#FC6"),e("tagColor","#FEF"),e("tableColor","#FFC"),e("templateColor","#FFC"),e("wikilinkColor","#EEF"),syntaxHighlighterConfig.timeout=syntaxHighlighterConfig.timeout||50;var a=document.createElement("div");l=document.createElement("div"),g=document.getElementById("wpTextbox1");var s=document.createElement("style");h=s.appendChild(document.createTextNode(""));var d=window.getComputedStyle(g),m=g.scrollTop,p=document.activeElement==g;l.dir=g.dir,l.lang=g.lang,l.style.backgroundColor=d.backgroundColor,l.style.border="1px solid transparent",l.style.boxSizing="border-box",l.style.color="transparent",l.style.fontFamily=d.fontFamily,l.style.fontSize=d.fontSize,l.style.lineHeight="normal",l.style.marginBottom=d.marginBottom,l.style.marginLeft="0",l.style.marginRight="0",l.style.marginTop=d.marginTop,l.style.overflowX="auto",l.style.overflowY="scroll",l.style.resize="vertical"==d.resize||"both"==d.resize?"vertical":"none",l.style.tabSize=d.tabSize,l.style.whiteSpace="pre-wrap",l.style.width="100%",l.style.wordWrap="normal",g.style.backgroundColor="transparent",g.style.border="1px inset gray",g.style.boxSizing="border-box",g.style.fontSize=d.fontSize,g.style.lineHeight="normal",g.style.left="0",g.style.margin="0",g.style.overflowX="auto",g.style.overflowY="scroll",g.style.padding="0",g.style.position="absolute",g.style.resize=l.style.resize,g.style.top="0",g.style.width="100%",g.style.wordWrap="normal",l.style.height=g.offsetHeight+"px",g.style.height=l.style.height,a.style.clear="both",a.style.position="relative",g.parentNode.insertBefore(a,g),a.appendChild(g),a.appendChild(l),l.scrollTop=m,g.scrollTop=m,p&&g.focus(),$(".tool-select *").css({zIndex:5}),document.head.appendChild(s),g.addEventListener("input",t),g.addEventListener("scroll",o),g.addEventListener("scroll",i),c=new MutationObserver(r),c.observe(g,{attributes:!0}),u=setInterval(n,500),t()}function s(){setTimeout(a,0)}var l,g,h,d,u,c,m=-1,p="\\[(?:\\[|(?:https?:|ftp:)?//|mailto:)|\\{(?:\\{\\{?|\\|)|<(?:[:A-Z_a-zÀ-ÖØ-öø-˿Ͱ-ͽͿ-⁰-Ⰰ-、-豈-﷏ﷰ-�][:\\wÀ-ÖØ-öø-˿Ͱ-ͽͿ-⁰-Ⰰ-、-豈-﷏ﷰ-�-\\.·̀-ͯ‿-‿-⁀]*(?=/?>| |\n)|!--[^]*?-->\n*)|(?:https?://|ftp://|mailto:)[^\\s\"<>[\\]{-}]*[^\\s\",\\.:;<>[\\]{-}]\n*|^(?:=|[*#:;]+\n*|-{4,}\n*)|\\\\'\\\\'(?:\\\\')?|~{3,5}\n*|&(?:(?:n(?:bsp|dash)|m(?:dash|inus)|lt|e[mn]sp|thinsp|amp|quot|gt|shy|zwn?j|lrm|rlm|Alpha|Beta|Epsilon|Zeta|Eta|Iota|Kappa|[Mm]u|micro|Nu|[Oo]micron|[Rr]ho|Tau|Upsilon|Chi)|#x[0-9a-fA-F]+);\n*",f=new RegExp(p,"gm"),y=e("]][a-zA-Z]*"),C=e("]"),x=e("}}}"),b=e("}}"),v=e("\\|}"),w=e("\n"),k={},H=mw.config.get("wgAction");"edit"!=H&&"submit"!=H||"wikitext"!=mw.config.get("wgPageContentModel")||"trident"==$.client.profile().layout||("complete"==document.readyState?s():$(window).load(s))}();