🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

leetcode user case

create user case unit test in leetcode.com

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==

// @require      http://libs.baidu.com/jquery/1.8.3/jquery.min.js
// @name         leetcode user case
// @namespace    http://tangmocd.cn/
// @version      0.1
// @description  create user case unit test in leetcode.com
// @author       [email protected]
// @match        *://leetcode-cn.com/problems/*
// @grant        none
// ==/UserScript==


(function() {
    'use strict';
    function addlight(){
        var node=document.createElement("div");
        node.id="light"
        node.style="display: none;"+
            "position: absolute;"+
            "top: 25%;"+
            "left: 25%;"+
            "width: 55%;"+
            "height: 55%;"+
            "padding: 20px;"+
            "border: 10px solid orange;"+
            "background-color: white;"+
            "z-index: 1002;"+
            "overflow: auto;"
        node.innerHTML="code Example."+
            "<a href=\"javascript:void(0)\" "+
            " onclick=\"document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'\">Close Window</a>"+
            "<textarea name=\"lines\" rows=\"30\" cols=\"100\" id=\"contentid\"></textarea>";
        return node;
    }
    function addfade(){
        var node=document.createElement("div");
        node.id="fade";
        node.style="display: none;"+
            "position: absolute;"+
            "top: 0%;"+
            "left: 0%;"+
            "width: 100%;"+
            "height: 100%;"+
            "background-color: black;"+
            "z-index: 1001;"+
            "-moz-opacity: 0.8;"+
            "opacity: .20;"+
            "filter: alpha(opacity=88);"
        return node;
    }


    function getfunctionname(content){
        //param: content include function name
        // return function name in code
        // eg. content=   def containsPattern(self, arr: List[int], m: int, k: int) -> bool:
        //     return:  containsPattern
        content=content.split("(")[0].replace("def","").replace(" ","").replace(/(^\s*)|(\s*$)/g, "");
        return content;

    }
    window.onload = function(){

        console.log("find language");
        var stra=$("#lang-select").find('span')[0].innerText;

        if (stra=='Python3'){
            console.log(stra);
            var childs=$(".view-lines").children()
            if (childs.length==2){
                console.log('child of code len is 2')
                var diivlines=$("div.view-lines")[0];

                var linesnum=$("div.margin-view-overlays")[0];

                var contentlist=[]
                contentlist.push("from typing import List")
                contentlist.push(childs[0].innerText.replace(/\xA0/g," "));
                contentlist.push(childs[1].innerText.replace(/\xA0/g," "));
                contentlist.push("        pass")
                contentlist.push("if __name__ == '__main__':");
                contentlist.push("    obj=Solution()")

                var funcname=getfunctionname($('div.view-lines > div:nth-child(2) > span')[0].innerText);

                var prelist=$(".notranslate pre")

                console.log(funcname);

                for(var i=0;i<prelist.length;i++){
                    var usercase=prelist[i].innerText;
                    usercase=usercase.replaceAll(":",":").split("\n")


                    var content2="    print(obj."+funcname;
                    for(var j=0;j<usercase.length;j++){
                        console.log(usercase[j])

                        var intputlist=usercase[j].split(":")
                        if (intputlist.length==2){

                            if (j==0){

                                content2+="("+intputlist[1]+')==';
                            }else if(j==1){

                                //change true-->True and false -->False
                                var result=intputlist[1].replaceAll("false","False").replaceAll("true","True");
                                content2+=result+")";
                                contentlist.push(content2);
                                //create next node content
                                content2="    print("+funcname;

                            }

                        }
                    }

                    var appex=document.getElementById("app")
                    appex.appendChild(addfade());
                    appex.appendChild(addlight());

                    document.getElementById('light').style.display='block';
                    document.getElementById('fade').style.display='block';
                    document.getElementById("contentid").value = contentlist.join('\n');

                }
            }


        }
    }
})();