[脱机BUG] 下载链接错误修复

[复制链接]

初入学徒

1

主题

22

回帖

30

积分
UID
5813
雷小钻
0
雷小币
534
贡献点数
13
发表于 昨天 18:21 | 显示全部楼层
针对论坛中下载链接错误的油猴脚本。
替换为正确的链接。




// ==UserScript==
// @name         雷小伊下载链接自动修复
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  精准修复“推荐下载(蓝奏云)”按钮的跳转链接
// @author       Gemini
// @match        *://bbs.tiepi.top/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // ================= 配置区域 =================
    // 1. 在这里填入你想要跳转的【正确链接】
    const NEW_URL = "https://lxy.lanzouu.com/b052mtlbg";

    // 2. 这里是那个【错误的原本链接】(用于辅助定位,不用改)
    const OLD_URL_PART = "lxy.lanzouj.com/b052mtlbg";
    // ===========================================

    function fixDownloadLink() {
        // 方法A:最精准 - 通过 title 属性寻找
        // 你的源代码里有 title="推荐下载(蓝奏云)",这是最好的身份证
        let btn = document.querySelector('a[title="推荐下载(蓝奏云)"]');

        // 方法B:如果方法A没找到,尝试通过原本的错误链接寻找 (双重保险)
        if (!btn) {
            btn = document.querySelector(`a[href*="${OLD_URL_PART}"]`);
        }

        // 如果找到了按钮,且还没有被修复过
        if (btn && btn.getAttribute('data-fixed') !== 'true') {

            console.log("找到目标按钮,准备修复...");

            // 1. 修改链接
            btn.href = NEW_URL;

            // 2. 视觉反馈:修改背景颜色为绿色,文字加粗
            // 这样你一进页面就知道脚本起作用了
            btn.style.backgroundColor = "#52c41a"; // 绿色
            btn.style.borderColor = "#52c41a";
            btn.style.color = "#fff";
            btn.innerHTML = "推荐下载(蓝奏云) ✅已修复";

            // 3. 标记为已修复,防止重复执行
            btn.setAttribute('data-fixed', 'true');
        }
    }

    // --- 执行逻辑 ---

    // 1. 刚打开页面时尝试一次
    fixDownloadLink();

    // 2. 开启“监视器” (MutationObserver)
    // 很多论坛的内容是动态加载的,用监视器可以在按钮刚出现的一瞬间就修复它
    const observer = new MutationObserver((mutations) => {
        fixDownloadLink();
    });

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });

})();


回复

举报 使用道具

您需要登录后才可以回帖 登录 | 立即注册
快速回复 返回顶部 返回列表