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);
}
})();
标签:style,btn,d1,js,var,div,document,leetcode,刷题
From: https://www.cnblogs.com/harglo/p/16607276.html