mylib

我的工具

Mint 2022.04.26.. Lásd a legutóbbi verzió

Ezt a szkriptet nem ajánlott közvetlenül telepíteni. Ez egy könyvtár más szkriptek számára, amik tartalmazzák a // @require https://update.greasyfork.org/scripts/435697/1044137/mylib.js hivatkozást.

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

You will need to install an extension such as Tampermonkey 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.

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

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

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!)

//dependency:myDomAppendBro
function myAddStyle(css,className=''){
    myDomAppendBro(document.body,'style',css,`type`,'text/css',`class`,className)
}
//enable or disable style with className
function mySwitchStyle(...styleClassNames) {
    styleClassNames.forEach(e=>{
        const style=document.querySelector('style.'+e);
        !style.type?style.type="text/css":style.type=0
    })
}
//seconds2date(new Date().getTime())
function 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
}
//myDocumentBodyAppendDom(document.body,'tag','content','idk','true','data-s')
function myDomAppendSon(dom,tag,content) {
    const son = document.createElement(tag),len = arguments.length
    son.appendChild(document.createTextNode(content)),dom.appendChild(son);
    if (len>3) {
        for(let i=3;i<len;i+=2){
            son.setAttribute([arguments[i]],arguments[i+1])
        }
    }
    return son;
}
//myDomAppendBro(document.body,'div','','suck','1','dick')
function myDomAppendBro(dom,tag,content){
    const bro = document.createElement(tag),len = arguments.length;
    bro.append(document.createTextNode(content)),dom.parentNode.insertBefore(bro,dom.nextElementSibling);
    if (len>3) {
        for(let i=3;i<len;i+=2){
            bro.setAttribute([arguments[i]],arguments[i+1])
        }
    }
    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) {
    const val = localStorage.getItem("XB_"+k)
    if (!val && 'undefined' != typeof aDefault) return aDefault;
    return val;
}
//myXbSetValue('k', 'v')
function myXbSetValue(k, v) {
    localStorage.setItem("XB_"+k, v);
}
//myXbSetValue('k')
function myXbDeleteValue(k) {
    if(k.indexOf("XB_")!=-1) localStorage.removeItem(k);
}
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;
}
//dependency:myXbListValues
function myXbClearValues() {
    myXbListValues().forEach(e=>{
        localStorage.removeItem(e)
    })
}
//get len of json obj
function myGetJsonLen(jsonObj){
    let jsonLen=0, key;
    for (key in jsonObj) {
        if (jsonObj.hasOwnProperty(key)) jsonLen++;
    }return jsonLen;
}
//syn console.log
function myLog(text){
    console.log(JSON.stringify(text))
}
//dependency:myAddStyle,myDomAppendSon
//myAddBtns(()=>{},a=e=>{confirm(e.target.id)},function(e){prompt(e.target.outerHTML)},function test(e){return 1})
function myAddBtns(...funcs){
    funcs.forEach(e=>{
        if(typeof e !='function') return console.log(e);
    });
    let myDiv=document.querySelector('#myBtnContainerDiv'),btns=[];
    if(!myDiv) myDiv=myDomAppendSon(document.body,'div','','id','myBtnContainerDiv');
    myAddStyle(`#myBtnContainerDiv{z-index:1650729359811!important;position: fixed!important;right:0!important;top:0!important}`);
    for(let i=0;i<funcs.length;i++){
        let fname=funcs[i].name;
        if(!fname) fname="noname";
        const btn = myDomAppendSon(myDiv,'input','','value',fname,'type','button','class','myQuickBtn');
        btn.addEventListener('click',funcs[i]),btns[i]=btn;
    }return btns
}
//prevent document.title from being changed
function myFixTitle(){
    Object.defineProperty(document,"title",{
        writable:false
    });
}