vjudge+background

为vJudge设置背景

当前为 2023-08-15 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         vjudge+background
// @namespace    vjudge-plus-v2
// @version      1.7
// @description  为vJudge设置背景
// @author       axototl (original by Suntra)
// @match        https://vjudge.net/
// @match        https://vjudge.net/*
// @noframes
// @icon         https://vjudge.net/favicon.ico
// @run-at       document-body
// @license      AGPLv3
// @grant        GM_addStyle
// @grant        GM_registerMenuCommand
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-idle
// ==/UserScript==

function reloader() {
    alert("设置成功,刷新生效");
    if (!navigator.onLine) {
        alert("离线状态,无法重加载");
        return;
    }
    location.reload();
}

(function() {
    if (navigator.userAgent.includes("Chrome") && performance.getEntries()[0].responseStatus != 200) return;
    // 设置背景
    let back = GM_getValue("background", "https://cdn.luogu.com.cn/images/bg/fe/Day_And_Night_1.jpg");
    GM_registerMenuCommand("设置背景URL", () => {
        back = window.prompt("请输入背景URL", back);
        GM_setValue("background", back);
        reloader();
    });
    let col = GM_getValue("col", "#b93e3e");
    const tes = /^#([0-9a-f]{3,4}|[0-9a-f]{6})$/i;
    function getColor(t) {
        do {
            tmp = window.prompt("请输入颜色的Hexcode\n(比如#b93e3e)\n建议选择背景主色调的反差色", t);
        } while (!tes.test(t));
        return t;
    }
    GM_registerMenuCommand("设置文字颜色", () => {
        GM_setValue("col", getColor(col));
        reloader();
    });
    let collink = GM_getValue("collink", "#ff4c8c");
    GM_registerMenuCommand("设置链接背景颜色", () => {
        GM_setValue("collink", getColor(collink));
        reloader();
    });
    // if(window.location.href.match(/\/problem\/description\/[^\/]+$/)) {
    //     console.log("error!!!");
    //     GM_addStyle(
    //         "dd {background-color: rgba(255,255,255,70%) !important;border-radius: 0.25rem !important;}"
    //     );
    // } else
    {
        GM_addStyle("body {background: url("+back+") no-repeat center top fixed;background-size: 100% 100%;-moz-background-size: 100% 100%;}");
        document.body.innerHTML = "<nav style='height: 60px'></nav>" + document.body.innerHTML;
    }

    GM_addStyle(
        ".navbar {border-radius:0rem;background-color: rgba(0,0,0,65%) !important;position: fixed;top: 0;left: 0;z-index: 1000;width: 100%;}"+
        "scrollbar-width: none"+
        "#prob-ads {display: none;}"+
        "#img-support {display: none;}"+
        ".card, .list-group-item, .btn-secondary, .page-link, .page-item.disabled .page-link, .dropdown-menu {background-color: rgba(255,255,255,65%);}"+
        ".modal-content {background-color: rgba(255,255,255,90%);}"+
        ".form-control {background-color: rgba(255,255,255,50%);}"+
        ".tab-content {background-color: rgba(255,255,255,50%);border: 2px solid #eceeef;border-radius: 0.25rem;padding: 20px;}"+
        "a:focus, a:hover {color: "+collink+";text-decoration: underline;}"+
        "body {color: "+col+";}"
    );

    document.querySelector("body > div.body-footer").innerHTML += '<p style="color: #3fb98b">Theme powered by vjudge+background (original by <a href="https://github.com/dffxd-suntra/vjudge-plus">vjudge+</a>)</p>';
})();