mylib

我的工具

Version vom 31.03.2022. Aktuellste Version

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/435697/1034235/mylib.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

function myAddStyle(css,className='') {
    const style = document.createElement('style');
    style.type='text/css';
    style.textContent = css;
    style.className=arguments[1];
    const h0 =document.querySelector('html');
    h0.insertBefore(style,h0.children[0]);
}
//enable or disable style with className
function mySwitchStyle(...styleClassNames) {
    styleClassNames.forEach(e=>{
        const style=document.querySelector('style.'+e);
        style.type==0?style.type="text/css":style.type=0
    })
}
//getDateStr(1524637692)>"2018-4-25  14:28:12"
function seconds2date(seconds){
    const date = new Date(seconds*1000)
    const year = date.getFullYear();
    const month = date.getMonth() + 1;
    const day = date.getDate();
    const hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    const minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    const second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    const currentTime = year + "-" + month + "-" + day + "  " + hour + ":" + minute + ":" + second;
    return currentTime
}
//myDocumentBodyAppendDom(document.body,'标签','内容','idk','true','data-s')
function myDomAppendSon(dom,tag,content) {
    const son = document.createElement(tag)
    son.appendChild(document.createTextNode(content));
    const len = arguments.length;
    if (len>3) {
        for(let i=3;i<len;i+=2){
            son.setAttribute([arguments[i]],arguments[i+1])
        }
    }
    dom.appendChild(son);
    return son;
}
function myDomAppendBro(dom,tag,content){//紧跟其后追加元素//myDomAppendBro(document.body,'div','','suck','1','dick')
    const bro = document.createElement(tag);
    bro.appendChild(document.createTextNode(content));
    const len = arguments.length;
    if (len>3) {
        for(let i=3;i<len;i+=2){
            bro.setAttribute([arguments[i]],arguments[i+1])
        }
    }
    dom.parentNode.insertBefore(bro,dom.nextElementSibling);
    return bro;
}
//跳出登录框后再执行
function myFuckTiebaLogin(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();
}
function myXbGetValue(k, aDefault) {
    let val = localStorage.getItem("XB_"+k)
    if (null === val && 'undefined' != typeof aDefault) return aDefault;
    return val;
}
//myXbSetValue('k', 'v')
function myXbsetValue(k, v) {
    localStorage.setItem("XB_"+k, v);
}
function myXbDeleteValue(k) {
    if(k.indexOf("XB_")!=-1) localStorage.removeItem(k);
}
//获取本地存储的Key
function myXbListValues() {
    let list=[],j=0;
    for (let i = 0; i < localStorage.length; i++) {
        let k=localStorage.key(i);
        if(k.indexOf("XB_")!=-1) list[j++] = localStorage.key(i);
    }return list;
}
//得到json对象的len
function myGetJsonLen(jsonObj){
    let jsonLen = 0, key;
    for (key in jsonObj) {
        if (jsonObj.hasOwnProperty(key)) jsonLen++;
    }return jsonLen;
}
//同步输出console.log()
function myLog(text){
    console.log(JSON.stringify(text))
}
//dependency:myAddCss,myDomAppendSon
//myAddBtnsWithFuncs(()=>{alert(1)},(e)=>{confirm(e.target.id)},(e)=>{prompt(e.target.outerHTML)})
function myAddBtnsWithFuncs(...funcs){
    funcs.forEach(e=>{
        if(typeof e !='function') return;
    })
    const myDiv=document.querySelector('#myDiv')?document.querySelector('#myDiv'):myDomAppendSon(document.body,'div','','id','myDiv');
    myAddStyle(`#myDiv{z-index:999999;position: fixed!important;right: 0;top:0}`);
    for(let i=0;i<funcs.length;i++){
        const name="btn"+i;
        const btn = myDomAppendSon(myDiv,'input','','value',name,'type','button','id',name);
        btn.addEventListener('click',funcs[i])
    }
}