myUtils

我的工具

2023-08-07 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/435697/1232006/myUtils.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         myUtils
// ==/UserScript==
window.my=new class {
    constructor(){
        const e=document.head.nextElementSibling;
        window.cl=window.console.log;window.al=window.alert;
        if(e.hasAttribute('my-zone')) this.zone=e;
        else {
            this.zone=this.after('div',document.head,'',`my-zone`,'',`class`,'rwf');
            this.addStyle(`#my-btn-container{display:none;flex-wrap:wrap;z-index:290390444;position:fixed!important}.my-btn{user-select: none!important}`,'my-css-for-btns rwf')
        }
    }

    addStyle(css,className='rwf'){//dependency:after,zone
        return this.append('style',this.zone,css,`class`,className);
    }

    append(tag,dom,content){
        if(!tag) return;
        const son=typeof tag==='string'?document.createElement(tag):tag instanceof EventTarget?tag:0;
        let len=arguments.length;
        if(dom instanceof EventTarget)dom.append(son);
        if(content)son.append(content);
        while(len>3){
            son.setAttribute([arguments[len-2]],arguments[len-1]);len-=2;
        }return son;
    }//my.append('tag',document.body,'content','idk','true','data-s')
    after(tag,dom,content){
        if(!tag) return;
        const bro=typeof tag==='string'?document.createElement(tag):tag instanceof EventTarget?tag:0;
        let len=arguments.length;
        if(dom instanceof EventTarget)dom.after(bro);
        if(content)bro.append(content);
        while(len>3){
            bro.setAttribute([arguments[len-2]],arguments[len-1]);len-=2;
        }return bro;
    }//my.after('div',document.body,'','suck','1','dick',000)
    before(tag,dom,content){
        if(!tag) return;
        const bro=typeof tag==='string'?
              document.createElement(tag):tag instanceof EventTarget?
              tag:0;
        let len=arguments.length;
        if(dom instanceof EventTarget)dom.before(bro);
        if(content)bro.append(content);
        while(len>3){
            bro.setAttribute([arguments[len-2]],arguments[len-1]);len-=2;
        }return bro;
    }// my.before('div',document.head,'','suck','1','dick')

    switchStyle(...styleQueryRule){//enable or disable styleTag found in my.zone
        styleQueryRule.forEach(e=>{
            this.zone.querySelectorAll('style'+e).forEach(e=>{
                return e.type!='0'?e.type=0:e.type="";
            });
        });
    }
    switchDisplay(...queryRule){//show or hide elements found
        queryRule.forEach(e=>{
            if(typeof e !="string") return e.style.display=='none'?e.style.display='initial':e.style.display='none';
            else{
                document.querySelectorAll(e).forEach(e=>{
                    return e.style.display=='none'?e.style.display='initial':e.style.display='none';
                });
            }
        });
    }
    
    s2date(seconds){
        const date=new Date(seconds),year=date.getFullYear(),month=date.getMonth()+1,day=date.getDate(),
              hour=date.getHours(),minute=date.getMinutes(),second=date.getSeconds(),milliseconds=date.getMilliseconds(),currentTime=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second+":"+milliseconds;
        return currentTime;
    }//my.seconds2date(new Date().getTime())

    fuckTiebaLogin(userName,password){//sign in tieba
        document.getElementById('TANGRAM__PSP_5__footerULoginBtn').click();
        document.getElementById('TANGRAM__PSP_5__userName').outerHTML+='';
        document.getElementById('TANGRAM__PSP_5__password').outerHTML+='';
        document.getElementById('TANGRAM__PSP_5__userName').value=userName;
        document.getElementById('TANGRAM__PSP_5__password').value=password;
        return document.getElementById('TANGRAM__PSP_5__submit').click();
    }

    addBtns(...params){//dependency:addStyle,append
        const z=this.zone,myDiv=z.querySelector('#my-btn-container')||this.append('div',z,'',`id`,'my-btn-container',`class`,'fucking-zhihu-sucks'),btns=[],l=params.length;
        for(let i=0;i<l;i+=2){
            const btn= params[i]==""?this.append('button',myDiv,params[i+1].name+'|','class','my-btn'):this.append('button',myDiv,params[i]+'|','class','my-btn');
            btn.addEventListener('click',params[i+1]);
            btns[btns.length]=btn;
        }return btns;
    }//my.addBtns('',()=>{},"func1",e=>{confirm(e.target.id)},'f2',function(e){prompt(e.target.outerHTML)},function test(e){return 1})
    addAs(...args){//dependency:addStyle,append
        const z=this.zone,myDiv=z.querySelector('#my-btn-container')||this.append('div',z,'',`id`,'my-btn-container',`class`,'fucking-zhihu-sucks');
        for(let i=0;i<args.length;i+=2){
            this.append('a',myDiv,args[i]+'|',`href`,args[i+1]);
        }
    }//my.addAs("bilibili","https://www.bilibili.com/","baidu","https://www.baidu.com/")

    fixTitle(){//stop title be changed
        Object.defineProperty(document,"title",{
            writable:false
        });
    }
    
}();