吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2388|回复: 10
收起左侧

[其他转载] js油猴脚本之修改leetcode刷题样式

  [复制链接]
harglo 发表于 2022-8-20 10:39
本帖最后由 harglo 于 2022-8-20 11:31 编辑

js油猴脚本之修改leetcode刷题样式

  • 作用:主要是调整编程题页面的字体大小,做编程题的时候看题目看得舒服一点

    • 调整字体大小(默认字体太小了)

    • 隐藏提示(点击按钮显示)

    • 自动隐藏顶栏

  • 油猴脚本代码:

// ==UserScript==
// @name         力扣刷题样式
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  try to take over the world!
// @AuThor       You
// @match        https://leetcode-cn.com/problems/*
// @match        https://leetcode.cn/problems/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.onload=function(){
        //字体大小:
        document.getElementsByClassName('notranslate')[0].style.fontSize="20px";
        var div = document.getElementsByClassName('notranslate')[1];
        div.style.fontSize="20px";
        var codes = div.getElementsByTagName('code');
        for (let i = 0; i < codes.length; i++) {
            codes[i].style.fontSize="20px";
        }
        var pres = div.getElementsByTagName('pre');
        for (let i = 0; i < pres.length; i++) {
            pres[i].style.fontSize="20px";
        }
        //多余div:
        var d1 = document.getElementsByClassName('css-5nit4e')[0];
        d1.style.display="none";
        d1.parentElement.removeChild(d1.previousElementSibling);
        d1.parentElement.removeChild(d1.previousElementSibling);
        d1.previousElementSibling.style.display="none";
        //隐藏提示
        var text="提示:";                //文本要写全,使用xpath
        var tipNode = document.evaluate('//*[text()="' + text + '"]', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE).snapshotItem(0);
        var tipContent = tipNode.parentElement.nextElementSibling;
        tipContent.style.display="none";
        var btn=document.createElement('button');
        btn.style.cssText="width:100px;height:40px;";
        btn.textContent="显示";
        var showFlag=false;
        btn.onclick=function () {
            if(showFlag){
                tipContent.style.display="none";
                btn.textContent="显示";
                showFlag=false;
            }else{
                tipContent.style.display="block";
                btn.textContent="隐藏";
                showFlag=true;
            }
        };
        tipNode.parentElement.appendChild(btn);
        //自动点击全屏隐藏顶栏
        setTimeout(function () {
            document.evaluate('//*[@id="lc-home"]/div/div[2]/div[1]/div/div[3]/div[1]/div[1]/div/div[1]/div[2]/div[8]/div/button',document).iterateNext().click();
        },1000);
    }
})();

免费评分

参与人数 4吾爱币 +10 热心值 +3 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
yjn866y + 1 + 1 谢谢@Thanks!
晓风残月祭 + 1 + 1 我很赞同!
xnink + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Future2012 发表于 2022-8-20 10:58
感谢楼主分享
newcools521 发表于 2022-8-20 11:00
daymissed 发表于 2022-8-20 11:17
 楼主| harglo 发表于 2022-8-20 11:30
daymissed 发表于 2022-8-20 11:17
这个脚本是干什么用的?

主要是调整编程题页面的字体大小,做编程题的时候看题目看得舒服一点
iawyxkdn8 发表于 2022-8-20 11:34
调整编程题页面的字体大小,没有什么太大的用处!
sht281 发表于 2022-8-20 12:08
学习中,多谢
txzs123 发表于 2022-8-20 12:54
感谢分享
zzqhandsome 发表于 2022-8-20 15:35

https://leetcode.cn/circle/article/48kq9d/
我觉得这种很实用,题目链接

// ==UserScript==
// home.php?mod=space&uid=170990         有没有人一起从零开始刷力扣
// home.php?mod=space&uid=467642    likou-replace
// home.php?mod=space&uid=1248337      1.0
// @description  none
// home.php?mod=space&uid=686208       Permission
// home.php?mod=space&uid=195849        https://leetcode.cn/circle/article/48kq9d/*
// @require      https://code.jquery.com/jquery-3.4.1.min.js
// home.php?mod=space&uid=609072        none
// ==/UserScript==

/* globals $, jQuery */
'use strict';

let proMap = new Map(),
    transMap = new Map(),
    buildMapComplete = false;

const getProblems = () => {
    $.ajax({
        url : 'https://leetcode.cn/api/problems/all/'
    }).then((response) => {
        getTrans(JSON.parse(response));
    });
}

const getTrans = (picker) => {
    $.post({
        url : 'https://leetcode.cn/graphql',data:{"operationName":"getQuestionTranslation","variables":{},"query":"query getQuestionTranslation($lang: String) {\n  translations: allAppliedQuestionTranslations(lang: $lang) {\n    title\n    questionId\n    __typename\n  }\n}\n"}
    }).then((trans) => {
        buildMap(picker, trans);
    });
}

const buildMap = (picker, trans) => {
    for(let pro of picker.stat_status_pairs){
        proMap.set(pro.stat.frontend_question_id, pro.stat.question__title_slug);
    }
    for(let t of trans.data.translations){
        transMap.set(t.questionId, t.title);
    }
    buildMapComplete = true;
};

const replace = () => {
    let even = true;
    for(let problem of $("table tr td")){
        if(!even){
            let htmlString = "";
            let normalExit = true;
            for(let id of problem.textContent.split('、')){
                if(isNaN(parseInt(id))){
                    normalExit = false;
                    break;
                }
                htmlString += `<a href = 'https://leetcode.cn/problems/${proMap.get(id)}/' title = '${transMap.get(id)}' target = 'blank'>${id}</a>、`;
            }
            if(normalExit){
                problem.innerHTML = `<td>${htmlString.substring(0, htmlString.length - 1)}</td>`;
            }
        }
        even = !even;
    };
}

getProblems();

const interval = setInterval(() => {
    if(buildMapComplete && $("table tr td").length != 0){
        clearInterval(interval);
        replace();
    }
}, 5e2);
三滑稽甲苯 发表于 2022-8-20 17:46
有对比效果图吗
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-28 22:47

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表