my

我的工具

目前為 2023-08-16 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/435697/1235901/my.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name my
// @description 我的工具
// @grant unsafeWindow
// ==/UserScript==
(function(win){
    const e=document.documentElement.firstElementChild;
    let z;
    win.my=new class {
        constructor(){
            if(e.tagName==='Z') z=this.zone=e;
            else {
                z=this.zone=this.before('z',e,'',`class`,'rwf');
                this.addStyle(`my-btns{display:block;z-index:9195129;position:fixed;right: 0;bottom: 0;height: min-content;}.my-btn{user-select: none}`,'my-btns');
                win.cl=win.console.log;win.al=win.alert;
            }
        }

        addStyle(css,className='rwf'){//depend:after,zone
            return this.append('style',z,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')

        eods(){//enable or disable style in my.zone
            z.querySelectorAll('style').forEach(e=>e.type==='0'?e.type='':e.type=0);
        }
        sohe(...args){//show or hide elements
            args.forEach(e=>{
                if(typeof e!=="string") e.style.display==='none'?e.style.display='initial':e.style.display='none';
                else document.querySelectorAll(e).forEach(e=>e.style.display==='none'?e.style.display='initial':e.style.display='none');
            });
        }
        s2d(seconds){//seconds2date
            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.s2d(new Date().getTime())
        tieba(uname,pwd){//login
            document.getElementById('TANGRAM__PSP_5__footerULoginBtn').click();
            document.getElementById('TANGRAM__PSP_5__uname').outerHTML+='';
            document.getElementById('TANGRAM__PSP_5__pwd').outerHTML+='';
            document.getElementById('TANGRAM__PSP_5__uname').value=uname;
            document.getElementById('TANGRAM__PSP_5__pwd').value=pwd;
            return document.getElementById('TANGRAM__PSP_5__submit').click();
        }
        fixTitle(){//stop title be changed
            Object.defineProperty(document,"title",{
                writable:false
            });
        }

        addBtns(...params){//depend:addStyle,append
            const myBtns=z.querySelector('my-btns')||this.append('my-btns',z,'',`class`,'rwf'),btns=[],l=params.length;
            for(let i=0;i<l;i+=2){
                const btn= params[i]==''?this.append('button',myBtns,params[i+1].name+'|','class','my-btn'):this.append('button',myBtns,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){//depend:addStyle,append
            const myBtns=z.querySelector('my-btns')||this.append('my-btns',z,'',`class`,'rwf');
            for(let i=0;i<args.length;i+=2){
                this.append('a',myBtns,args[i]+'|',`href`,args[i+1]);
            }
        }//my.addAs("bilibili","https://www.bilibili.com/","baidu","https://www.baidu.com/")

    }()
})(unsafeWindow);