Greasy Fork

来自缓存

Greasy Fork is available in English.

洛谷专栏保存站跳转

在洛谷专栏页面添加保存站跳转按钮

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         洛谷专栏保存站跳转
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  在洛谷专栏页面添加保存站跳转按钮
// @author       Federico2903
// @match        https://www.luogu.com.cn/article/*
// @match        https://www.luogu.com/article/*
// @icon         https://www.luogu.com.cn/favicon.ico
// @grant        GM_addStyle
// @license      GPL-3.0-or-later
// ==/UserScript==

(function() {
    'use strict';
    let loc = 0;
    if (window.location.href.startsWith('https://www.luogu.com.cn')) loc = 1;
    if (!loc) {
        const checkContainer = setInterval(() => {
            const metasContainer = document.querySelector('.meta .metas');
            if (metasContainer) {
                clearInterval(checkContainer);
                const articleId = window.location.pathname.split('/')[2];
                const mirrorContainer = document.createElement('div');
                mirrorContainer.setAttribute('data-v-076e399a', '');
                mirrorContainer.setAttribute('style', 'margin-left: 1.5em');
                mirrorContainer.innerHTML = `
                <div data-v-076e399a class="label">保存站</div>
                <a class="mirror-link"
                   href="https://www.luogu.me/article/${articleId}"
                   target="_blank"
                   style="color: var(--lfe-color--blue-3);
                          text-decoration: none;
                          cursor: pointer;
                          transition: color 0.2s;">
                    前往专栏保存站
                </a>
            `;
                const link = mirrorContainer.querySelector('.mirror-link');
                link.addEventListener('mouseover', () => {
                    link.style.color = 'var(--lfe-color--blue-2)';
                });
                link.addEventListener('mouseout', () => {
                    link.style.color = 'var(--lfe-color--blue-3)';
                });

                metasContainer.appendChild(mirrorContainer);
            }
        }, 10);
    }
    else {
        const checkUrl = setInterval(() => {
            const cont = document.querySelector('#url');
            if (!cont) return;
            clearInterval(checkUrl);
            cont.innerHTML = cont.innerHTML.replaceAll('.com', '.me');
            const articleId = window.location.pathname.split('/')[2];
            const link = document.querySelector('a[href^="https://www.luogu.com/article/"]');
            link.setAttribute('href', link.href.replaceAll('.com', '.me'))
        }, 10);
    }
})();