js油猴脚本之修改leetcode刷题样式
本帖最后由 harglo 于 2022-8-20 11:31 编辑js油猴脚本之修改leetcode刷题样式
* 作用:主要是调整编程题页面的字体大小,做编程题的时候看题目看得舒服一点
* 调整字体大小(默认字体太小了)
* 隐藏提示(点击按钮显示)
* 自动隐藏顶栏
* 油猴脚本代码:
~~~javascript
// ==UserScript==
// @name 力扣刷题样式
// @namespace http://tampermonkey.net/
// @version 0.3
// @descriptiontry 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').style.fontSize="20px";
var div = document.getElementsByClassName('notranslate');
div.style.fontSize="20px";
var codes = div.getElementsByTagName('code');
for (let i = 0; i < codes.length; i++) {
codes.style.fontSize="20px";
}
var pres = div.getElementsByTagName('pre');
for (let i = 0; i < pres.length; i++) {
pres.style.fontSize="20px";
}
//多余div:
var d1 = document.getElementsByClassName('css-5nit4e');
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('//*', 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/div/div/div/div/div/div/div/div/div/div/button',document).iterateNext().click();
},1000);
}
})();
~~~ https://leetcode.cn/circle/article/48kq9d/
我觉得这种很实用,题目链接
```js
// ==UserScript==
// @name 有没有人一起从零开始刷力扣
// @namespace likou-replace
// @version 1.0
// @descriptionnone
// @AuThor Permission
// @match https://leetcode.cn/circle/article/48kq9d/*
// @require https://code.jquery.com/jquery-3.4.1.min.js
// @grant 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) {\ntranslations: 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);
``` daymissed 发表于 2022-8-20 11:17
这个脚本是干什么用的?
主要是调整编程题页面的字体大小,做编程题的时候看题目看得舒服一点 感谢楼主分享
感谢楼主分享 这个脚本是干什么用的? 调整编程题页面的字体大小,没有什么太大的用处! 学习中,多谢 感谢分享 有对比效果图吗
页:
[1]
2