Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 oneClickSave(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 oneClickSave. -->\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>.
- );
- }
- oneClickSave(true);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement