跳转到内容

MediaWiki:Gadget-prism-plugin-match-braces.js

来自萌娘共享

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的更改的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/prism-plugin-match-braces/Gadget-prism-plugin-match-braces.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=103d1a563ea4ccc8ff29fb55c9bcd88329a56eb5|shortId=103d1a56|summary=feat: rename (#594)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}'; 

/* <pre> */

"use strict";!function(){function mapClassName(e){var a=Prism.plugins.customClass;return a?a.apply(e,"none"):e}function getPartnerBrace(e){var a=c.exec(e.id);return document.querySelector("#"+a[1]+("open"==a[2]?"close":"open"))}function hoverBrace(){Prism.util.isActive(this,"brace-hover",!0)&&[this,getPartnerBrace(this)].forEach(function(e){e.classList.add(mapClassName("brace-hover"))})}function leaveBrace(){[this,getPartnerBrace(this)].forEach(function(e){e.classList.remove(mapClassName("brace-hover"))})}function clickBrace(){Prism.util.isActive(this,"brace-select",!0)&&[this,getPartnerBrace(this)].forEach(function(e){e.classList.add(mapClassName("brace-selected"))})}if("undefined"!=typeof Prism&&"undefined"!=typeof document){var e={"(":")","[":"]","{":"}"},a={"(":"brace-round","[":"brace-square","{":"brace-curly"},r={"${":"{"},n=0,c=/^(pair-\d+-)(close|open)$/;Prism.hooks.add("complete",function(c){var t=c.element,s=t.parentElement;if(s&&"PRE"==s.tagName){var o=[];if(Prism.util.isActive(t,"match-braces")&&o.push("(","[","{"),0!=o.length){s.__listenerAdded||(s.addEventListener("mousedown",function removeBraceSelected(){var e=s.querySelector("code"),a=mapClassName("brace-selected");Array.prototype.slice.call(e.querySelectorAll("."+a)).forEach(function(e){e.classList.remove(a)})}),Object.defineProperty(s,"__listenerAdded",{value:!0}));var i=Array.prototype.slice.call(t.querySelectorAll("span."+mapClassName("token")+"."+mapClassName("punctuation"))),m=[];o.forEach(function(c){for(var t=e[c],s=mapClassName(a[c]),o=[],l=[],u=0;u<i.length;u++){var f=i[u];if(0==f.childElementCount){var p=f.textContent;(p=r[p]||p)===c?(m.push({index:u,open:!0,element:f}),f.classList.add(s),f.classList.add(mapClassName("brace-open")),l.push(u)):p===t&&(m.push({index:u,open:!1,element:f}),f.classList.add(s),f.classList.add(mapClassName("brace-close")),l.length&&o.push([u,l.pop()]))}}o.forEach(function(e){var a="pair-"+n+++"-",r=i[e[0]],c=i[e[1]];r.id=a+"open",c.id=a+"close",[r,c].forEach(function(e){e.addEventListener("mouseenter",hoverBrace),e.addEventListener("mouseleave",leaveBrace),e.addEventListener("click",clickBrace)})})});var l=0;m.sort(function(e,a){return e.index-a.index}),m.forEach(function(e){e.open?(e.element.classList.add(mapClassName("brace-level-"+(l%12+1))),l++):(l=Math.max(0,l-1),e.element.classList.add(mapClassName("brace-level-"+(l%12+1))))})}}})}}(); 

/* </pre> */