Benben Linker

Make a link to Benben Saver and also a link backwards

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
        }
    }
})();