jcunews

InsertLinkFileInfo Bookmarklet

Nov 10th, 2021 (edited)
793
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:
  2. /*InsertLinkFileInfo*/
  3. ((l, i, a) => {
  4.   if (!document || !document.body || document.body.dataset.ilfi) return;
  5.   document.body.dataset.ilfi = 1;
  6.   if (!(l = document.querySelectorAll("A")).length) {
  7.     delete document.body.dataset.ilfi;
  8.     alert("No link found.");
  9.     return
  10.   }
  11.   i = 0;
  12.   (function pr(s, u) {
  13.     while (a = l[i++]) {
  14.       if (a.pathname.substr(-1) !== "/") {
  15.         fetch(a.href, {method: "HEAD", redirect: "error", keepalive: true}).catch(e => {
  16.           a.insertAdjacentHTML("afterend", ` [NetErr]`)
  17.           pr()
  18.         }).then((r, d) => {
  19.           if (r.status < 400) {
  20.             if (!isNaN(s = parseInt(r.headers.get("Content-Length")))) {
  21.               if (s > 1023) {
  22.                 if ((s /= 1024) > 1023) {
  23.                   if ((s /= 1024) > 1023) {
  24.                     if ((s /= 1024) > 1023) {
  25.                       s = (s / 1024).toFixed(0) + "TB"
  26.                     } else s = s.toFixed(0) + "GB"
  27.                   } else s = s.toFixed(0) + "MB"
  28.                 } else s = s.toFixed(0) + "KB"
  29.               }
  30.             } else s = "???";
  31.             if (d = r.headers.get("Last-Modified")) {
  32.               s += ", " + (new Date(d)).toLocaleString()
  33.             } else s+= ", ???";
  34.             s = ` [${s}]`
  35.           } else s = ` [Err${r.status}]`;
  36.           a.insertAdjacentHTML("afterend", s);
  37.           pr()
  38.         });
  39.         return
  40.       }
  41.     }
  42.     delete document.body.dataset.ilfi
  43.   })()
  44. })()
Add Comment
Please, Sign In to add comment