new luogu

Luogu Expansion

Verze ze dne 13. 04. 2024. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         new luogu
// @namespace    http://tampermonkey.net/
// @version      1.0.2
// @description  Luogu Expansion
// @description:zh  洛谷扩展
// @author       volatile
// @match        https://www.luogu.com.cn/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=luogu.com.cn
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @grant        GM_listValues
// @grant        GM_setClipboard
// @grant        GM_xmlhttpRequest
// @grant        GM_getResourceText
// @grant        unsafeWindow
// @connect      https://top.baidu.com/board?tab=realtime
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    //进入插件
    console.log("This is new luogu");
    console.log("\n          _____                    _____                    _____                    _____            _____          \n         /\\    \\                  /\\    \\                  /\\    \\                  /\\    \\          /\\    \\         \n        /::\\____\\                /::\\    \\                /::\\____\\                /::\\____\\        /::\\    \\        \n       /::::|   |               /::::\\    \\              /:::/    /               /:::/    /       /::::\\    \\       \n      /:::::|   |              /::::::\\    \\            /:::/   _/___            /:::/    /       /::::::\\    \\      \n     /::::::|   |             /:::/\\:::\\    \\          /:::/   /\\    \\          /:::/    /       /:::/\\:::\\    \\     \n    /:::/|::|   |            /:::/__\\:::\\    \\        /:::/   /::\\____\\        /:::/    /       /:::/  \\:::\\    \\    \n   /:::/ |::|   |           /::::\\   \\:::\\    \\      /:::/   /:::/    /       /:::/    /       /:::/    \\:::\\    \\   \n  /:::/  |::|   | _____    /::::::\\   \\:::\\    \\    /:::/   /:::/   _/___    /:::/    /       /:::/    / \\:::\\    \\  \n /:::/   |::|   |/\\    \\  /:::/\\:::\\   \\:::\\    \\  /:::/___/:::/   /\\    \\  /:::/    /       /:::/    /   \\:::\\ ___\\ \n/:: /    |::|   /::\\____\\/:::/__\\:::\\   \\:::\\____\\|:::|   /:::/   /::\\____\\/:::/____/       /:::/____/  ___\\:::|    |\n\\::/    /|::|  /:::/    /\\:::\\   \\:::\\   \\::/    /|:::|__/:::/   /:::/    /\\:::\\    \\       \\:::\\    \\ /\\  /:::|____|\n \\/____/ |::| /:::/    /  \\:::\\   \\:::\\   \\/____/  \\:::\\/:::/   /:::/    /  \\:::\\    \\       \\:::\\    /::\\ \\::/    / \n         |::|/:::/    /    \\:::\\   \\:::\\    \\       \\::::::/   /:::/    /    \\:::\\    \\       \\:::\\   \\:::\\ \\/____/  \n         |::::::/    /      \\:::\\   \\:::\\____\\       \\::::/___/:::/    /      \\:::\\    \\       \\:::\\   \\:::\\____\\    \n         |:::::/    /        \\:::\\   \\::/    /        \\:::\\__/:::/    /        \\:::\\    \\       \\:::\\  /:::/    /    \n         |::::/    /          \\:::\\   \\/____/          \\::::::::/    /          \\:::\\    \\       \\:::\\/:::/    /     \n         /:::/    /            \\:::\\    \\               \\::::::/    /            \\:::\\    \\       \\::::::/    /      \n        /:::/    /              \\:::\\____\\               \\::::/    /              \\:::\\____\\       \\::::/    /       \n        \\::/    /                \\::/    /                \\::/____/                \\::/    /        \\::/____/        \n         \\/____/                  \\/____/                  ~~                       \\/____/                          \n                                                                                                                     ");

    var css = ".newlgmenu{width: 100vw; height: 100vh; display: none; align-items: center; justify-content: center; } .NEWLG-menu{width: 600px; height: 400px; display: flex; flex-direction: column; padding: 40px; position: relative; z-index: 100; background: inherit; border-radius: 18px; overflow: hidden; } .NEWLG-menu::before{ content: \"\"; width: calc\(100%  + 20px\); height: calc\(100% + 20px\); position: absolute; top: -10px; left: -10px; overflow:hidden; background: inherit; box-shadow: inset 0 0 0 200px rgba\(255, 255, 255, 0.75\); filter: blur\(5px\); z-index: -1; } .NEWLG-menu input { margin: 6px 0; height: 36px; border: none; background-color: rgba\(255, 255, 255, 0.75\); border-radius: 4px; padding: 0 14px; color: #3d5245; }";
    var style = document.createElement("style");
    style.innerHTML = css;
    document.head.appendChild(style);

    let nowurl = window.location.href;
    console.log(nowurl);

    function getcookie(name){
        const cookiestring = document.cookie;
        const cookies = cookiestring.split('; ');
        for(const cookie of cookies){
            const [cookiename, cookievalue] = cookie.split('=');
            if(cookiename === name) return cookievalue;
        }
        const time = new Date();
        time.setDate(time.getDate() + 365);
        document.cookie = "color=lg-fg-purple" + ";expires=" + time.toUTCString();
        return "lg-fg-purple";
    }

    let _username;

    GM_xmlhttpRequest({
        method: "GET",
        url: 'https://www.luogu.com.cn/',
        onload: function(response){
            let username = new DOMParser();
            let doc1 = username.parseFromString(response.responseText, "text/html");
            _username = doc1.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a').textContent;
        }
    });

    //首页
    if(nowurl == 'https://www.luogu.com.cn/'){
        //日历
        const today=new Date();
        const year=today.getFullYear();
        const month=String(today.getMonth()+1);
        const day=String(today.getDate());
        console.log(year);
        console.log(month);
        console.log(day);
        let date_html='<h2>今天是 '+year+'-'+month+'-'+day+'</h2>';
        if(month==1&&day==1){
            date_html+='<h2>今天是元旦,新的一年,新的开始</h2>';
        }
        else if(month==2&&day==29){
            date_html+='<h2>今年是闰年</h2>';
        }
        else if(month==4&&day==1){
            date_html+='<h2>今天是愚人节</h2>';
        }
        else if(month==5&&day==1){
            date_html+='<h2>今天是劳动节</h2>';
        }
        else if(month==6&&day==1){
            date_html+='<h2>今天是儿童节</h2>';
        }
        else if(month==9&&day==10){
            date_html+='<h2>今天是教师节</h2>';
        }
        else if(month==10&&day==1){
            date_html+='<h2>今天是国庆节,七天小长假,启动!</h2>'
        }
        else if(month==12&&day==31){
            date_html+='<h2>明年见</h2>';
        }
        else if(month==4&&day==28){
            let years=year-2012;
            date_html+='<h2>今天是作者生日的后 '+years+' 年</h2>';
        }
        else{
            date_html+='<h2>欢迎!</h2>';
        }
        let date = document.createElement('div');
        date.className = 'lg-article';
        date.innerHTML = date_html;
        document.querySelector('div.lg-right > div:nth-child(1)').insertAdjacentElement('beforebegin', date);

        //更改用户名颜色
        let color = document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-4.lg-punch.am-text-center > h2 > a');
        let changecolor = getcookie('color');
        console.log(color);
        if(changecolor != 'null') color.className=changecolor;

        document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(3) > div.am-u-lg-3.am-u-md-4.lg-right > div:nth-child(3) > div:nth-child(5)').remove();
        document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(3) > div.am-u-lg-3.am-u-md-4.lg-right > div:nth-child(3) > div').remove();

        GM_xmlhttpRequest({
            method: "GET",
            url: 'https://top.baidu.com/board?tab=realtime',
            onload: function(response){
                let rs = new DOMParser();
                let doc = rs.parseFromString(response.responseText, "text/html");
                for(let i=1;i<=5;i++){
                    let th = i.toString();
                    let selector = '#sanRoot > main > div.container.right-container_2EFJr > div > div:nth-child(2) > div:nth-child(' + th + ') > div.content_1YWBm > a > div.c-single-text-ellipsis';
                    let _rs = doc.querySelector(selector);
                    console.log(_rs.textContent);
                    let selector2 = '#sanRoot > main > div.container.right-container_2EFJr > div > div:nth-child(2) > div:nth-child(' + th + ') > div.content_1YWBm > a';
                    let rslink = doc.querySelector(selector2);
                    console.log(rslink);
                    let link = document.createElement("a");
                    link.href = rslink.href;
                    link.textContent = _rs.textContent;
                    let RS = document.createElement("p");
                    RS.appendChild(link);
                    document.querySelector('#app-old > div.lg-index-content.am-center > div:nth-child(3) > div.am-u-lg-3.am-u-md-4.lg-right > div:nth-child(3) > h2:nth-child(4)').parentNode.append(RS);
                }
            }
        });
    }

    window.onload = function(){
        let button = document.createElement("div");
        button.innerHTML = '<button style=\"background-color: rgb\(94,114,228\);border-radius: 7px;color: white;border: none;padding: 7px 12px;text-align: center;text-decoration: none;display: inline-block;font-size: 16px;margin: 4px 2px;cursor: pointer;border: none;box-shadow: 2px 3px 7px #000;\">NEWLG</button>';
        if(nowurl=='https://www.luogu.com.cn/' || nowurl=='https://www.luogu.com.cn/chat' || nowurl.includes('https://www.luogu.com.cn/user/notification') || (nowurl.includes('https://www.luogu.com.cn/user/') && !nowurl.includes('https://www.luogu.com.cn/user/setting'))) document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div.container > nav').insertAdjacentElement('beforebegin', button);
        let menu = document.createElement("div");
        menu.innerHTML = '<div class=\"newlgmenu\"><from class=\"NEWLG-menu\"><h2>v1.0.1</h2><h3>用户名颜色</h3><input type="text" value="更改名字颜色为(如“紫名”“复原”)" id="nlcolor"><button>提交</button></from></div>';
        document.querySelector("#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div.container").parentNode.append(menu);
        const tb = document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div.container > div:nth-child(3) > button');
        tb.addEventListener('click', function(){
            let menudisplay = document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div:nth-child(3) > div');
            if(menudisplay.style.display == 'none') menudisplay.style.display = 'flex';
            else menudisplay.style.display = 'none';

            const submitcolor = document.querySelector('#app > div.main-container > div.wrapper.wrapped.lfe-body.header-layout.tiny > div:nth-child(3) > div > from > button');
            submitcolor.addEventListener('click', function(){
                let colorchange = document.getElementById('nlcolor').value;
                console.log(colorchange);
                if(colorchange=='灰名'){
                    const time = new Date();
                    time.setDate(time.getDate() + 365);
                    document.cookie = "color=lg-fg-gray" + ";expires=" + time.toUTCString();
                    location.reload();
                }
                else if(colorchange=='蓝名'){
                    const time = new Date();
                    time.setDate(time.getDate() + 365);
                    document.cookie = "color=lg-fg-blue" + ";expires=" + time.toUTCString();
                    location.reload();
                }
                else if(colorchange=='绿名'){
                    const time = new Date();
                    time.setDate(time.getDate() + 365);
                    document.cookie = "color=lg-fg-green" + ";expires=" + time.toUTCString();
                    location.reload();
                }
                else if(colorchange=='橙名'){
                    const time = new Date();
                    time.setDate(time.getDate() + 365);
                    document.cookie = "color=lg-fg-orange" + ";expires=" + time.toUTCString();
                    location.reload();
                }
                else if(colorchange=='红名'){
                    const time = new Date();
                    time.setDate(time.getDate() + 365);
                    document.cookie = "color=lg-fg-red" + ";expires=" + time.toUTCString();
                    location.reload();
                }
                else if(colorchange=='紫名'){
                    const time = new Date();
                    time.setDate(time.getDate() + 365);
                    document.cookie = "color=lg-fg-purple" + ";expires=" + time.toUTCString();
                    location.reload();
                }
                else if(colorchange=='复原'){
                    const time = new Date();
                    time.setDate(time.getDate() + 365);
                    document.cookie = "color=null" + ";expires=" + time.toUTCString();
                    location.reload();
                }
            });
        });
        if(nowurl.includes('https://www.luogu.com.cn/user/')&&!nowurl.includes('https://www.luogu.com.cn/user/setting')){
            if(document.querySelector('#app > div.main-container > main > div > div.card.user-header-container.padding-0 > div.user-header-top > div.user-info > div.user-name > span').textContent != _username) document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div:nth-child(2)').remove();
            let jieshao = document.querySelector('#app > div.main-container > main > div > div.full-container > section.main > div > div.introduction.marked');
            if(jieshao.style.display == 'none') jieshao.removeAttribute('style');
        }
    };
    // Your code here...
})();