-
Notifications
You must be signed in to change notification settings - Fork 1
/
unfuck-tabstops.min.js
1 lines (1 loc) · 2.5 KB
/
unfuck-tabstops.min.js
1
javascript:void!function(e){"use strict";function t(e,o=""){const n=[];for(const r of e.childNodes)switch(r.nodeType){case Node.TEXT_NODE:n.push(r);break;case Node.ELEMENT_NODE:o&&r.matches(o)||n.push(...t(r))}return n}const o={__proto__:null};function n(e,t=2){const n=o[t]||=new RegExp(`(^|\\n)((?:${" ".repeat(t)})+)`,"g");return function(e){return e.replace(/ |�*160;|�*A0;|\xA0/g," ")}(e).replace(n,((e,o,n)=>o+"\t".repeat(n.length/t)))}const r=[".highlight > pre > .line span:first-child:not(:only-child)",".prism-code .token-line > .token",".react-code-cell",".react-code-line-contents","td.blob-num + .blob-code",".add-line-comment ~ .blob-code-inner","pre, code, tt"];(function(){const{body:e}=document,t=e.querySelectorAll("*"),o=e=>!!/^pre(?:-wrap)?$/i.test(window.getComputedStyle(e).whiteSpace);return!e.childElementCount&&e.textContent&&o(e)||1===t.length&&o(t[0])})()&&r.push("body, body *");const c=(e=>{if(o=document.documentElement.style,(t=e[0].toLowerCase()+e.slice(1))in o)return t;for(var t,o,n=((n="Webkit Moz Ms O Khtml").toLowerCase()+n).split(" "),r=0;r<10;++r)if((t=n[r]+e)in o)return t;return""})("TabSize");for(const e of document.querySelectorAll("[data-tab-size], .prism-code"))e.dataset.tabSize=e.style[c]=4;for(const e of document.querySelectorAll("clipboard-copy[value]"))e.value=n(e.value);if(document.styleSheets.length)for(const e of document.styleSheets)try{for(const t of[...e.rules])t instanceof CSSStyleRule&&!Number.isNaN(+t.style[c])&&(t.style[c]=4)}catch(e){console.error(e)}else{document.head.appendChild(document.createElement("style")).innerHTML="*, *::before, *::after {\n"+["-moz-","-o-",""].map((e=>`${e}tab-size: 4 !important`)).join("; ")+"\n}"}for(const e of document.querySelectorAll("[style]"))[...e.style].includes("tab-size")&&(e.style[c]=4);for(const{CodeMirror:e}of document.querySelectorAll(".CodeMirror"))try{e.setOption("indentWithTabs",!0),e.setOption("indentUnit",4),e.setValue(n(e.getValue()))}catch(e){}for(const{cmView:e}of document.querySelectorAll(".cm-editor [role='textbox']"))try{const t=e.editorView.state.doc.toString(),o=/^(?: {2})+/gm,n=[];let r;for(;r=o.exec(t);){const e=r.index,t=e+r[0].length,o="\t".repeat(r[0].length/2);n.push({from:e,to:t,insert:o})}e.editorView.dispatch({changes:n})}catch(e){console.error(e)}for(const e of document.querySelectorAll("select#indent-mode + select#indent-size"))e.value=4,e.previousElementSibling.value="tab";for(const e of document.querySelectorAll(r.join(", ")))for(const o of t(e)){const{data:e}=o,t=n(e);t!==e&&(o.data=t)}}();