Advertisement
jcunews

ResourceList bookmarklet

Mar 27th, 2022
1,249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:/*ResourceList*/
  2. ((l) => {
  3.   function add(u, m, o) {
  4.     if (!(m = u.match(/\.[0-9a-z]*(?:[&#'"]|$)/))) m = ["."];
  5.     if (!l[m[0]]) l[m[0]] = new Set;
  6.     l[m[0]].add(u)
  7.   }
  8.   l = {};
  9.   document.querySelectorAll('*').forEach((e, m) => {
  10.     if (e.href && (m = e.href.match(/https?:\/\/[^&#'"]+/))) add(m[0]);
  11.     if (e.src && (m = e.src.match(/https?:\/\/[^&#'"]+/))) add(m[0]);
  12.     if (m = getComputedStyle(e).backgroundImage.match(/https?:\/\/[^'"\)]+/)) add(m[0]);
  13.   }, []);
  14.   document.documentElement.insertAdjacentHTML("beforeend", `<div id=llbm><style>
  15. #llbm,#llbm *{all:revert}
  16. #llbm{position:fixed;z-index:9999999999999;left:0;top:0;right:0;bottom:0;background:rgb(0,0,0,.5);cursor:pointer;font:12pt/normal sans-serif}
  17. #llbmc{position:fixed;left:50vw;top:50vh;transform:translate(-50%,-50%);border:.2em solid #000;border-radius:.3em;background:#fff;max-width:90vw;max-height:90vh;cursor:auto}
  18. #llbmo{position:relative;height:100%}
  19. #llbmh{padding:0 .2em;background:#000;color:#fff;text-align:center;font-weight:bold}
  20. #llbm th{padding:0 .2em;background:#777;color:#fff;text-align:center}
  21. #llbm td{vertical-align:top}
  22. #llbmt{max-height:77vh}
  23. #llbmu{max-height:75vh;overflow-x:hidden;overflow-y:auto}
  24. #llbmu>div{padding:.1em .2em}
  25. #llbmu>div:nth-child(2n){background:#eee}
  26. #llbmu a{word-break:break-all}
  27. </style><div id=llbmc><div id=llbmo>
  28. <div id=llbmh>Resource List</div>
  29. <table><thead><tr><th>Type</th><th>URLs</th></tr></thead>
  30. <tbody><tr><td><select id=llbmt>${
  31.   Object.keys(l).map(k => k !== "." ? k : "Page/Unknown").sort().map(k => `<option value="${k[0] === "." ? k : "."}">${k}</option>`)
  32. }</select></td><td><div id=llbmu></div></td></tr></tbody>
  33. </table></div></div></div>`);
  34.   llbm.onclick = ev => (ev.target === llbm) && llbm.remove();
  35.   llbmt.onchange = (c, a, x) => {
  36.     x = 40;
  37.     c = llbmu.cloneNode(false);
  38.     Array.from(l[llbmt.value]).sort().forEach((u, e, m) => {
  39.       c.appendChild(document.createElement("DIV")).appendChild(e = document.createElement("A")).href = u;
  40.       (m = decodeURIComponent(u).match(/^.*?:\/\/([^\/]+\/)(?:([^?]+)(\?.*)|(.*))?/)).shift();
  41.       if (m[3]) {
  42.         m.splice(1, 2);
  43.         if (m[1] && (m[1].length > x)) m[1] = m[1].substr(0, x) + "..." + m[1].substr(-x);
  44.       } else {
  45.         if (m[1] && (m[1].length > x)) m[1] = m[1].substr(0, x) + "..." + m[1].substr(-x);
  46.         if (m[2] && (m[2].length > x)) m[2] = m[2].substr(0, x) + "...";
  47.       }
  48.       e.textContent = m.join("");
  49.     });
  50.     llbmu.replaceWith(c)
  51.   };
  52.   llbmt.size = llbmt.childElementCount > 1 ? llbmt.childElementCount : 2;
  53.   llbmt.selectedIndex = 0;
  54.   llbmt.onchange()
  55. })()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement