Skip to content

Instantly share code, notes, and snippets.

View DarrenSem's full-sized avatar

Darren Semotiuk DarrenSem

View GitHub Profile
@DarrenSem
DarrenSem / consoleRestore.js
Last active April 14, 2025 17:20
consoleRestore.js -- Bookmarklet to bring back [something close to] the native console.log() etc. that have been replaced with a custom override (e.g. by Microsoft Teams April 2025)
// consoleRestore.js -- Bookmarklet to bring back [something close to] the native console.log() etc. that have been replaced with a custom override (e.g. by Microsoft Teams April 2025)
// https://gist.github.com/DarrenSem/48f853b2bca6d8334320affde48e225e
// also adds `console.tableEach(...args)` = args.forEach( arg => console.table(arg) ) + `console.dirEach(...args)`
// ^ purpose and examples here: https://gist.github.com/DarrenSem/a0109f95056c0c2512fe2abeb930bab2
// Silent: 398 char javascript:void function(){(()=>{const a="table",b=console,c=/\bnative code|^\(\.\.\.\w+\)=>\w+\.(forEach\(\w+=>\w+(\[\w+\])|\.assert)\(/;if(!c.test(b.log)){const d=c.test(b[a])?(...c)=>c.forEach(c=>b[a](c)):(...a)=>b.assert(!1,"\n",...a);["debug","error","info","log","warn"].forEach(a=>b[a]=d)}return b.tableEach=(...a)=>a.forEach(a=>b.table(a)),b.dirEach=(...a)=>a.forEach(a=>b.dir(a)),b})()}();
@DarrenSem
DarrenSem / width.js
Last active April 14, 2025 15:51
width.js - Bookmarklet for OpenAI playground to fix maxWidth of "Configure" panel (due to latest layout update); add as browser Favorite then click to toggle visibility
// width.js - Bookmarklet for OpenAI playground to fix maxWidth of "Configure" panel (due to latest layout update); add as browser Favorite then click to toggle visibility
// https://gist.github.com/DarrenSem/0d9da09fc5a7b95abcc0df95d65b02c7
// 05Apr2025 234pm: will now FIRST close "Configure" if already opened as slide-in panel version (could have BOTH versions visible!)
// 2016 char javascript:void function(){const a=null,b="innerText",c=(b,c=1)=>{let d=b;for(;c--&&(d=d?.parentElement););return d||a},d=(a,b)=>a.test(b??""),e=()=>{const a=document.querySelectorAll("button > span > span + span.sr-only"),c=Array.from(a).filter((a,c)=>{const e=a[b],f=d(/Configure/,e);return console.log({isTextConfigure:f,text:e,el:a,i:c}),f});return console.log({collConfigureButtons:c,collButtonSpans:a,selButtonSpans:"button > span > span + span.sr-only"}),c},f=e=>{let f,g,h=a;const i=c(e,1),j=i.querySelectorAll("button");for(f of j)if(g=f.dataset,console.log({dataset:g,elButton:f}),!d(/\S/,f[b])&&"secondary"==g?.color&&"md"
@DarrenSem
DarrenSem / above(parentElement).js + next(siblingElement).js
Created April 14, 2025 15:48
above.js (PARENT element, levels = #) + next.js (SIBLING element, levels = #) helper functions instead of foo.parentElement.parentElement.parentElement etc.
// above.js (PARENT element, levels = #) + next.js (SIBLING element, levels = #) helper functions instead of foo.parentElement.parentElement.parentElement etc.
// https://gist.github.com/DarrenSem/4d37711fb71a484b6ed2356c60e3c94a
// PARENT element: ...
const above = (startingElement, levels = 1) => {
let el = startingElement;
while ( levels-- && (el = el?.parentElement) );
return el || null;
@DarrenSem
DarrenSem / console.tableEach.js + console.dirEach().js
Last active April 12, 2025 20:18
console.tableEach(...args) = args.forEach( arg => console.table(arg) ) - and also console.dirEach().js
// console.tableEach() - and also console.dirEach().js
/////////////////////
console.tableEach = (...args) => args.forEach( arg => console.table(arg) );
// comparing native log() and table() functions vs. new custom function tableEach()...
@DarrenSem
DarrenSem / SwapBranches(GitHub compare).js
Last active April 11, 2025 16:48
SwapBranches(GitHub compare).js -- Bookmarklet for toggling/reversing order of [base: targetBranch] <-- [compare: sourceBranch]
// SwapBranches(GitHub compare).js -- Bookmarklet for toggling/reversing order of [base: targetBranch] <-- [compare: sourceBranch]
// 287 char: javascript:void function(){const a=a=>{const b=a?.href??a??"",c=/(\/compare\/)([^.\/]+)\.\.\.([^.\/]+)/;return c.test(b)?b.replace(c,(a,b,c,d)=>`${b}${d}...${c}`):b},b=(b=location)=>{const c=b?.href??b??"",d=a(c);return c!=d&&((b?.href?b:{}).href=d)};console.clear(),console.log(b())}();
const getSwappedGitHubBranches = (url) => {
const href = url?.href ?? url ?? "";
const pattern = /(\/compare\/)([^.\/]+)\.\.\.([^.\/]+)/;
const replacer = (_, prefix, branch1, branch2) => `${prefix}${branch2}...${branch1}`
@DarrenSem
DarrenSem / DLasMD - DOWNLOAD contents as MarkDown.js
Last active March 8, 2025 18:14
console.save.js + DOWNLOAD contents as MarkDown.js -- download your JavaScript objects from your web browser's F12 Dev Tools console! (also Bookmarklet click defaults to saving prompt text data or body.innerText as `DL-[date].md`)
// DLasMD - DOWNLOAD contents as MarkDown.js
// old as of 15Jan2025; start using DLasMD-console.save.js
// 27Dec2024 1053am NEW promptData rules (Blank or Empty or =FILENAME.EXT defaults to document.body.innerText)
// 477 char javascript:void function(){let a=document,b=(b,c=`DL-${+new Date}.md`,d="octet-stream")=>{let e=URL.createObjectURL(new Blob([b],{type:d}));Object.assign(a.createElement("a"),{href:e,download:c}).click(),URL.revokeObjectURL(e)},c=prompt("Enter data to download...\n\n(Blank or Empty or =FILENAME.EXT defaults to document.body.innerText)")?.trim();if(null!=c){let d=c.startsWith("=")&&c.slice(1);b(c.length&&!d?c:a.body.innerText,d?`${d}${d.includes(".")?"":".md"}`:void 0)}}();
let doc=document;
let saveDataAsFilenameMime = (
@DarrenSem
DarrenSem / innerText.js
Last active January 26, 2025 18:33
innerText.js bookmarklet for mobile (to show webpage text contents OR html) (including PARTIAL source of SELECTION)
// 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??
@DarrenSem
DarrenSem / ordinal.js
Created July 10, 2022 21:41
ordinal.js - one-liner returns ordinal(1)="1st", (2)="2nd", (3)="3rd", (11)="11th", (21)="21st", (111)="111th", (121)="121st", etc.
// ordinal.js - one-liner returns ordinal(1)="1st", (2)="2nd", (3)="3rd", (11)="11th", (21)="21st", (111)="111th", (121)="121st", etc.
let ordinal = num => `${num}${[, "st", "nd", "rd"][ (num % 100 < 11 || num % 100 > 13) && (num % 10) ] || "th"}`;
// ^ Final Answer. (below = the story of how I got there...)
"use strict";// ordinal.js - one-liner returns ordinal(1)="1st", (2)="2nd", (3)="3rd", (11)="11th", (21)="21st", (111)="111th", (121)="121st", etc.
let ordinal = num => `${num}${[, "st", "nd", "rd"][ (num % 100 < 11 || num % 100 > 13) && (num % 10) ] || "th"}`;
@DarrenSem
DarrenSem / store.js
Created November 26, 2022 22:26
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
// 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)
) => {
@DarrenSem
DarrenSem / Math.sum [ , Math.avg , Math.max , Math.sum ] .js
Created November 24, 2022 18:06
Math.sum.js and Math.avg (average) and Math.max and Math.sum -- ALL will automatically flatten (all, args, passed, [[even, [, Arrays]]])
// 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] }