User:Elominius/One-click saver.js

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 ISO8601_file_name { return new Date.toISOString.replace(":","-").replace(":","-"); }

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.        + ISO8601_file_name        + ".DOM.html"        // Generates the file name.

, "\n" // Notes the source URL and time stamp inside the file.

+ new XMLSerializer.serializeToString(document) // Similar to document.documentElement.outerHTML, but includes text outside. ); } oneClickSave(true);