Skip to content

Instantly share code, notes, and snippets.

@glenkusuma
Last active March 19, 2025 21:09
Show Gist options
  • Save glenkusuma/fd78731193257a9c92ef361707659afa to your computer and use it in GitHub Desktop.
Save glenkusuma/fd78731193257a9c92ef361707659afa to your computer and use it in GitHub Desktop.
toolbox
!function(){"use strict";const e="#a12520",t="#ffffff",n="invert(100%",r="#6B7280";function o(e,t,n,r){const o=document.createElement("img");if(e.trim().startsWith("<svg")){const t="data:image/svg+xml;base64,"+btoa(e);o.src=t}else o.src=e;return o.alt=t,o.style.width=r,o.style.height="auto",o.style.maxWidth=r,n&&(o.style.filter=n),o}function i(e,t){e.style.backgroundColor=t||""}function a(e,t){t&&(e.style.backgroundColor=function(e,t){if(!e)return"";if(e.startsWith("#")){let n=parseInt(e.slice(1),16),r=Math.round(2.55*t),o=(n>>16)+r,i=(n>>8&255)+r,a=(255&n)+r;return"#"+(16777216+(Math.min(255,Math.max(0,o))<<16)+(Math.min(255,Math.max(0,i))<<8)+Math.min(255,Math.max(0,a))).toString(16).slice(1)}if(e.startsWith("rgb")){const n=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)(,\s*[\d.]+)?\)/);if(!n)return e;let r=parseInt(n[1],10),o=parseInt(n[2],10),i=parseInt(n[3],10),a=n[4]||"",l=Math.round(2.55*t);return r=Math.min(255,Math.max(0,r+l)),o=Math.min(255,Math.max(0,o+l)),i=Math.min(255,Math.max(0,i+l)),`rgb${a?"a":""}(${r}, ${o}, ${i}${a})`}return e}(t,-10))}function l(e,t){return Array(t+1).join(e)}var c=["ADDRESS","ARTICLE","ASIDE","AUDIO","BLOCKQUOTE","BODY","CANVAS","CENTER","DD","DIR","DIV","DL","DT","FIELDSET","FIGCAPTION","FIGURE","FOOTER","FORM","FRAMESET","H1","H2","H3","H4","H5","H6","HEADER","HGROUP","HR","HTML","ISINDEX","LI","MAIN","MENU","NAV","NOFRAMES","NOSCRIPT","OL","OUTPUT","P","PRE","SECTION","TABLE","TBODY","TD","TFOOT","TH","THEAD","TR","UL"];function C(e){return p(e,c)}var s=["AREA","BASE","BR","COL","COMMAND","EMBED","HR","IMG","INPUT","KEYGEN","LINK","META","PARAM","SOURCE","TRACK","WBR"];function d(e){return p(e,s)}var u=["A","TABLE","THEAD","TBODY","TFOOT","TH","TD","IFRAME","SCRIPT","AUDIO","VIDEO"];function p(e,t){return t.indexOf(e.nodeName)>=0}function f(e,t){return e.getElementsByTagName&&t.some((function(t){return e.getElementsByTagName(t).length}))}var m={};function g(e){return e?e.replace(/(\n+\s*)+/g,"\n"):""}function h(e){for(var t in this.options=e,this._keep=[],this._remove=[],this.blankRule={replacement:e.blankReplacement},this.keepReplacement=e.keepReplacement,this.defaultRule={replacement:e.defaultReplacement},this.array=[],e.rules)this.array.push(e.rules[t])}function v(e,t,n){for(var r=0;r<e.length;r++){var o=e[r];if(w(o,t,n))return o}}function w(e,t,n){var r=e.filter;if("string"==typeof r){if(r===t.nodeName.toLowerCase())return!0}else if(Array.isArray(r)){if(r.indexOf(t.nodeName.toLowerCase())>-1)return!0}else{if("function"!=typeof r)throw new TypeError("`filter` needs to be a string, array, or function");if(r.call(e,t,n))return!0}}function y(e){var t=e.nextSibling||e.parentNode;return e.parentNode.removeChild(e),t}function x(e,t,n){return e&&e.parentNode===t||n(t)?t.nextSibling||t.parentNode:t.firstChild||t.nextSibling||t.parentNode}m.paragraph={filter:"p",replacement:function(e){return"\n\n"+e+"\n\n"}},m.lineBreak={filter:"br",replacement:function(e,t,n){return n.br+"\n"}},m.heading={filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,t,n){var r=Number(t.nodeName.charAt(1));return"setext"===n.headingStyle&&r<3?"\n\n"+e+"\n"+l(1===r?"=":"-",e.length)+"\n\n":"\n\n"+l("#",r)+" "+e+"\n\n"}},m.blockquote={filter:"blockquote",replacement:function(e){return"\n\n"+(e=(e=e.replace(/^\n+|\n+$/g,"")).replace(/^/gm,"> "))+"\n\n"}},m.list={filter:["ul","ol"],replacement:function(e,t){var n=t.parentNode;return"LI"===n.nodeName&&n.lastElementChild===t?"\n"+e:"\n\n"+e+"\n\n"}},m.listItem={filter:"li",replacement:function(e,t,n){e=e.replace(/^\n+/,"").replace(/\n+$/,"\n").replace(/\n/gm,"\n ");var r=n.bulletListMarker+" ",o=t.parentNode;if("OL"===o.nodeName){var i=o.getAttribute("start"),a=Array.prototype.indexOf.call(o.children,t);r=(i?Number(i)+a:a+1)+". "}return r+e+(t.nextSibling&&!/\n$/.test(e)?"\n":"")}},m.indentedCodeBlock={filter:function(e,t){return"indented"===t.codeBlockStyle&&"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,t,n){return"\n\n "+t.firstChild.textContent.replace(/\n/g,"\n ")+"\n\n"}},m.fencedCodeBlock={filter:function(e,t){return"fenced"===t.codeBlockStyle&&"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,t,n){for(var r,o=((t.firstChild.getAttribute("class")||"").match(/language-(\S+)/)||[null,""])[1],i=t.firstChild.textContent,a=n.fence.charAt(0),c=3,C=new RegExp("^"+a+"{3,}","gm");r=C.exec(i);)r[0].length>=c&&(c=r[0].length+1);var s=l(a,c);return"\n\n"+s+o+"\n"+i.replace(/\n$/,"")+"\n"+s+"\n\n"}},m.horizontalRule={filter:"hr",replacement:function(e,t,n){return"\n\n"+n.hr+"\n\n"}},m.inlineLink={filter:function(e,t){return"inlined"===t.linkStyle&&"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,t){var n=t.getAttribute("href");n&&(n=n.replace(/([()])/g,"\\$1"));var r=g(t.getAttribute("title"));return r&&(r=' "'+r.replace(/"/g,'\\"')+'"'),"["+e+"]("+n+r+")"}},m.referenceLink={filter:function(e,t){return"referenced"===t.linkStyle&&"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,t,n){var r,o,i=t.getAttribute("href"),a=g(t.getAttribute("title"));switch(a&&(a=' "'+a+'"'),n.linkReferenceStyle){case"collapsed":r="["+e+"][]",o="["+e+"]: "+i+a;break;case"shortcut":r="["+e+"]",o="["+e+"]: "+i+a;break;default:var l=this.references.length+1;r="["+e+"]["+l+"]",o="["+l+"]: "+i+a}return this.references.push(o),r},references:[],append:function(e){var t="";return this.references.length&&(t="\n\n"+this.references.join("\n")+"\n\n",this.references=[]),t}},m.emphasis={filter:["em","i"],replacement:function(e,t,n){return e.trim()?n.emDelimiter+e+n.emDelimiter:""}},m.strong={filter:["strong","b"],replacement:function(e,t,n){return e.trim()?n.strongDelimiter+e+n.strongDelimiter:""}},m.code={filter:function(e){var t=e.previousSibling||e.nextSibling,n="PRE"===e.parentNode.nodeName&&!t;return"CODE"===e.nodeName&&!n},replacement:function(e){if(!e)return"";e=e.replace(/\r?\n|\r/g," ");for(var t=/^`|^ .*?[^ ].* $|`$/.test(e)?" ":"",n="`",r=e.match(/`+/gm)||[];-1!==r.indexOf(n);)n+="`";return n+t+e+t+n}},m.image={filter:"img",replacement:function(e,t){var n=g(t.getAttribute("alt")),r=t.getAttribute("src")||"",o=g(t.getAttribute("title"));return r?"!["+n+"]("+r+(o?' "'+o+'"':"")+")":""}},h.prototype={add:function(e,t){this.array.unshift(t)},keep:function(e){this._keep.unshift({filter:e,replacement:this.keepReplacement})},remove:function(e){this._remove.unshift({filter:e,replacement:function(){return""}})},forNode:function(e){return e.isBlank?this.blankRule:(t=v(this.array,e,this.options))||(t=v(this._keep,e,this.options))||(t=v(this._remove,e,this.options))?t:this.defaultRule;var t},forEach:function(e){for(var t=0;t<this.array.length;t++)e(this.array[t],t)}};var D="undefined"!=typeof window?window:{};var E,b,A,F=function(){var e=D.DOMParser,t=!1;try{(new e).parseFromString("","text/html")&&(t=!0)}catch(e){}return t}()?D.DOMParser:(E=function(){},b=require("@mixmark-io/domino"),E.prototype.parseFromString=function(e){return b.createDocument(e)},E);function T(e,t){var n;"string"==typeof e?n=(A=A||new F).parseFromString('<x-turndown id="turndown-root">'+e+"</x-turndown>","text/html").getElementById("turndown-root"):n=e.cloneNode(!0);return function(e){var t=e.element,n=e.isBlock,r=e.isVoid,o=e.isPre||function(e){return"PRE"===e.nodeName};if(t.firstChild&&!o(t)){for(var i=null,a=!1,l=null,c=x(l,t,o);c!==t;){if(3===c.nodeType||4===c.nodeType){var C=c.data.replace(/[ \r\n\t]+/g," ");if(i&&!/ $/.test(i.data)||a||" "!==C[0]||(C=C.substr(1)),!C){c=y(c);continue}c.data=C,i=c}else{if(1!==c.nodeType){c=y(c);continue}n(c)||"BR"===c.nodeName?(i&&(i.data=i.data.replace(/ $/,"")),i=null,a=!1):r(c)||o(c)?(i=null,a=!0):i&&(a=!1)}var s=x(l,c,o);l=c,c=s}i&&(i.data=i.data.replace(/ $/,""),i.data||y(i))}}({element:n,isBlock:C,isVoid:d,isPre:t.preformattedCode?k:null}),n}function k(e){return"PRE"===e.nodeName||"CODE"===e.nodeName}function M(e,t){return e.isBlock=C(e),e.isCode="CODE"===e.nodeName||e.parentNode.isCode,e.isBlank=function(e){return!d(e)&&!function(e){return p(e,u)}(e)&&/^\s*$/i.test(e.textContent)&&!function(e){return f(e,s)}(e)&&!function(e){return f(e,u)}(e)}(e),e.flankingWhitespace=function(e,t){if(e.isBlock||t.preformattedCode&&e.isCode)return{leading:"",trailing:""};var n=(r=e.textContent,o=r.match(/^(([ \t\r\n]*)(\s*))(?:(?=\S)[\s\S]*\S)?((\s*?)([ \t\r\n]*))$/),{leading:o[1],leadingAscii:o[2],leadingNonAscii:o[3],trailing:o[4],trailingNonAscii:o[5],trailingAscii:o[6]});var r,o;n.leadingAscii&&L("left",e,t)&&(n.leading=n.leadingNonAscii);n.trailingAscii&&L("right",e,t)&&(n.trailing=n.trailingNonAscii);return{leading:n.leading,trailing:n.trailing}}(e,t),e}function L(e,t,n){var r,o,i;return"left"===e?(r=t.previousSibling,o=/ $/):(r=t.nextSibling,o=/^ /),r&&(3===r.nodeType?i=o.test(r.nodeValue):n.preformattedCode&&"CODE"===r.nodeName?i=!1:1!==r.nodeType||C(r)||(i=o.test(r.textContent))),i}var H=Array.prototype.reduce,N=[[/\\/g,"\\\\"],[/\*/g,"\\*"],[/^-/g,"\\-"],[/^\+ /g,"\\+ "],[/^(=+)/g,"\\$1"],[/^(#{1,6}) /g,"\\$1 "],[/`/g,"\\`"],[/^~~~/g,"\\~~~"],[/\[/g,"\\["],[/\]/g,"\\]"],[/^>/g,"\\>"],[/_/g,"\\_"],[/^(\d+)\. /g,"$1\\. "]];function R(e){if(!(this instanceof R))return new R(e);var t={rules:m,headingStyle:"setext",hr:"* * *",bulletListMarker:"*",codeBlockStyle:"indented",fence:"```",emDelimiter:"_",strongDelimiter:"**",linkStyle:"inlined",linkReferenceStyle:"full",br:" ",preformattedCode:!1,blankReplacement:function(e,t){return t.isBlock?"\n\n":""},keepReplacement:function(e,t){return t.isBlock?"\n\n"+t.outerHTML+"\n\n":t.outerHTML},defaultReplacement:function(e,t){return t.isBlock?"\n\n"+e+"\n\n":e}};this.options=function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)n.hasOwnProperty(r)&&(e[r]=n[r])}return e}({},t,e),this.rules=new h(this.options)}function S(e){var t=this;return H.call(e.childNodes,(function(e,n){var r="";return 3===(n=new M(n,t.options)).nodeType?r=n.isCode?n.nodeValue:t.escape(n.nodeValue):1===n.nodeType&&(r=I.call(t,n)),V(e,r)}),"")}function O(e){var t=this;return this.rules.forEach((function(n){"function"==typeof n.append&&(e=V(e,n.append(t.options)))})),e.replace(/^[\t\r\n]+/,"").replace(/[\t\r\n\s]+$/,"")}function I(e){var t=this.rules.forNode(e),n=S.call(this,e),r=e.flankingWhitespace;return(r.leading||r.trailing)&&(n=n.trim()),r.leading+t.replacement(n,e,this.options)+r.trailing}function V(e,t){var n=function(e){for(var t=e.length;t>0&&"\n"===e[t-1];)t--;return e.substring(0,t)}(e),r=t.replace(/^\n*/,""),o=Math.max(e.length-n.length,t.length-r.length);return n+"\n\n".substring(0,o)+r}R.prototype={turndown:function(e){if(!function(e){return null!=e&&("string"==typeof e||e.nodeType&&(1===e.nodeType||9===e.nodeType||11===e.nodeType))}(e))throw new TypeError(e+" is not a string, or an element/document/fragment node.");if(""===e)return"";var t=S.call(this,new T(e,this.options));return O.call(this,t)},use:function(e){if(Array.isArray(e))for(var t=0;t<e.length;t++)this.use(e[t]);else{if("function"!=typeof e)throw new TypeError("plugin must be a Function or an Array of Functions");e(this)}return this},addRule:function(e,t){return this.rules.add(e,t),this},keep:function(e){return this.rules.keep(e),this},remove:function(e){return this.rules.remove(e),this},escape:function(e){return N.reduce((function(e,t){return e.replace(t[0],t[1])}),e)}};var B=/highlight-(?:text|source)-([a-z0-9]+)/;function P(e){e.addRule("highlightedCodeBlock",{filter:function(e){var t=e.firstChild;return"DIV"===e.nodeName&&B.test(e.className)&&t&&"PRE"===t.nodeName},replacement:function(e,t,n){var r=((t.className||"").match(B)||[null,""])[1];return"\n\n"+n.fence+r+"\n"+t.firstChild.textContent+"\n"+n.fence+"\n\n"}})}function z(e){e.addRule("strikethrough",{filter:["del","s","strike"],replacement:function(e){return"~"+e+"~"}})}var $=Array.prototype.indexOf,j=Array.prototype.every,U={};function _(e){var t,n,r=e.parentNode;return"THEAD"===r.nodeName||r.firstChild===e&&("TABLE"===r.nodeName||(n=(t=r).previousSibling,"TBODY"===t.nodeName&&(!n||"THEAD"===n.nodeName&&/^\s*$/i.test(n.textContent))))&&j.call(e.childNodes,(function(e){return"TH"===e.nodeName}))}function Z(e,t){var n=" ";return 0===$.call(t.parentNode.childNodes,t)&&(n="| "),n+e+" |"}function G(e){for(var t in e.keep((function(e){return"TABLE"===e.nodeName&&!_(e.rows[0])})),U)e.addRule(t,U[t])}function W(e){e.addRule("taskListItems",{filter:function(e){return"checkbox"===e.type&&"LI"===e.parentNode.nodeName},replacement:function(e,t){return(t.checked?"[x]":"[ ]")+" "}})}function q(e){e.use([P,z,G,W])}async function Y(e,t=0){const n=e.querySelectorAll("img"),r=[];return n.forEach((e=>{const n=function(e,t=0){return new Promise((n=>{const r=new Image;r.crossOrigin="Anonymous",r.onload=function(){try{const e=document.createElement("canvas");e.width=r.width,e.height=r.height,e.getContext("2d").drawImage(r,0,0);const o=e.toDataURL("image/png");t>=2&&console.log("[convertImageToDataURL] Converted image to data URL."),n(o)}catch(r){t>=1&&console.warn("[convertImageToDataURL] Error converting image, returning original src:",r),n(e.src)}},r.onerror=function(r){t>=1&&console.warn("[convertImageToDataURL] Failed to load image for conversion, returning original src.",r),n(e.src)},r.src=e.src,r.complete&&r.onload()}))}(e,t).then((t=>{e.src=t}));r.push(n)})),Promise.all(r)}function K(e="div.outcome.clearfix",t,n=0){let r;if(n>=1&&console.log("[copyInnerHtmlAction] Called with targetElement:",e),"string"==typeof e?r=document.querySelector(e):e instanceof Element&&(r=e),!r){const t=`[copyInnerHtmlAction] Target element "${e}" not found.`;return n>=1&&console.error(t),Promise.reject(new Error(t))}const o=r.innerHTML;return n>=2&&console.log("[copyInnerHtmlAction] Extracted innerHTML:",o),navigator.clipboard.writeText(o).then((()=>(n>=1&&console.log("[copyInnerHtmlAction] Successfully copied innerHTML to clipboard."),o))).catch((e=>{n>=1&&console.warn("[copyInnerHtmlAction] Clipboard write failed, using prompt fallback:",e);const t=prompt("Failed to copy automatically. Please manually copy the HTML below:",o);return null!==t?Promise.resolve(t):Promise.reject(new Error("User cancelled prompt."))}))}U.tableCell={filter:["th","td"],replacement:function(e,t){return Z(e,t)}},U.tableRow={filter:"tr",replacement:function(e,t){var n="",r={left:":--",right:"--:",center:":-:"};if(_(t))for(var o=0;o<t.childNodes.length;o++){var i="---",a=(t.childNodes[o].getAttribute("align")||"").toLowerCase();a&&(i=r[a]||i),n+=Z(i,t.childNodes[o])}return"\n"+e+(n?"\n"+n:"")}},U.table={filter:function(e){return"TABLE"===e.nodeName&&_(e.rows[0])},replacement:function(e){return"\n\n"+(e=e.replace("\n\n","\n"))+"\n\n"}},U.tableSection={filter:["thead","tbody","tfoot"],replacement:function(e){return e}};!function(l,c=!0){const C=document.createElement("div");C.classList.add("floating-buttons-parent"),Object.assign(C.style,{position:"fixed",bottom:"5px",right:"5px",display:"flex",gap:"8px",zIndex:"9999"}),C.style.flexDirection="row",C.style.alignItems="center";const s=document.createElement("div");s.classList.add("user-buttons-container"),Object.assign(s.style,{display:"flex",flexDirection:"row",flexWrap:"wrap",gap:"8px"});const d=document.createElement("div");d.classList.add("toggle-container"),Object.assign(d.style,{display:"flex"}),C.appendChild(s),C.appendChild(d),document.body.appendChild(C);const u=[];function p(){u.forEach((t=>{"default"===t.state&&i(t,e)}))}if(l.forEach((r=>{const l=document.createElement("button");r.id&&(l.id=r.id),l.state="default",l.feedbackTimer=null;const c=!!r.icon,C=!!r.name;if(c&&C){l.textContent="",Object.assign(l.style,{display:"flex",alignItems:"center",gap:"0.3rem"});const e=o(r.icon,r.name||"icon",n,"16px");l.appendChild(e);const t=document.createElement("span");t.textContent=r.name,l.appendChild(t)}else if(c&&!C){l.textContent="",Object.assign(l.style,{display:"block",textAlign:"center"});const e=o(r.icon,"icon-only",n);l.appendChild(e)}else l.textContent=!c&&C?r.name:"";Object.assign(l.style,{width:"auto",height:"2rem",color:t,borderRadius:"9999px",border:"none",cursor:"pointer",fontWeight:"600",fontSize:"12px",padding:"0.2rem 1rem",boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)",transition:"background-color 0.2s ease-in-out",display:"none",position:"relative"}),i(l,e),r.tooltip&&function(e,t){const n=document.createElement("div");n.textContent=t,Object.assign(n.style,{position:"absolute",color:"#fff",backgroundColor:"rgba(0,0,0,0.8)",padding:"4px 8px",borderRadius:"4px",fontSize:"12px",zIndex:"99999",pointerEvents:"none",display:"none",overflowWrap:"break-word",wordWrap:"break-word"}),Object.assign(n.style,{bottom:"105%",left:"50%",transform:"translateX(-50%)",maxWidth:"150px",textAlign:"center"}),e.style.position="relative",e.appendChild(n);let r=null;e.addEventListener("mouseenter",(()=>{r=setTimeout((()=>{n.style.display="block"}),750)})),e.addEventListener("mouseleave",(()=>{clearTimeout(r),n.style.display="none"}))}(l,r.tooltip),l.addEventListener("mouseenter",(()=>{"default"===l.state?a(l,e):"feedback"===l.state&&(l.feedbackTimer&&(clearTimeout(l.feedbackTimer),l.feedbackTimer=null),l.state="default",l.disabled=!1,i(l,e),l.style.cursor="pointer")})),l.addEventListener("mouseleave",(()=>{"default"===l.state&&i(l,e)})),r.handler&&"function"==typeof r.handler?l.addEventListener("click",(t=>{p(),l.state="pending",l.disabled=!0,i(l,"rgba(245, 158, 11, 0.8)"),l.style.cursor="not-allowed",r.handler(t,0).then((()=>{l.state="feedback",i(l,"#14532D"),l.feedbackTimer=setTimeout((()=>{l.state="default",l.disabled=!1,i(l,e),l.style.cursor="pointer"}),5e3)})).catch((t=>{l.state="feedback",i(l,"#701A75"),l.feedbackTimer=setTimeout((()=>{l.state="default",l.disabled=!1,i(l,e),l.style.cursor="pointer"}),5e3)}))})):l.addEventListener("click",(()=>{p(),alert("Hello from button: "+(r.name||"Unknown"))})),s.appendChild(l),u.push(l)})),c){const e=document.createElement("button");e.id="hide-show-toggle",e.state="default",e.feedbackTimer=null;{e.textContent="",Object.assign(e.style,{display:"flex",justifyContent:"center",alignItems:"center"});const t=o("data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22iso-8859-1%22%3F%3E%3C!DOCTYPE%20svg%20PUBLIC%20%22-%2F%2FW3C%2F%2FDTD%20SVG%201.1%2F%2FEN%22%20%22http%3A%2F%2Fwww.w3.org%2FGraphics%2FSVG%2F1.1%2FDTD%2Fsvg11.dtd%22%3E%3Csvg%20fill%3D%22%23000000%22%20version%3D%221.1%22%20id%3D%22Capa_1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20%20%20width%3D%2212px%22%20height%3D%2212px%22%20viewBox%3D%220%200%20400.001%20400%22%20xml%3Aspace%3D%22preserve%22%20%3E%3Cg%3E%20%3Cg%3E%20%20%3Cpath%20d%3D%22M373.509%2C51.66H352.76V33.114c0-7.312-5.932-13.246-13.246-13.246H60.485c-7.314%2C0-13.246%2C5.935-13.246%2C13.246v68.875%20%20%20c0%2C7.316%2C5.932%2C13.245%2C13.246%2C13.245h279.029c7.314%2C0%2C13.246-5.929%2C13.246-13.245V78.146h20.749v243.711H352.76v-23.842%20%20%20c0-7.316-5.932-13.246-13.246-13.246H60.485c-7.314%2C0-13.246%2C5.93-13.246%2C13.246v23.842H26.491v-108.61H47.24v21.19%20%20%20c0%2C7.313%2C5.932%2C13.244%2C13.246%2C13.244h279.029c7.314%2C0%2C13.246-5.931%2C13.246-13.244v-68.872c0-7.315-5.932-13.245-13.246-13.245%20%20%20H60.485c-7.314%2C0-13.246%2C5.93-13.246%2C13.245v21.19H26.491C11.885%2C186.756%2C0%2C198.64%2C0%2C213.246v108.609%20%20%20c0%2C14.606%2C11.884%2C26.486%2C26.491%2C26.486H47.24v18.546c0%2C7.313%2C5.932%2C13.246%2C13.246%2C13.246h279.029%20%20%20c7.314%2C0%2C13.246-5.935%2C13.246-13.246v-18.546h20.749c14.606%2C0%2C26.491-11.88%2C26.491-26.486V78.148%20%20%20C400%2C63.54%2C388.115%2C51.66%2C373.509%2C51.66z%20M109.052%2C88.304c-11.462%2C0-20.751-9.293-20.751-20.75%20%20%20c0-11.462%2C9.29-20.751%2C20.751-20.751c11.459%2C0%2C20.749%2C9.289%2C20.749%2C20.751C129.801%2C79.011%2C120.511%2C88.304%2C109.052%2C88.304z%20%20%20%20M219.867%2C80.798c0%2C5.483-4.448%2C9.931-9.937%2C9.931c-5.485%2C0-9.933-4.447-9.933-9.931V54.31c0-5.488%2C4.446-9.936%2C9.933-9.936%20%20%20c5.487%2C0%2C9.937%2C4.447%2C9.937%2C9.936V80.798z%20M264.016%2C80.798c0%2C5.483-4.445%2C9.931-9.933%2C9.931c-5.485%2C0-9.933-4.447-9.933-9.931%20%20%20V54.31c0-5.488%2C4.446-9.936%2C9.933-9.936s9.933%2C4.447%2C9.933%2C9.936V80.798z%20M308.167%2C80.798c0%2C5.483-4.446%2C9.931-9.935%2C9.931%20%20%20c-5.486%2C0-9.934-4.447-9.934-9.931V54.31c0-5.488%2C4.446-9.936%2C9.934-9.936c5.486%2C0%2C9.935%2C4.447%2C9.935%2C9.936V80.798z%20%20%20%20M288.3%2C186.759c0-5.486%2C4.446-9.936%2C9.934-9.936c5.486%2C0%2C9.935%2C4.449%2C9.935%2C9.936v26.488c0%2C5.486-4.446%2C9.937-9.935%2C9.937%20%20%20c-5.486%2C0-9.934-4.449-9.934-9.937V186.759z%20M244.15%2C186.759c0-5.486%2C4.446-9.936%2C9.933-9.936s9.933%2C4.449%2C9.933%2C9.936v26.488%20%20%20c0%2C5.486-4.445%2C9.937-9.933%2C9.937c-5.485%2C0-9.933-4.449-9.933-9.937V186.759z%20M200%2C186.759c0-5.486%2C4.447-9.936%2C9.934-9.936%20%20%20c5.485%2C0%2C9.936%2C4.449%2C9.936%2C9.936v26.488c0%2C5.486-4.448%2C9.937-9.936%2C9.937c-5.486%2C0-9.934-4.45-9.934-9.937V186.759z%20%20%20%20M109.052%2C179.25c11.459%2C0%2C20.749%2C9.29%2C20.749%2C20.752s-9.29%2C20.752-20.749%2C20.752c-11.462%2C0-20.751-9.29-20.751-20.752%20%20%20S97.59%2C179.25%2C109.052%2C179.25z%20M109.052%2C353.203c-11.462%2C0-20.751-9.289-20.751-20.751c0-11.457%2C9.29-20.75%2C20.751-20.75%20%20%20c11.459%2C0%2C20.749%2C9.293%2C20.749%2C20.75C129.801%2C343.914%2C120.511%2C353.203%2C109.052%2C353.203z%20M219.867%2C345.696%20%20%20c0%2C5.487-4.448%2C9.936-9.937%2C9.936c-5.485%2C0-9.933-4.446-9.933-9.936v-26.488c0-5.481%2C4.446-9.93%2C9.933-9.93%20%20%20c5.487%2C0%2C9.937%2C4.445%2C9.937%2C9.93V345.696z%20M264.016%2C345.696c0%2C5.487-4.445%2C9.936-9.933%2C9.936c-5.485%2C0-9.933-4.446-9.933-9.936%20%20%20v-26.488c0-5.481%2C4.446-9.93%2C9.933-9.93s9.933%2C4.445%2C9.933%2C9.93V345.696z%20M308.167%2C345.696c0%2C5.487-4.446%2C9.936-9.935%2C9.936%20%20%20c-5.486%2C0-9.934-4.446-9.934-9.936v-26.488c0-5.481%2C4.446-9.93%2C9.934-9.93c5.486%2C0%2C9.935%2C4.445%2C9.935%2C9.93V345.696z%22%2F%3E%20%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E","toggle-icon","invert(100%)");e.appendChild(t)}Object.assign(e.style,{width:"2rem",height:"2rem",color:t,borderRadius:"9999px",border:"none",cursor:"pointer",fontWeight:"700",fontSize:"14px",padding:"",boxShadow:"0 4px 6px rgba(0, 0, 0, 0.1)",transition:"background-color 0.2s ease-in-out"}),i(e,r),e.addEventListener("mouseenter",(()=>{"default"===e.state&&a(e,r)})),e.addEventListener("mouseleave",(()=>{"default"===e.state&&i(e,r)})),e.addEventListener("click",(()=>{[...s.children].forEach((e=>{e.style.display="none"===e.style.display?"":"none"}))})),d.appendChild(e)}}([{id:"copyMarkdown",name:null,icon:"data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3Csvg%20fill%3D%22%23000000%22%20width%3D%2216px%22%20height%3D%2216px%22%20viewBox%3D%220%200%2024%2024%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M2%2C12H5a1%2C1%2C0%2C0%2C0%2C0-2H4.635l.586-1.692H8.779L9.365%2C10H9a1%2C1%2C0%2C0%2C0%2C0%2C2h3a1%2C1%2C0%2C0%2C0%2C0-2h-.518L8.945%2C2.673A1%2C1%2C0%2C0%2C0%2C8%2C2H6a1%2C1%2C0%2C0%2C0-.945.673L2.518%2C10H2a1%2C1%2C0%2C0%2C0%2C0%2C2ZM6.712%2C4h.576l.8%2C2.308H5.913ZM23%2C4a1%2C1%2C0%2C0%2C1-1%2C1H15a1%2C1%2C0%2C0%2C1%2C0-2h7A1%2C1%2C0%2C0%2C1%2C23%2C4Zm0%2C6a1%2C1%2C0%2C0%2C1-1%2C1H15a1%2C1%2C0%2C0%2C1%2C0-2h7A1%2C1%2C0%2C0%2C1%2C23%2C10Zm0%2C5a1%2C1%2C0%2C0%2C1-1%2C1H2a1%2C1%2C0%2C0%2C1%2C0-2H22A1%2C1%2C0%2C0%2C1%2C23%2C15Zm0%2C6a1%2C1%2C0%2C0%2C1-1%2C1H2a1%2C1%2C0%2C0%2C1%2C0-2H22A1%2C1%2C0%2C0%2C1%2C23%2C21Z%22%2F%3E%3C%2Fsvg%3E",tooltip:"Copy question as Markdown",handler:(e,t)=>function(e,t,n=0){return n>=1&&console.log("[turndownConvertAction] Called with element:",e),new Promise(((t,r)=>{let o;if(o=document.querySelector(e),o){n>=2&&console.log("[turndownConvertAction] Found element, converting to Markdown...");const e=(new R).turndown(o.innerHTML);navigator.clipboard.writeText(e).then((()=>{n>=1&&console.log("[turndownConvertAction] Copied Markdown to clipboard successfully"),t()})).catch((t=>{n>=1&&console.warn("[turndownConvertAction] Failed to copy. Manual copy required:\n",e),prompt("Failed to copy. Please manually copy the text below:",e),r(t)}))}else{const e="[turndownConvertAction] Target element not found.";n>=1&&console.error(e),r(new Error(e))}}))}(".formulation.clearfix",0,t)},{id:"copyMarkdownGfm",name:null,icon:"data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3Csvg%20fill%3D%22%23000000%22%20height%3D%2216px%22%20width%3D%2216px%22%20id%3D%22Layer_1%22%20data-name%3D%22Layer%201%22%20%20%20%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2016%2016%22%3E%20%20%20%20%3Cpath%20class%3D%22cls-1%22%20d%3D%22M14.25%2C3H1.75A.74027.74027%2C0%2C0%2C0%2C1%2C3.73016v8.53968A.74029.74029%2C0%2C0%2C0%2C1.75%2C13h12.5a.74029.74029%2C0%2C0%2C0%2C.75-.73016V3.73016A.74027.74027%2C0%2C0%2C0%2C14.25%2C3ZM7.965%2C10.059H6.97374V7.77311L5.9825%2C9.34956%2C4.99125%2C7.77311V10.059H4V5.934h.91L5.9825%2C7.51038%2C7.055%2C5.934h.91Zm2.45884.0071L8.84766%2C7.94479H9.94749V5.934h.99124V7.94479H12Z%22%2F%3E%3C%2Fsvg%3E",tooltip:"Copy question as Markdown using Gfm Plugin",handler:(e,t)=>async function(e="textarea.coderunner-answer.edit_code",t,n=0,r={preserveTable:!0,getImageData:!0}){let o;if(n>=1&&console.log("[turndownGfmAction] Called with targetElement:",e),"string"==typeof e?o=document.querySelector(e):e instanceof Element&&(o=e),!o){const t=`[turndownGfmAction] Target element "${e}" not found.`;return n>=1&&console.error(t),Promise.reject(new Error(t))}r.getImageData&&await Y(o,n);const i=new R;i.use(q),r.preserveTable&&i.addRule("preserveTable",{filter:function(e){return"table"===e.nodeName.toLowerCase()},replacement:function(e,t){return"\n\n"+t.outerHTML+"\n\n"}});const a=i.turndown(o.innerHTML);return n>=2&&console.log("[turndownGfmAction] Markdown output:",a),navigator.clipboard.writeText(a).then((()=>{n>=1&&console.log("[turndownGfmAction] Markdown successfully copied to clipboard.")})).catch((e=>(n>=1&&console.warn("[turndownGfmAction] Clipboard write failed, using prompt fallback. Markdown:\n",a),prompt("Failed to copy automatically. Please manually copy the text below:",a),Promise.reject(e))))}(".formulation.clearfix",0,t,{preserveTable:!0,getImageData:!0})},{id:"btnCopyCode",name:null,icon:"data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3Csvg%20width%3D%2216px%22%20height%3D%2216px%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20d%3D%22M21%208C21%206.34315%2019.6569%205%2018%205H10C8.34315%205%207%206.34315%207%208V20C7%2021.6569%208.34315%2023%2010%2023H18C19.6569%2023%2021%2021.6569%2021%2020V8ZM19%208C19%207.44772%2018.5523%207%2018%207H10C9.44772%207%209%207.44772%209%208V20C9%2020.5523%209.44772%2021%2010%2021H18C18.5523%2021%2019%2020.5523%2019%2020V8Z%22%20fill%3D%22%230F0F0F%22%2F%3E%3Cpath%20d%3D%22M6%203H16C16.5523%203%2017%202.55228%2017%202C17%201.44772%2016.5523%201%2016%201H6C4.34315%201%203%202.34315%203%204V18C3%2018.5523%203.44772%2019%204%2019C4.55228%2019%205%2018.5523%205%2018V4C5%203.44772%205.44772%203%206%203Z%22%20fill%3D%22%230F0F0F%22%2F%3E%3C%2Fsvg%3E",tooltip:"Copy code area to clipboard",handler:(e,t)=>function(e="textarea.coderunner-answer.edit_code",t,n=0){n>=1&&console.log("[copyCodeAreaAction] Called for element:",e);const r=document.querySelector(e);if(!r){const t=`Target textarea (${e}) not found.`;return n>=1&&console.error("[copyCodeAreaAction]",t),Promise.reject(new Error(t))}const o=r.value;return navigator.clipboard.writeText(o).then((()=>(n>=1&&console.log("[copyCodeAreaAction] Successfully copied text:",o),o))).catch((e=>{n>=1&&console.warn("[copyCodeAreaAction] Clipboard copy failed, using prompt fallback:",e);const t=prompt("Failed to copy automatically. Please manually copy the text below:",o);return null!==t?Promise.resolve(t):Promise.reject(new Error("User cancelled prompt."))}))}("textarea.coderunner-answer.edit_code",0,t)},{id:"btnReplaceCode",name:null,icon:"data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3Csvg%20fill%3D%22%23000000%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20%20%20width%3D%2216px%22%20height%3D%2216px%22%20viewBox%3D%220%200%2052%2052%22%20enable-background%3D%22new%200%200%2052%2052%22%20xml%3Aspace%3D%22preserve%22%3E%3Cg%3E%20%3Cpath%20d%3D%22M17.5%2C12h17c0.8%2C0%2C1.5-0.7%2C1.5-1.5V6c0-2.2-1.8-4-4-4H20c-2.2%2C0-4%2C1.8-4%2C4v4.5C16%2C11.3%2C16.7%2C12%2C17.5%2C12z%22%2F%3E%20%3Cpath%20d%3D%22M44%2C6h-2.5C40.7%2C6%2C40%2C6.7%2C40%2C7.5V12c0%2C2.2-1.8%2C4-4%2C4H16c-2.2%2C0-4-1.8-4-4V7.5C12%2C6.7%2C11.3%2C6%2C10.5%2C6H8%20%20c-2.2%2C0-4%2C1.8-4%2C4v36c0%2C2.2%2C1.8%2C4%2C4%2C4h36c2.2%2C0%2C4-1.8%2C4-4V10C48%2C7.8%2C46.2%2C6%2C44%2C6z%20M38%2C41c0%2C0.6-0.4%2C1-1%2C1H15c-0.6%2C0-1-0.4-1-1v-2%20%20c0-0.6%2C0.4-1%2C1-1h22c0.6%2C0%2C1%2C0.4%2C1%2C1V41z%20M38%2C33c0%2C0.6-0.4%2C1-1%2C1H15c-0.6%2C0-1-0.4-1-1v-2c0-0.6%2C0.4-1%2C1-1h22c0.6%2C0%2C1%2C0.4%2C1%2C1V33z%20%20%20M38%2C25c0%2C0.6-0.4%2C1-1%2C1H15c-0.6%2C0-1-0.4-1-1v-2c0-0.6%2C0.4-1%2C1-1h22c0.6%2C0%2C1%2C0.4%2C1%2C1V25z%22%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E",tooltip:"Paste (replace) code area from clipboard",handler:(e,t)=>function(e="textarea.coderunner-answer.edit_code",t,n=0){n>=1&&console.log("[replaceCodeAreaAction] Called for element:",e);const r=document.querySelector(e);if(!r){const t=`Target textarea (${e}) not found.`;return n>=1&&console.error("[replaceCodeAreaAction]",t),Promise.reject(new Error(t))}return navigator.clipboard.readText().then((e=>(n>=1&&console.log("[replaceCodeAreaAction] Clipboard text read:",e),r.value=e,e))).catch((e=>{n>=1&&console.warn("[replaceCodeAreaAction] Clipboard read failed, using prompt fallback:",e);const t=prompt("Failed to read from clipboard. Please paste your text:","");return null!==t?(r.value=t,t):Promise.reject(new Error("User cancelled prompt."))}))}("textarea.coderunner-answer.edit_code",0,t)},{id:"btnCopyOutcome",name:null,icon:"data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3Csvg%20fill%3D%22%23000000%22%20height%3D%2216px%22%20width%3D%2216px%22%20version%3D%221.1%22%20id%3D%22XMLID_207_%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20%20%20viewBox%3D%220%200%2024%2024%22%20xml%3Aspace%3D%22preserve%22%3E%3Cg%20id%3D%22test%22%3E%20%3Cg%3E%20%20%3Cpath%20d%3D%22M23%2C24H1v-4.3l7-12V2H6V0h12v2h-2v5.7l7%2C12V24z%20M12%2C22h9v-1.7l-3.4-5.9l0%2C0c-2.6-1.5-3.9-0.8-5.4-0.1S9%2C15.7%2C6.5%2C14.5%20%20%20l-3.4%2C5.9V22H12z%20M7.4%2C12.7C9%2C13.4%2C10%2C13%2C11.3%2C12.4c1.2-0.5%2C2.7-1.2%2C4.7-0.7l-2-3.4V2h-4v6.3L7.4%2C12.7z%22%2F%3E%20%3C%2Fg%3E%20%3Cg%3E%20%20%3Ccircle%20cx%3D%2214.5%22%20cy%3D%2217.5%22%20r%3D%221.5%22%2F%3E%20%3C%2Fg%3E%20%3Cg%3E%20%20%3Ccircle%20cx%3D%229.5%22%20cy%3D%2218.5%22%20r%3D%221.5%22%2F%3E%20%3C%2Fg%3E%3C%2Fg%3E%3C%2Fsvg%3E",tooltip:"Copy outcome tests HTML to clipboard",handler:(e,t)=>K("div.outcome.clearfix",0,t)},{id:"btnCopyMain",name:null,icon:"data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%3Csvg%20width%3D%2216px%22%20height%3D%2216px%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20d%3D%22M16.5098%205.01L14.5498%203.05C13.1498%201.65%2010.8498%201.65%209.44977%203.05L7.48977%205.01C7.09977%205.4%207.09977%206.04%207.48977%206.43L11.2998%2010.24C11.6898%2010.63%2012.3198%2010.63%2012.7098%2010.24L16.5198%206.43C16.8998%206.04%2016.8998%205.4%2016.5098%205.01Z%22%20fill%3D%22%23292D32%22%2F%3E%3Cpath%20d%3D%22M5.01%207.49172L3.05%209.45172C1.65%2010.8517%201.65%2013.1517%203.05%2014.5517L5.01%2016.5117C5.4%2016.9017%206.03%2016.9017%206.42%2016.5117L10.23%2012.7017C10.62%2012.3117%2010.62%2011.6817%2010.23%2011.2917L6.43%207.49172C6.04%207.10172%205.4%207.10172%205.01%207.49172Z%22%20fill%3D%22%23292D32%22%2F%3E%3Cpath%20d%3D%22M20.9491%209.45172L18.9891%207.49172C18.5991%207.10172%2017.9691%207.10172%2017.5791%207.49172L13.7691%2011.3017C13.3791%2011.6917%2013.3791%2012.3217%2013.7691%2012.7117L17.5791%2016.5217C17.9691%2016.9117%2018.5991%2016.9117%2018.9891%2016.5217L20.9491%2014.5617C22.3491%2013.1517%2022.3491%2010.8517%2020.9491%209.45172Z%22%20fill%3D%22%23292D32%22%2F%3E%3Cpath%20d%3D%22M7.48907%2018.9891L9.44907%2020.9491C10.8491%2022.3491%2013.1491%2022.3491%2014.5491%2020.9491L16.5091%2018.9891C16.8991%2018.5991%2016.8991%2017.9691%2016.5091%2017.5791L12.6991%2013.7691C12.3091%2013.3791%2011.6791%2013.3791%2011.2891%2013.7691L7.47907%2017.5791C7.09907%2017.9591%207.09907%2018.5991%207.48907%2018.9891Z%22%20fill%3D%22%23292D32%22%2F%3E%3C%2Fsvg%3E",tooltip:"Copy Main HTML to clipboard",handler:(e,t)=>K('div[role="main"]',0,t)}],!0)}();
@glenkusuma
Copy link
Author

glenkusuma commented Mar 19, 2025

To utilize the toolbox by injecting custom JavaScript into your desired websites, follow these steps:

  1. Install the Custom JavaScript for Websites 2 Extension:

    This browser extension allows you to run custom JavaScript on any website.

  2. Inject the toolbox Script Using a GitHub Gist:

    To inject the toolbox into your target website:

    • Open the Custom JavaScript for Websites 2 extension on the website where you want to inject the script.

    • Paste the following code into the extension's editor:

      customjsReady('body', function (element) {
        fetch('https://gist.githubusercontent.com/glenkusuma/fd78731193257a9c92ef361707659afa/raw/e78f6f2f3c98b598dec5ade3a1439bcce030818e/toolbox.js')
          .then(res => res.text())
          .then(js => {
            eval(js);
          })
          .catch(err => console.error(err));
      });
    • Save the changes within the extension.

    • Refresh the webpage to apply the injected script.

Note: Ensure that the GitHub Gist URL in the fetch function points to the raw JavaScript file of the toolbox. This method allows you to dynamically load and execute the toolbox on specified websites.

For a visual walkthrough on installing and using the Custom JavaScript for Websites 2 extension, you might find this tutorial helpful:
How To Install The Custom Javascript For Websites 2 Plugin In Google Chrome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment