This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| console.log("TOP"); | |
| exports.importedInfo = [, 3, 6, 9, exports && exports.length, "someGlobal:", typeof someGlobal !== "undefined" && someGlobal]; | |
| module.exports.xyz = 123; | |
| alert('executing xt.js?' + location.href); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // HTML.js - display full webpage source (document.documentElement.outerHTML) into a new tab popup | |
| // RUN = 304 char: javascript:void function(){let a=open("about:blank").document,b=a.body;b.appendChild(a.createElement("b")).innerText=a.title=`Source code of ${location.href}`;let c=b.appendChild(a.createElement("pre"));c.innerText=document.documentElement.outerHTML,c.style.whiteSpace="pre-wrap",c.style.color="blue"}(); | |
| let doc = open('about:blank').document; | |
| let body = doc.body; | |
| let tagForTitle = "b"; | |
| body.appendChild(doc.createElement(tagForTitle)).innerText = doc.title = `Source code of ${location.href}`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // selectedHtml.js -- returns [htmlString, htmlString.length] , args are ALL optional ( doc, selection = doc.getSelection(), range = selection.getRangeAt(0) ) | |
| // const selectedHtml=(b=document,c=b.getSelection(),d=c&&c.getRangeAt(0),e=d&&a.createElement("div"),f=e?(e.appendChild(d.cloneContents()),e.innerHTML):"")=>[f,f.length]; | |
| const selectedHtml = ( | |
| _doc = document, | |
| _sel = _doc.getSelection(), // "You can call Window.getSelection(), which works identically to Document.getSelection()." https://developer.mozilla.org/en-US/docs/Web/API/Document/getSelection | |
| _range = _sel && _sel.getRangeAt(0), | |
| _el = _range && doc.createElement("div"), | |
| _result = !_el ? "" : ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // htmlDecode.js htmlEncode.js - using modern browsers' built-in DOM manipulation (plus common escaping for htmlEncode) | |
| // let htmlDecode=a=>Object.assign(document.createElement("textarea"),{innerHTML:null==a?"":a.replace(/<\s*br\s*\/?\s*>/gi,"\n")}).value; | |
| let htmlDecode = html => Object.assign( | |
| document.createElement("textarea"), { | |
| innerHTML: html == null ? "" : html.replace(/<\s*br\s*\/?\s*>/gi, "\n") | |
| } | |
| ).value; | |
| // let htmlEncode=a=>Object.assign(document.createElement("div"),{innerText:null==a?"":a}).innerHTML.replace(/<br>/g,"\n").replace(/['"\t\f\r\n\u00A0-\u2666]/g,a=>({"'":"'",'"':"""})[a]||`&#${a.charCodeAt(0)};`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // store.js ALL-IN-ONE function: () = dump Storage, (keyOrNS, value OTHER THAN undefined) = return value after setting it, (keyOrNS) = return value - UNDEFINED if missing, (null, keyOrNS) = removeItem(keyOrNS) then return keyOrNS | |
| // let store=(k,d,s=localStorage,z=s.getItem(k))=>null==k?null==d?s:(s.removeItem(d),d):void 0===d?null==z?void 0:JSON.parse(z):(s.setItem(k,JSON.stringify(d,0,"\t")),d); | |
| let store = ( | |
| keyOrNS, | |
| data, | |
| storage = [localStorage, sessionStorage][0], | |
| _z = storage.getItem(keyOrNS) | |
| ) => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Math.sum.js and Math.avg and Math.max and Math.sum -- ALL will automatically flatten (all, args, passed, [[even, [, Arrays]]]) | |
| console.log(Math.sum); | |
| // undefined | |
| console.log(Math.avg); | |
| // undefined | |
| console.log(Math.max); | |
| // ƒ max() { [native code] } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // randomWithSeed.js - use rnd() after rnd = createRandomWithSeed( seed [0+] = Date.now() ) - Math.random is less than 2x faster than this 'good enough' SEED-able version | |
| let createRandomWithSeed = seed => { | |
| seed = Math.abs(isNaN(seed) ? Date.now() : seed); | |
| return () => { | |
| seed = (seed * 9301 + 49297) % 233280; | |
| return seed / 233280; | |
| }; | |
| }; | |
| // R=s=>(s=Math.abs(isNaN(s)?Date.now():s),_=>(s=(9301*s+49297)%233280,s/233280)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // innerText.js bookmarklet for mobile (to show webpage text contents OR html) (including PARTIAL source of SELECTION) | |
| // https://gist.github.com/DarrenSem/7e1216bda80e6269ad53b43d90603158 | |
| // 26Jan2025 BUGFIX: now missing ONLY the "System instructions" section (one extra div layer was added SIGH) | |
| // 4784 char javascript:void function(){"use strict";const e="main div[data-collapsed",n="engine-select",t=`div.model-select>button>span`,d=[]._,i=((e,t,i,a,n,l,d,r)=>(t=new Date(e||Date()),[i,a,,n]=t.toLocaleTimeString().replace(/(a|p)\.(m)\./i,"$1$2").split(/\W/),[,,l,d]=t.toString().split(" "),r=t.toLocaleString().replace(/(\d+)-(\d+)-(\d+)/,"$2/$1/$3").split("/")[0].padStart(2,0),`${i}${a}${(n||"").toLowerCase()} ${d}-${r}-${l}`))(),a=`${""} ${i}`,l=top.document,r=location,u=(e,n)=>(n||l).querySelectorAll(e||null),o=(e,n)=>{const t=e?.[n?"value":x],i=t==d?d:n?t:t.replace(/\n{3,}/g,"\n\n\n").replace(/\n\n/g,"\n");return i},f=e=>e.trim(),s=e=>(e??"").replace(/\nSYNC$/i,"").replace(/ INSTRUCTIONS$/i,""),c=e=>(e?? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // contentsInNewWindow.js - F5-REFRESHABLE! - with TITLE! - (contents = '' or [], title, type = 'octet-stream', array-joining-delim = '\n\n') | |
| // const contentsInNewWindow=(c=[],T,t="octet-stream",d="\n\n")=>{const w=open(URL.createObjectURL(new Blob([[c].flat(1/0).join(d)],{type:"text"===t?t+"/plain;charset=utf-8":t})),"_blank");return w&&!w.closed&&(w.onload=()=>w.document.title=T),w}; | |
| const contentsInNewWindow = (contents = [], title, type = ["text", "octet-stream"][1], delim = "\n\n") => { | |
| const win = open( | |
| URL.createObjectURL( | |
| new Blob([ | |
| [contents].flat(1/0).join(delim) | |
| ], { | |
| // auto-UTF8 if type === 'text', to easily ensure visible emojis etc. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // sorted.js (array, strFlags) returns CLONE (not in-place sort!) -- flags 'uid': u=Unique original values, i=case Insensitive compare function, d=Descending (reverse) order | |
| // minified = 179 chars s=(a,f="",c=a=>f.includes(a),d=[...(c("u")?[...new Set(a)]:a)])=>(d=c("i")?d.sort((a,b,c=(a+"").toUpperCase(),d=(b+"").toUpperCase())=>c<d?-1:c===d):d.sort(),c("d")?d.reverse():d) | |
| let sorted = (array, strFlags = "", | |
| // friendlier syntax like RegExp( _, strFlags ) rather than fetch( _, {options} ) | |
| _tmp_HasFlag = flag => strFlags.includes(flag), | |
| // work with CLONE of original array (or Set made from it) -- we do NOT want to do IN-PLACE sort |