Mathew 以前搞的神秘小插件合集

· · 科技·工程

前言

应该都可以在我 GreasyFork 主页找到。

都是一些小功能,拉完了。

大部分是两三年前写的,和现在 AI 写的插件没得比。

广告屏蔽

// ==UserScript==
// @name         洛谷广告屏蔽
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  屏蔽洛谷的广告
// @author       Mathew_Miao
// @match        https://www.luogu.com.cn/problem/*
// @match        https://www.luogu.com.cn/contest/*
// @match        https://www.luogu.com.cn/training/*
// @grant        unsafeWindow
// ==/UserScript==
(function() {
    'use strict';
    setTimeout(function(){
        document.querySelector("#app > div.main-container.lside-nav > div > main > div > div > div.side > div:nth-child(5)").remove();
    },500)
    setTimeout(function(){
        document.querySelector("#app > div.main-container.lside-nav > div > main > div > div > div.side > div:nth-child(5)").remove();
    },1000)
    setTimeout(function(){
        document.querySelector("#app > div.main-container.lside-nav > div > main > div > div > div.side > div:nth-child(5)").remove();
    },2500)
})();

功能是删掉这个位置的广告:

总是坏,因为洛谷老更新题目界面,这个广告的 JS 位置总是变。

用户顶栏数据显示

// ==UserScript==
// @name         洛谷用户顶栏精确数字显示
// @version      0.5
// @description  洛谷用户顶栏显示精确数字
// @match        *://www.luogu.com.cn/user/*
// @author       MlkMathew
// @license      MIT
// @grant        none
// @namespace    https://greasyfork.org/users/1068192
// ==/UserScript==
(function() {
    'use strict';
    function __work(){
        let currData=JSON.parse(document.querySelector("#lentille-context").textContent).data;
        let Col=document.querySelector("#app > div.main-container.lside-nav > main > div > div.l-card > div.user-header-bottom > div.user-stat-data.lfe-caption > div");
        for(let x of Col.children)
        {
            if(x.children[0].textContent=='关注'){
                x.children[1].textContent=currData.user.followingCount;
            }
            if(x.children[0].textContent=='粉丝'){
                x.children[1].textContent=currData.user.followerCount;
            }
            if(x.children[0].textContent=='提交'){
                x.children[1].textContent=currData.user.submittedProblemCount;
            }
            if(x.children[0].textContent=='通过'){
                x.children[1].textContent=currData.user.passedProblemCount;
            }
            if(x.children[0].textContent=='排名'){
                x.children[1].textContent=currData.user.ranking;
            }
        }
    }
    function work(){
        __work();
        setTimeout(__work,500);
        setTimeout(__work,2500);
        setTimeout(__work,5000);
        setTimeout(__work,7500);
    }
    window.addEventListener('load',function(){
        let Col=document.querySelector("#app > div.main-container.lside-nav > main > div > div.l-card > div.user-header-bottom > div.menu > ul");
        for(let x of Col.children)
        {
            x.children[0].addEventListener("click",work);
        }
        work();
    },true);
})();

效果如下:

主页净化

// ==UserScript==
// @name         洛谷主页净化
// @version      0.8
// @description  让洛谷主页变得简洁
// @match        https://www.luogu.com.cn$
// @author       MlkMathew
// @license      MIT
// @grant        none
// @namespace https://greasyfork.org/users/1068192
// ==/UserScript==

(function() {
    'use strict';
    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(1)").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.lg-article.am-hide-sm").remove();
    document.querySelector("#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div.am-u-md-8").remove();
    //document.querySelector("#app-old > div.lg-index-content.am-center > div:nth-child(3) > div.am-u-lg-9.am-u-md-8.lg-index-benben.lg-right > div:nth-child(2)").remove();
    document.querySelector("#app-old > div.lg-index-content.am-center > div:nth-child(1) > div > div > div > div").className="am-u-md-12 lg-punch am-text-center";
    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").lastChild.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").lastChild.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").lastChild.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").lastChild.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").lastChild.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").lastChild.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").lastChild.remove();
})();

功能:

效果:

双击跳题

我个人用得最爽的一个,以前 exlg 有这个功能,我觉得很好用,exlg 死了之后重新写了。

// ==UserScript==
// @name         洛谷双击跳题
// @version      0.4
// @description  仿exlg双击跳题
// @match        https://www.luogu.com.cn*
// @match        https://www.luogu.com.cn/*
// @match        *://*
// @match        *://*/*
// @author       MlkMathew
// @license      MIT
// @grant        none
// @namespace    https://greasyfork.org/users/1068192
// @downloadURL none
// ==/UserScript==

