mylib

我的工具

当前为 2022-04-18 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/435697/1041312/mylib.js

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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
    })
}
//seconds2date(new Date().getTime())
function seconds2date(seconds){
    const date = new Date(seconds)
    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,'tag','content','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;
}
//myDomAppendBro(document.body,'div','','suck','1','dick')
function myDomAppendBro(dom,tag,content){
    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);
}
//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() {
    return 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))
}function myAlert(text){
    myAlert(JSON.stringify(text))
}
//dependency:myAddStyle,myDomAppendSon
//myReaddBtnsWithFuncs(()=>{},a=e=>{confirm(e.target.id)},function(e){prompt(e.target.outerHTML)},function test(e){return 1})
function myReaddBtnsWithFuncs(...funcs){
    funcs.forEach(e=>{
        if(typeof e !='function') return;
    });
    let myDiv=document.querySelector('#myDiv0');
    if(myDiv) myDiv.remove(),myDiv=myDomAppendSon(document.body,'div','','id','myDiv0')
    else myDiv=myDomAppendSon(document.body,'div','','id','myDiv0');
    myAddStyle(`#myDiv0{z-index:999999;position: fixed!important;right: 0;top:0}`);
    for(let i=0;i<funcs.length;i++){
        let fname=funcs[i].name;console.log(fname)
        const bname="btn"+i;
        if(!fname) fname="noname";
        const btn = myDomAppendSon(myDiv,'input','','value',fname,'type','button','id',bname);
        btn.addEventListener('click',funcs[i])
    }
}
//myAddBtnsWithFuncs(()=>{},a=e=>{confirm(e.target.id)},function(e){prompt(e.target.outerHTML)},function test(e){return 1})
function myAddBtnsWithFuncs(...funcs){
    funcs.forEach(e=>{
        if(typeof e !='function') return;
    });
    let myDiv=document.querySelector('#myDiv1');
    if(!myDiv) myDiv=myDomAppendSon(document.body,'div','','id','myDiv1')
    myAddStyle(`#myDiv1{z-index:999999;position: fixed!important;right: 0;bottom:0}`);
    for(let i=0;i<funcs.length;i++){
        let fname=funcs[i].name;console.log(fname)
        const bname="btn"+i;
        if(!fname) fname="noname";
        const btn = myDomAppendSon(myDiv,'input','','value',fname,'type','button','id',bname);
        btn.addEventListener('click',funcs[i])
    }
}
//prevent document.title from being changed
function myFixTitle(){
    Object.defineProperty(document,"title",{
        writable:false
    });
}