首页 > 其他分享 >js脚本之修改leetcode刷题样式

js脚本之修改leetcode刷题样式

时间:2022-08-20 10:45:33浏览次数:63  
标签:style btn d1 js var div document leetcode 刷题

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

相关文章

  • Newtonsoft.Json
    1、序列化stringjsonStr=JsonConvert.SerializeObject(obj)2、反序列化Tobj=JsonConvert.DeserializeObject(jsonStr)3、Newtonsoft.Json扩展方法类///<summa......
  • 学习:json数据
    json本质上是一个固定格式的字符串JSON是一种轻量级的数据交换语音Json可以实现不同平台的数据交换也可以使用它保存业务数据格式Json使用键值对的方式表示一个业务对......
  • js的运动及封装
    概述运动主要是动画的操作,主要是操作某个document元素的属性变化(位置变化)运动主要的三步骤使用定时器来定时更改对应的内容实时获取对应的元素的属性及相关内容判断是否......
  • js时间戳获取和转换
    js时间戳获取和转换1.js获取当前时间戳1.1获取的时间戳是把毫秒改成000显示vartimestamp=Date.parse(newDate());1.2获取了当前毫秒的时间戳vartimestamp=(ne......
  • [Google] LeetCode 366 Find Leaves of Binary Tree
    Giventherootofabinarytree,collectatree'snodesasifyouweredoingthis:Collectalltheleafnodes.Removealltheleafnodes.Repeatuntilthetre......
  • auto.js常见的APP脚本指令
    appapp模块提供一系列函数,用于使用其他应用、与其他应用交互。例如发送意图、打开文件、发送邮件等。同时提供了方便的进阶函数startActivity和sendBroadcast,用他们可完......
  • [Google] LeetCode 2096 Step-By-Step Directions From a Binary Tree Node to Anothe
    Youaregiventherootofabinarytreewithnnodes.Eachnodeisuniquelyassignedavaluefrom1ton.YouarealsogivenanintegerstartValuerepresenting......
  • LeetCode/最大二叉树
    给定一个不重复的整数数组nums。最大二叉树可以用下面的算法从nums递归地构建:创建一个根节点,其值为nums中的最大值递归地在最大值左边的子数组前缀上构建......
  • 【LeetCode】102.二叉树的层序遍历
    【LeetCode】102.二叉树的层序遍历/**转载请说明出处与作者*作者:多巴胺dopamine*/一问题描述1题目给你二叉树的根节点root,返回其节点值的层序遍历。(即......
  • 【面试题】JSON.stringify()妙用,你真的知道吗?
    JSON.stringify()妙用点击打开视频讲解更加详细语法:JSON.stringify(value,replacer,space)value:将要序列化成一个JSON字符串的值。replacer(可选):如果该参数是一个......