Last active
March 8, 2025 18:14
-
-
Save DarrenSem/444cc1c0539226a4902e7f265f23820f to your computer and use it in GitHub Desktop.
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`)
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
// 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 = ( | |
data, | |
filename=`DL-${+new Date}.md`, | |
mimeType = "octet-stream" | |
) => { | |
let href = URL.createObjectURL( | |
new Blob( | |
[data], | |
{ type: mimeType } | |
) | |
); | |
Object.assign( | |
doc.createElement("a"), | |
{ href, download: filename } | |
).click(); | |
URL.revokeObjectURL(href); | |
}; | |
let promptData = prompt( | |
"Enter data to download...\n\n(Blank or Empty or =FILENAME.EXT defaults to document.body.innerText)" | |
)?.trim(); | |
if(promptData != null) { | |
let filename = promptData.startsWith("=") && promptData.slice(1); | |
saveDataAsFilenameMime( | |
promptData.length && !filename | |
? promptData | |
: doc.body.innerText | |
, filename ? `${filename}${filename.includes(".") ? "" : ".md"}` : undefined | |
) | |
}; |
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
// DLasMD-console.save.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`) | |
// javascript:void function(){let a=document,b=Object,c=b._,d="application/octet-stream",e=console,f=()=>a.body.innerText,g=a=>a,h=(c,e=`DL-${+new Date}.md`,f)=>{let g=URL,h=g.createObjectURL(c=new Blob([c],{type:f||c?.type||d}));b.assign(a.createElement("a"),{href:h},!0===e?{target:"_blank"}:{download:e||""}).click(),g.revokeObjectURL(h)};(e.save||=(a,b,e)=>{if(a==c){let d=prompt("Enter data to download...\n\n(Whitespace or =FILENAME.EXT defaults to document.body.innerText)")?.trim();if(d==c)return c;/^=./.test(d)&&(b=d.slice(1),d=0);a=d.length?d:f(),b=!0===b?b:b?`${b}${b.includes(".")?"":".md"}`:c}let g="object"==typeof a;g&&(a=JSON.stringify(a,0,4));h(a,b||`DL-${+new Date}.${g?".json.txt":"md"}`,e||(g?"application/json":d))})()}(); | |
// ^ Bookmarklet (741 char) -- drag-and-drop add this to your web browser's Favorites | |
// (15Jan2025; stop using old "DLasMD - DOWNLOAD contents as MarkDown.js") | |
// inspired by the simple idea @ https://coderwall.com/p/prhwzg/add-console-save-to-chrome https://archive.is/cWiF6 | |
// this GIST url: https://gist.github.com/DarrenSem/444cc1c0539226a4902e7f265f23820f |
Author
DarrenSem
commented
Mar 8, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment