獲取網頁中的全部鏈接

獲取網頁中的全部鏈接,將 @match 改到你想獲得鏈接的網站 。

目前为 2021-02-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Get All Links
  3. // @name:zh-TW 获取网页中的全部链接
  4. // @name:zh-HK 獲取網頁中的全部鏈接
  5. // @name:zh-CN 獲取網頁中的全部鏈接
  6. // @namespace https://tdl3.com/
  7. // @version 0.1.0
  8. // @description Get all links from a website, change @match to the website to which you want to get links.
  9. // @description:zh-TW 获取网页中的全部链接,将 @match 改到你想获得链接的网站。
  10. // @description:zh-HK 獲取網頁中的全部鏈接,將 @match 改到你想獲得鏈接的網站 。
  11. // @description:zh-CN 獲取網頁中的全部鏈接,將 @match 改到你想獲得鏈接的網站 。
  12. // @author TDL3
  13. // @match https://heyeased.weebly.com/*
  14. // @grant none
  15. // @run-at document-idle
  16. // ==/UserScript==
  17.  
  18. function make_table(links_and_names) {
  19. let table = "<table><thead><th>Names</th><th>Links</th></thead><tbody>";
  20. for (const [link, name] of Object.entries(links_and_names)) {
  21. table += `<tr><td> ${name} </td><td> ${link} </td></tr>`;
  22. }
  23. table += "</table>";
  24. window.open("").document.write(table);
  25. }
  26.  
  27. function make_list(links) {
  28. let list = "";
  29. for (let link in links) {
  30. list += `<div>${links[link]}</div>`;
  31. }
  32. window.open("").document.write(list);
  33. }
  34.  
  35. (function () {
  36. "use strict";
  37. let urls = document.querySelectorAll("a");
  38. let links_and_names = {};
  39. const name_regex = new RegExp("/png|jpg$/g");
  40. let res = false
  41. for (let i = 0; i < urls.length; i++) {
  42. let nametext = urls[i].textContent;
  43. let cleantext = nametext.replace(/\t|\s+/g, "").trim();
  44. let cleanlink = urls[i].href;
  45. // uncomment this line to get all links
  46. // let res = name_regex.test(cleanlink);
  47. // remove white spaces and tabs
  48. if (!res) {
  49. links_and_names[cleanlink] = cleantext;
  50. }
  51. }
  52. //make_list(Object.keys(links_and_names));
  53. make_table(links_and_names);
  54. })();