您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
获取网页中的全部链接。鼠标右键 -> tampermonkey -> "Get All Links"。
当前为
- // ==UserScript==
- // @name Get All Links
- // @name:zh-CN 获取网页中的全部链接
- // @namespace xcl
- // @version 1.0
- // @description Get all links from a website. right-click -> tampermonkey -> "Get All Links".
- // @description:zh-CN 获取网页中的全部链接。鼠标右键 -> tampermonkey -> "Get All Links"。
- // @author xcl
- // @match *://*/*
- // @grant none
- // @run-at context-menu
- // ==/UserScript==
- const filter_results = false;
- const filter_regex = new RegExp(/png|jpg/g);
- function make_table(results) {
- let table = "<table><thead><th>Names</th><th>Links</th></thead><tbody>";
- results.forEach(result => {
- table += `<tr><td> ${result.name} </td><td> ${result.url} </td></tr>`;
- });
- table += "</table>";
- window.open("").document.write(table);
- }
- function make_list(results) {
- let list = "";
- results.forEach(result => {
- list += `<div>${result.url}</div>`;
- });
- window.open("").document.write(list);
- }
- function filter_link(link) {
- if (!!link.match(filter_regex)) {
- return true;
- }
- return false;
- }
- function get_links() {
- let urls = document.querySelectorAll("a");
- let results = [];
- urls.forEach(url => {
- let link_name = url.textContent.replace(/\t|\s+/g, "").trim();
- let link = url.href;
- if (!filter_results) {
- results.push({
- name: link_name,
- url: link
- });
- } else if (filter_link(link)) {
- results.push({
- name: link_name,
- url: link
- });
- }
- });
- // make_list(results);
- make_table(results);
- }
- (function () {
- "use strict";
- get_links();
- })();