获取网页中的全部链接

获取网页中的全部链接,将 @match 改到你想获得链接的网站。

目前為 2021-02-13 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Get All links from a website
// @name:zh-TW   获取网页中的全部链接
// @name:zh-HK   獲取網頁中的全部鏈接 
// @name:zh-CN   獲取網頁中的全部鏈接 
// @namespace    https://tdl3.com/
// @version      0.1.0
// @description  Get all links from a website, change @match to the website which you want to get link from.
// @description:zh-TW  获取网页中的全部链接,将 @match 改到你想获得链接的网站。
// @description:zh-HK  獲取網頁中的全部鏈接,將 @match 改到你想獲得鏈接的網站 。
// @description:zh-CN  獲取網頁中的全部鏈接,將 @match 改到你想獲得鏈接的網站 。
// @author       TDL3
// @match        https://heyeased.weebly.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

function make_table(links_and_names) {
    let table = "<table><thead><th>Names</th><th>Links</th></thead><tbody>";
    for (const [link, name] of Object.entries(links_and_names)) {
      table += `<tr><td> ${name} </td><td> ${link} </td></tr>`;
    }
    table += "</table>";
    window.open("").document.write(table);
  }

  function make_list(links) {
    let list = "";
    for (let link in links) {
      list += `<div>${links[link]}</div>`;
    }
    window.open("").document.write(list);
  }

  (function () {
    "use strict";
    let urls = document.querySelectorAll("a");
    let links_and_names = {};
    const name_regex = new RegExp("/png|jpg$/g");
    let res = false
    for (let i = 0; i < urls.length; i++) {
      let nametext = urls[i].textContent;
      let cleantext = nametext.replace(/\t|\s+/g, "").trim();
      let cleanlink = urls[i].href;
      // uncomment this line to get all links
      // let res = name_regex.test(cleanlink);
      // remove white spaces and tabs
      if (!res) {
          links_and_names[cleanlink] = cleantext;
      }
    }
    //make_list(Object.keys(links_and_names));
    make_table(links_and_names);
  })();