Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- javascript: /*DOMSnapshotDownload*/ (rl => {
- function htm(t, m, a, c, x) {
- if(document.head && !document.head.querySelector("base")) {
- (x = document.createElement("BASE")).href = location.href.split("?")[0];
- document.head.appendChild(x)
- } else x = null;
- t = true;
- c = document.contentType;
- m = Array.from(document.childNodes).map((nd, i) => {
- switch (nd.nodeType) {
- case Node.COMMENT_NODE:
- case Node.TEXT_NODE:
- return `<!--${nd.data}-->\n`;
- case Node.ELEMENT_NODE:
- return nd.outerHTML + "\n";
- case Node.DOCUMENT_TYPE_NODE:
- t = !(nd.publicId || nd.systemId);
- return `<!${(/\bxml\b/).test(c) ? "DOCTYPE" : "doctype"} ${nd.name}${
- nd.publicId ? ` PUBLIC "${nd.publicId}"` : ""
- }${nd.systemId ? ` "${nd.systemId}"` : ""}>\n`;
- default:
- console.log("Unprocessed node", nd);
- return `<!--(NodeType${nd.nodeType})-->\n`
- }
- });
- if(document instanceof XMLDocument) {
- m.unshift(`<?xml version="1.0" encoding="${document.characterSet}" standalone="${t ? "yes" : "no"}"?>\n`)
- }
- rl.forEach(r => {
- r[1].parentNode.insertBefore(r[0], r[1]);
- r[1].parentNode.removeChild(r[1])
- });
- a = document.createElement("A");
- a.href = URL.createObjectURL(new Blob(m, {type: c}));
- if(!c.includes("xml")) {
- if(x) x.parentNode.removeChild(x);
- if(t = document.title) {
- x = {
- "\"": "\u201c",
- "*": "\u20f0",
- "/": "-",
- ":": "\ua789",
- "<": "\u2264",
- ">": "\u2265",
- "?": "\xbf",
- "\\": "-",
- "|": "\u2502"
- };
- t = t.replace(/["*\/:<>?\\|]/g, c => x[c]) + " - "
- }
- if (!(m = (m = location.pathname.match(/\/([^\/]+)$/)) ? m[1] : "")) t = t.replace(/ - $/, "");
- a.download = t + ((/\.html?$/i).test(m)
- ? m
- : m + "." + ([["xhtml", "xhtml"], ["html", "html"], ["xml", "xml"], ["text", "txt"]].reduce((r, k) => {
- if(!r && c.includes(k[0])) r = k[1];
- return r
- }, "") || "bin"));
- a.target = "_blank";
- a.click()
- } else open(a.href, "_blank")
- }
- function subsEle(ri, u, h, e) {
- e = document.createElement(rl[ri].href ? "style" : "script");
- e.setAttribute("source", u);
- e.innerHTML = h;
- rl[ri] = [rl[ri], e];
- rl[ri][0].parentNode.insertBefore(e, rl[ri][0]);
- rl[ri][0].parentNode.removeChild(rl[ri][0]);
- if(++ri < rl.length) {
- getRes(ri)
- } else htm()
- }
- function getRes(ri, u) {
- u = rl[ri].href || rl[ri].src;
- console.log("Fetching: " + u);
- fetch(u).catch((er, e) => {
- console.log("Error fetching: " + u, er);
- alert(`Error fetching:\n${u}\n\n${er}`);
- subsEle(ri, u, `/* ${er} */`)
- }).then(r => r.text()).then((t, e) => {
- console.log("Fetched: " + u);
- subsEle(ri, u, t)
- })
- }
- rl = Array.from(document.querySelectorAll("link[href][rel=stylesheet],script[src]")).filter(e => e.href || e.src);
- if(rl.length) {
- getRes(0)
- } else htm()
- })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement