Advertisement
Guest User

oneClickSave (new version – September 2022)

a guest
Sep 29th, 2022
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.21 KB | Source Code | 0 0
  1. function download(filename, text) {
  2.   var tmp_node = document.createElement('a');
  3.   tmp_node.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  4.   tmp_node.setAttribute('download', filename);
  5.  
  6.   tmp_node.style.display = 'none';
  7.   document.body.appendChild(tmp_node);
  8.  
  9.   tmp_node.click();
  10.  
  11.   document.body.removeChild(tmp_node);
  12. }
  13.  
  14.  
  15. function oneClickSave(include_title,comment) {
  16.     download(
  17.         ( document.title && include_title ? document.title + "." : "")
  18.         + window.location.hostname
  19.         + "."
  20.         + ( comment != undefined  ? comment + "." : "" )
  21.         // Avoiding colons for file system compatibilty and foregoing replaceAll() for browser compatibility.
  22.         + new Date().toISOString().replace(":","-").replace(":","-")
  23.         + ".DOM.html"
  24.         // Generates the file name.
  25.  
  26.         , "<!-- Downloaded on " + new Date().toISOString() + " from " + document.location + " using oneClickSave. -->\n"
  27.         // Notes the source URL and time stamp inside the file.
  28.  
  29.         + new XMLSerializer().serializeToString(document)
  30.         // Similar to document.documentElement.outerHTML, but includes text outside <html></html>.
  31.     );
  32. }
  33. oneClickSave(true);
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement