vjudge+background

为vJudge设置背景

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         vjudge+background
// @namespace    vjudge-plus-v2
// @version      1.6
// @inject-into  content
// @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() {
    window.alert("设置成功,刷新生效");
    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");
    let tes = /^#([0-9a-f]{3,4}|[0-9a-f]{6})$/i;
    GM_registerMenuCommand("设置文字颜色", () => {
        let tmp = col;
        do {
            tmp = window.prompt("请输入颜色的Hexcode\n(比如#b93e3e)\n建议选择背景主色调的反差色", tmp);
        } while (!tes.test(tmp));
        GM_setValue("col", tmp);
        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: #f0f0f0 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: #ff4c8c;text-decoration: underline;}"+
        "body {color: "+col+" !important;}"
    );

    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>';
})();