(function() {
    'use strict';
    var web=location.href;
    function number(s){
        let res=0;
        for(let i=0;i<s.length;i++)
        {
            if(s[i]<'0'||s[i]>'9'){
                return -1;
            }
            res=res*10+(s[i]-'0');
        }
        return res;
    }
    function letter(c){
        if('a'<=c&&c<='z'){
            return String.fromCharCode(c.charCodeAt()-97+65);
        }
        return c;
    }
    function prefix(s,pre){
        if(s.length<pre.length){
            return false;
        }
        for(let i=0;i<pre.length;i++)
        {
            if(letter(s[i])!=pre[i]){
                return false;
            }
        }
        return true;
    }
    function check(s){
        if(prefix(s,"P")){
            return (number(s.substr(1,s.length-1))>=1000);
        }
        if(web.match("luogu.com.cn")&&prefix(s,"U")&&(!prefix(s,"UVA"))&&(!prefix(s,"UOJ"))){
            return (number(s.substr(1,s.length-1))>0);
        }
        if(web.match("luogu.com.cn")&&prefix(s,"T")){
            return (number(s.substr(1,s.length-1))>=100);
        }
        if(prefix(s,"B")){
            return (number(s.substr(1,s.length-1))>2000);
        }
        if(prefix(s,"CF")){
            if(('A'<=letter(s[s.length-2])&&letter(s[s.length-2])<='Z')&&(s[s.length-1]=='1'||s[s.length-1]=='2')){
                return (number(s.substr(2,s.length-4))>0);
            }
            if(('A'<=letter(s[s.length-1])&&letter(s[s.length-1])<='Z')){
                return (number(s.substr(2,s.length-3))>0);
            }
        }
        if(prefix(s,"AT")){
            return true;
        }
        if(prefix(s,"SP")){
            return (number(s.substr(2,s.length-2))>0);
        }
        if(prefix(s,"UVA")){
            return (number(s.substr(3,s.length-3))>=100);
        }
        if(prefix(s,"LOJ")){
            return (number(s.substr(3,s.length-3))>0);
        }
        if(prefix(s,"QOJ")){
            return (number(s.substr(3,s.length-3))>0);
        }
        if(prefix(s,"UOJ")){
            return (number(s.substr(3,s.length-3))>0);
        }
        if(prefix(s,"GYM")){
            return (number(s.substr(3,s.length-4))>0);
        }
        return false;
    }
    function dbclick()
    {
        let s="";
        if(window.getSelection){
            s=window.getSelection().toString();
        }
        else if(document.selection&&document.selection.createRange){
            s=document.selection.createRange().text;
        }
        while(s[s.length-1]==' ')
        {
            s=s.substr(0,s.length-1);
        }
        if(check(s)){
            if(prefix(s,"LOJ")){
                window.open("https://loj.ac/p/"+number(s.substr(3,s.length-3)));
            }
            else if(prefix(s,"QOJ")){
                window.open("https://qoj.ac/problem/"+number(s.substr(3,s.length-3)));
            }
            else if(prefix(s,"UOJ")){
                window.open("https://uoj.ac/problem/"+number(s.substr(3,s.length-3)));
            }
            else if(prefix(s,"GYM")){
                window.open("https://codeforces.com/gym/"+number(s.substr(3,s.length-4))+"/problem/"+s[s.length-1]);
            }
            else{
                window.open("https://www.luogu.com.cn/problem/"+s);
            }
        }
    }
    document.addEventListener('dblclick',dbclick);
})();

功能相比 exlg 的那个牛逼多了:

Codeforces 提交填写题目名

// ==UserScript==
// @name         CF提交填写题目名
// @namespace    http://tampermonkey.net/
// @version      v1
// @description  提交时自动填写最近访问过的题目
// @author       You
// @match        *://codeforces.com/*
// @icon         https://aowuucdn.oss-accelerate.aliyuncs.com/codeforces.png
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';
    var web=location.href;
    if(web.match('problem/')){
        var cts='',pid='';
        for(let i=web.length-1;~i;i--)
        {
            if(web[i]=='/'){
                pid=web.substr(i+1,web.length-i-1);
                break;
            }
        }
        for(let i=web.length-1;i;i--)
        {
            if(web[i-1]=='/'&&'0'<=web[i]&&web[i]<='9'){
                for(let j=i;j<web.length&&web[j]!='/';j++)
                {
                    cts=cts+web[j];
                }
                break;
            }
        }
        GM_setValue('CF_LAST_VISIT_PROBLEM',cts+pid);
    }
    if(web.match('submit')){
        var input=document.querySelector('input[name="submittedProblemCode"]');
        let id=GM_getValue('CF_LAST_VISIT_PROBLEM');
        if(id){
            input.value=id;
        }
    }
})();

没人发现最近这个功能没了吗。

原理:提交时自动填写最近访问过的题目