myUtils

自分用、dom取得等の機能追加。

Устаревшая версия за 31.05.2022. Перейдите к последней версии.

Этот скрипт недоступен для установки пользователем. Он является библиотекой, которая подключается к другим скриптам мета-ключом // @require https://update.greasyfork.org/scripts/435697/1056321/myUtils.js

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey, Greasemonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Violentmonkey.

Чтобы установить этот скрипт, вы сначала должны установить расширение браузера, например Tampermonkey или Userscripts.

Чтобы установить этот скрипт, сначала вы должны установить расширение браузера, например Tampermonkey.

Чтобы установить этот скрипт, вы должны установить расширение — менеджер скриптов.

(у меня уже есть менеджер скриптов, дайте мне установить скрипт!)

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение браузера, например Stylus.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

Чтобы установить этот стиль, сначала вы должны установить расширение — менеджер стилей.

(у меня уже есть менеджер стилей, дайте мне установить скрипт!)

// ==UserScript==
// @name         myUtils
// @description  自分用、dom取得等の機能追加。
// @include        *
// @noframes
// ==/UserScript==
class my{
    //dependency:myDomAppendBro
    static addStyle(css,className=void(0)){
        this.domAppendBro('style',document.head,css,`class`,className)
    }
    
    //my.domAppendSon('tag',document.body,'content','idk','true','data-s')
    static domAppendSon(tag,dom,content){
        if(!tag) return;
        const son=typeof tag=='string'?
              document.createElement(tag):tag instanceof HTMLElement||DocumentFragment?
              tag:void(0),len=arguments.length;
        if(dom instanceof HTMLElement||dom instanceof DocumentFragment)dom.append(son);
        if(content)son.append(content);
        if (len>3) {
            for(let i=3;i<len;i+=2){
                son.setAttribute([arguments[i]],arguments[i+1])
            }
        }return son;
    }
    
    //my.domAppendBro('div',document.body,'','suck','1','dick')
    static domAppendBro(tag,dom,content){
        if(!tag) return;
        const bro=typeof tag=='string'?
              document.createElement(tag):tag instanceof HTMLElement||DocumentFragment?
              tag:void(0),len=arguments.length;
        if(dom instanceof HTMLElement||dom instanceof DocumentFragment)dom.after(bro);
        if(content)bro.append(content);
        if (len>3) {
            for(let i=3;i<len;i+=2){
                bro.setAttribute([arguments[i]],arguments[i+1])
            }
        }return bro;
    }
    
    // my.domInsertBro('div',document.head,'','suck','1','dick')
    static domInsertBro(tag,dom,content){
        if(!tag) return;
        const bro=typeof tag=='string'?
              document.createElement(tag):tag instanceof HTMLElement||DocumentFragment?
              tag:void(0),len=arguments.length;
        if(dom instanceof HTMLElement||dom instanceof DocumentFragment)dom.before(bro);
        if(content)bro.append(content);
        if (len>3) {
            for(let i=3;i<len;i+=2){
                bro.setAttribute([arguments[i]],arguments[i+1])
            }
        }return bro;
    }
    
    //enable or disable style with queryStr
    static switchStyle(...styleQueryStr){
        styleClassNames.forEach(e=>{
            const style=document.querySelectorAll('style'+e).forEach(e=>{
                e.type!='0'?e.type=0:e.type="";
            });
        })
    }
    
    //my.seconds2date(new Date().getTime())
    static seconds2date(seconds){
        const date=new Date(seconds),year=date.getFullYear(),month=date.getMonth()+1,day=date.getDate();
        const hour=date.getHours(),minute=date.getMinutes(),second=date.getSeconds(),milliseconds=date.getMilliseconds(),currentTime=year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second+":"+milliseconds;
        return currentTime
    }
    
    //跳出登录框后再执行
    static fuckTiebaLogin(userName,password){
        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();
    }
    
    static getValue(k,aDefault){
        const val=localStorage.getItem("XB_"+k)
        if (!val && 'undefined' != typeof aDefault) return aDefault;
        return val;
    }
    
    //setValue('k', 'v')
    static setValue(k, v){
        localStorage.setItem("XB_"+k, v);
    }
    
    //deleteValue('k')
    static deleteValue(k){
        if(k.indexOf("XB_")!=-1) localStorage.removeItem(k);
    }
    
    static listValues(){
        let list=[],j=0,k;
        for (let i=0; i<localStorage.length;i++) {
            k=localStorage.key(i);
            if(k.indexOf("XB_")!=-1) list[j++]=localStorage.key(i);
        }return list;
    }
    
    //dependency:myXbListValues
    static clearValues(){
        this.listValues().forEach(e=>{
            localStorage.removeItem(e)
        })
    }
    
    //get len of json obj
    static getJsonLen(jsonObj){
        let jsonLen=0, key;
        for (key in jsonObj) {
            if (jsonObj.hasOwnProperty(key)) jsonLen++;
        }return jsonLen;
    }
    
    //syn console.log
    static log(text){
        console.log(JSON.stringify(text))
    }
    
    //dependency:myAddStyle,myDomAppendSon
    //my.addBtns(()=>{},a=e=>{confirm(e.target.id)},function(e){prompt(e.target.outerHTML)},function test(e){return 1})
    static addBtns(...funcs){
        const myDiv=document.querySelector('#myBtnContainerDiv')||this.domAppendBro('div',document.body,'',`id`,'myBtnContainerDiv',`class`,void(0)),btns=[];
        if(!document.querySelector('style.mycss'))this.addStyle(`#myBtnContainerDiv{display:flex;z-index:1650729359811;position: fixed!important;right:0;top:0}`,'mycss undefined');
        for(let i=0;i<funcs.length;i++){
            const fname=funcs[i].name||"noname",
                btn=this.domAppendSon('button',myDiv,fname+'|','class','myQuickBtn');
            btn.addEventListener('click',funcs[i]),btns[i]=btn;
        }return btns
    }
    
    //dependency:myAddStyle,myDomAppendSon
    //my.addAs("哔哩哔哩","https://www.bilibili.com/","百度","https://www.baidu.com/")
    static addAs(...args){
        const myDiv=document.querySelector('#myBtnContainerDiv')||this.domAppendBro('div',document.body,'',`id`,'myBtnContainerDiv',`class`,void(0)),btns=[];
        if(!document.querySelector('style.mycss'))this.addStyle(`#myBtnContainerDiv{display:flex;z-index:1650729359811;position: fixed!important;right:0;top:0}`,'mycss undefined');
        for(let i=0;i<args.length;i+2){
            const inh=args[i],href=args[i+1];
            this.domAppendSon('a',myDiv,inh+'|',`href`,href);
        }
    }

    //prevent document.title from being changed
    static fixTitle(){
        Object.defineProperty(document,"title",{
            writable:false
        })
    }
    
}