Greasy Fork

Greasy Fork is available in English.

世图增加已下载的红色链接

为世图增加已下载的红色链接

当前为 2025-03-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         世图增加已下载的红色链接
// @namespace    http://tampermonkey.net/
// @version      2025-03-11
// @description  为世图增加已下载的红色链接
// @author       You
// @match        https://research.worldlib.site/result_query.aspx
// @icon         https://www.google.com/s2/favicons?sz=64&domain=worldlib.site
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    // Your code here...
    // 设置定时器,每秒执行一次任务
    function addVisitedStyle() {
        // 检查是否已经存在 a:visited 样式
        const existingStyle = document.querySelector('style[data-visited-style]');

        if (!existingStyle) {
            // 创建一个新的 <style> 元素
            const style = document.createElement('style');
            style.setAttribute('data-visited-style', ''); // 添加自定义属性以标识

            // 定义样式内容
            const styleContent = `
            a:visited {
                color: #e233eb; /* 设置访问过的链接颜色为红色 */
            }
        `;

            // 将样式内容添加到 <style> 元素中
            style.appendChild(document.createTextNode(styleContent));

            // 将 <style> 元素插入到文档的 <head> 中
            document.head.appendChild(style);
        }
    }

    // 调用函数,添加样式
    addVisitedStyle();
    setInterval(function () {
        // 查找所有包含data-url属性的<a>标签
        const links = document.querySelectorAll('a[data-url]');
        // console.log(links.length)
        // 遍历这些<a>标签
        links.forEach(function (link) {
            // 检查是否已经存在类为new_a的元素
            const existingNewA = link.nextElementSibling;

            // 如果不存在new_a类的元素,则添加新的<a>标签
            if (!existingNewA) {
                // 创建新的<a>标签
                const newA = document.createElement('a');
                newA.textContent = "下载"
                // 设置新<a>标签的href属性为data-url的值
                newA.href = link.getAttribute('data-url');
                // 设置新<a>标签的打开方式为新窗口
                newA.target = '_blank';
                // 添加类名new_a
                newA.classList.add('new_a');
                // 将新<a>标签插入到当前<a>标签后面
                link.parentNode.appendChild(newA);
                // console.log("add new_a")
            }
        });
    }, 1000);
})();