Benben Linker

Make a link to Benben Saver and also a link backwards

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Benben Linker
// @version      0.5
// @description  Make a link to Benben Saver and also a link backwards
// @author       AZaphodBeeblebrox
// @match        *://*/*
// @license      MIT
// @icon         https://cdn.luogu.com.cn/upload/usericon/3.png
// @grant        none
// @namespace https://greasyfork.org/users/1137586
// ==/UserScript==

(function() {
    'use strict';

    var url = window.location.href;
    var regex = /\/user\/(\d+)/;
    var matches = url.match(regex);

    if (matches != null) {
        var userid = matches[1].toString();
        var button = document.createElement('button');
        if (url.includes('luogu')) {
            button.textContent = '查看历史犇犇';
            button.style.position = "absolute";
            button.style.top = "100px";
            button.style.left = "100px";
            window.addEventListener('scroll', function() {
                var scrollY = window.scrollY;
                button.style.top = (100 + scrollY) + 'px';
            });
            button.classList.add('button-lgcm');
            button.addEventListener('click', async function() {
                window.location.href="https://lgf.imken.moe/user/"+userid
            });
            document.body.appendChild(button);
        }
        else if (url.includes('lgf.imken.moe')) {
            button.textContent = '返回洛谷个人主页';
            button.style.position = "absolute";
            button.style.bottom = "50px";
            button.style.right = "50px";
            button.classList.add('button-lgcm');
            window.addEventListener('scroll', function() {
                var scrollY = window.scrollY;
                button.style.bottom = (50 - scrollY) + 'px';
            });
            button.addEventListener('click', async function() {
                window.location.href="https://www.luogu.com.cn/user/"+userid
            });
            document.body.appendChild(button);
        }
    }
})();