获取网页中的全部链接

获取网页中的全部链接。鼠标右键 -> tampermonkey -> "Get All Links"。

  1. // ==UserScript==
  2. // @name Get All Links
  3. // @name:zh-CN 获取网页中的全部链接
  4. // @name:zh-HK 獲取網頁中的全部鏈接
  5. // @name:zh-TW 獲取網頁中的全部鏈接
  6. // @namespace https://tdl3.com/
  7. // @version 0.3.1
  8. // @description Get all links from a website. right-click -> tampermonkey -> "Get All Links".
  9. // @description:zh-CN 获取网页中的全部链接。鼠标右键 -> tampermonkey -> "Get All Links"。
  10. // @description:zh-HK 獲取網頁中的全部鏈接。滑鼠右鍵 -> tampermonkey -> "Get All Links" 。
  11. // @description:zh-TW 獲取網頁中的全部鏈接。滑鼠右鍵 -> tampermonkey -> "Get All Links"。
  12. // @author TDL3
  13. // @match https://tdl3.com/*
  14. // @grant none
  15. // @run-at context-menu
  16. // ==/UserScript==
  17.  
  18. const filter_results = false;
  19. const filter_regex = new RegExp(/png|jpg/g);
  20.  
  21. function make_table(results) {
  22. let table = "<table><thead><th>Names</th><th>Links</th></thead><tbody>";
  23. results.forEach(result => {
  24. table += `<tr><td> ${result.name} </td><td> ${result.url} </td></tr>`;
  25. });
  26. table += "</table>";
  27. window.open("").document.write(table);
  28. }
  29.  
  30. function make_list(results) {
  31. let list = "";
  32. results.forEach(result => {
  33. list += `<div>${result.url}</div>`;
  34. });
  35.  
  36. window.open("").document.write(list);
  37. }
  38.  
  39. function filter_link(link) {
  40. if (!!link.match(filter_regex)) {
  41. return true;
  42. }
  43. return false;
  44. }
  45.  
  46. function get_links() {
  47. let urls = document.querySelectorAll("a");
  48. let results = [];
  49. urls.forEach(url => {
  50. let link_name = url.textContent.replace(/\t|\s+/g, "").trim();
  51. let link = url.href;
  52. if (!filter_results) {
  53. results.push({
  54. name: link_name,
  55. url: link
  56. });
  57. } else if (filter_link(link)) {
  58. results.push({
  59. name: link_name,
  60. url: link
  61. });
  62. }
  63. });
  64. // make_list(results);
  65. make_table(results);
  66. }
  67.  
  68. (function () {
  69. "use strict";
  70. get_links();
  71. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址