Kawiesh

List/Filter Links

Nov 3rd, 2020 (edited)
2,965
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. From@ http://subsimple.com/bookmarklets/collection_links.php
  2.  
  3.  
  4. javascript: (function() {
  5.     var x, n, nD, z, i, h = '';
  6.  
  7.     function htmlEscape(s) {
  8.         s = s.replace(/&/g, '&');
  9.         s = s.replace(/>/g, '>');
  10.         s = s.replace(/</g, '&lt;');
  11.         return s;
  12.     }
  13.  
  14.     function attrQuoteEscape(s) {
  15.         s = s.replace(/&/g, '&amp;');
  16.         s = s.replace(/"/g, '&quot;');
  17.         return s;
  18.     }
  19.     x = prompt("Leave blank to list all links or filter links on this page containing this word/phrase:", "");
  20.     n = 0;
  21.     if(x != null) {
  22.         x = x.toLowerCase();
  23.         nD = window.open().document;
  24.         h += '<html>
  25. <head>
  26. <title>Links containing "' + htmlEscape(x) + '"</title>
  27. <base target="_blank">
  28. </head>
  29. <body>
  30. ' + 'List of links on <a href="' + attrQuoteEscape(location.href) + '">' + htmlEscape(location.href) + '</a><br>
  31. with link text/target URL containing &quot;' + htmlEscape(x) + '&quot;<br>
  32. <hr>
  33. <table>';
  34.         z = document.links;
  35.         for(i = 0; i < z.length; ++i) {
  36.             if((z[i].innerHTML && z[i].innerHTML.toLowerCase().indexOf(x) != -1) || z[i].href.toLowerCase().indexOf(x) != -1) {
  37.                 h += '<tr><td>' + (++n) + '. ' + z[i].innerHTML + '</td><td><a href="' + htmlEscape(z[i].href) + '">' + htmlEscape(z[i].href) + '</a></td</tr>';
  38.             }
  39.         }
  40.         h += '
  41. </table>
  42. </body>
  43. </html>';
  44.         nD.writeln(h);
  45.         nD.close();
  46.     }
  47. })();
Advertisement
Add Comment
Please, Sign In to add comment