Skip to content

Instantly share code, notes, and snippets.

@DarrenSem
Last active April 14, 2025 17:20
Show Gist options
  • Save DarrenSem/48f853b2bca6d8334320affde48e225e to your computer and use it in GitHub Desktop.
Save DarrenSem/48f853b2bca6d8334320affde48e225e to your computer and use it in GitHub Desktop.
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})()}();
// With extra logging including before vs after: 659 char javascript:void function(){"use strict";console.clear?.(),console.log?.(["old",console.log,console.log+""],console.log,console.tableEach,console.dirEach,console,console+""),(()=>{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})(),console.log?.(["new",console.log,console.log+""],console.log,console.tableEach,console.dirEach,console,console+"")}();
"use strict";
//// [Silent]
const restoreConsole = () => {
const TABLE_OR_DIR = ["table", "dir"][0];
const con = console;
// ? ( (...D)=>D.forEach(V=>con[TABLE_OR_DIR](V)) )
// : ( (...A)=>con.assert(false,"\n",...A) )
const reNativeOrTableOrDirOrAssert = /\bnative code|^\(\.\.\.\w+\)=>\w+\.(forEach\(\w+=>\w+(\[\w+\])|\.assert)\(/;
if ( !reNativeOrTableOrDirOrAssert.test(con.log) ) {
const fn = (
reNativeOrTableOrDirOrAssert.test( con[TABLE_OR_DIR] )
? ( (...D)=>D.forEach(V=>con[TABLE_OR_DIR](V)) )
: ( (...A)=>con.assert(false,"\n",...A) )
);
// below = (5), Object.keys(con) = all = (25) ['debug', 'error', 'info', 'log', 'warn', 'dir', 'dirxml', 'table', 'trace', 'group', 'groupCollapsed', 'groupEnd', 'clear', 'count', 'countReset', 'assert', 'profile', 'profileEnd', 'time', 'timeLog', 'timeEnd', 'timeStamp', 'context', 'createTask', 'memory']
['debug', 'error', 'info', 'log', 'warn'] // cf. https://developer.chrome.com/docs/devtools/console/api/
.forEach(key => con[key] = fn);
};
con.tableEach = (...args) => args.forEach( arg => con.table(arg) );
con.dirEach = (...args) => args.forEach( arg => con.dir(arg) );
return con;
};
// restoreConsole();
//// [/Silent]
// debugger;
console.clear?.();
console.log?.( [ "old", console.log, String(console.log) ], console.log, console.tableEach, console.dirEach, console, String(console) );
// console.log = null; debugger; // for easier testing faster comparing "console.table" vs. "console.dir"
restoreConsole();
// debugger;
console.log?.( [ "new", console.log, String(console.log) ], console.log, console.tableEach, console.dirEach, console, String(console) );
@DarrenSem
Copy link
Author

DarrenSem commented Apr 12, 2025

// see also:

console.tableEach = (...args) => args.forEach( arg => console.table(arg) );

console.dirEach = (...args) => args.forEach( arg => console.dir(arg) );

// ^ purpose and examples here: console.tableEach(...args) = args.forEach( arg => console.table(arg) ) - and also console.dirEach().js
// https://gist.github.com/DarrenSem/a0109f95056c0c2512fe2abeb930bab2

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