Last active
November 5, 2022 22:35
-
-
Save HT-7/e3772d4afbc18970a3f105481bac44db to your computer and use it in GitHub Desktop.
downloadDOM – Save pages as lightweight HTML documents with one click! A file name with domain name and time stamp is automatically generated.
This file contains 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
function download(filename, text) { | |
var tmp_node = document.createElement('a'); | |
tmp_node.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); | |
tmp_node.setAttribute('download', filename); | |
tmp_node.style.display = 'none'; | |
document.body.appendChild(tmp_node); | |
tmp_node.click(); | |
document.body.removeChild(tmp_node); | |
} | |
function downloadDOM(include_title,comment) { | |
download( | |
( document.title && include_title ? document.title + "." : "") | |
+ window.location.hostname | |
+ "." | |
+ ( comment != undefined ? comment + "." : "" ) | |
// Avoiding colons for file system compatibilty and foregoing replaceAll() for browser compatibility. | |
+ new Date().toISOString().replace(":","-").replace(":","-") | |
+ ".DOM.html" | |
// Generates the file name. | |
, "<!-- Downloaded on " + new Date().toISOString() + " from " + document.location + " using downloadDOM. -->\n" | |
// Notes the source URL and time stamp inside the file. | |
+ new XMLSerializer().serializeToString(document) | |
// Similar to document.documentElement.outerHTML, but includes text outside <html></html>. | |
); | |
} | |
downloadDOM(true); |
This file contains 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
javascript:function download(e,t){var o=document.createElement("a");o.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),o.setAttribute("download",e),o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o)}function oneClickSave(e,t){download((document.title&&e?document.title+".":"")+window.location.hostname+"."+(void 0!=t?t+".":"")+new Date().toISOString().replace(":","-").replace(":","-")+".DOM.html","<!-- Downloaded on "+new Date().toISOString()+" from "+document.location+" using oneClickSave. -->\n"+new XMLSerializer().serializeToString(document))}function download(e,t){var o=document.createElement("a");o.setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),o.setAttribute("download",e),o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o)}function oneClickSave(e,t){download((document.title&&e?document.title+".":"")+window.location.hostname+"."+(void 0!=t?t+".":"")+new Date().toISOString().replace(":","-").replace(":","-")+".DOM.html","<!-- Downloaded on "+new Date().toISOString()+" from "+document.location+" using oneClickSave. -->\n"+new XMLSerializer().serializeToString(document))}oneClickSave(!0),oneClickSave(!0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment