UnaTools

自用公用脚本

Este script não deve ser instalado diretamente. Este script é uma biblioteca de outros scripts para incluir com o diretório meta // @require https://update.greasyfork.org/scripts/493023/1472683/UnaTools.js

const log=console.log.bind(console,"%c[Tools]:","font-weight:bold;background-color:#D8D8D8;color:#000;padding: 3px 3px;margin: 5px 0px;border-radius:2px;");const debuglog=console.log.bind(console,"%c[Tools]:","font-weight:bold;background-color:#00A0D8;color:#fff;padding: 3px 3px;margin: 5px 0px;border-radius:2px;");const toastStyle=`.link-toast{position:relative !important;margin-top:5px;padding:12px 24px;font-size:14px;border-radius:8px;white-space:nowrap;color:#fff;-webkit-transition:-webkit-transform 0.4s cubic-bezier(0.22,0.58,0.12,0.98);transition:-webkit-transform 0.4s cubic-bezier(0.22,0.58,0.12,0.98);transition:transform 0.4s cubic-bezier(0.22,0.58,0.12,0.98);transition:transform 0.4s cubic-bezier(0.22,0.58,0.12,0.98),-webkit-transform 0.4s cubic-bezier(0.22,0.58,0.12,0.98);-webkit-animation:link-msg-move-in-top cubic-bezier(0.22,0.58,0.12,0.98) 0.4s;animation:link-msg-move-in-top cubic-bezier(0.22,0.58,0.12,0.98) 0.4s;z-index:10100;text-align:center;height:auto;line-height:auto}.link-toast.mobile{text-align:center;-webkit-box-shadow:none !important;box-shadow:none !important;width:auto;background-color:transparent !important;position:fixed;top:50vh;left:0;right:0}.link-toast.mobile .toast-text{background-color:rgba(0,0,0,0.8);padding:8px;border-radius:8px;display:inline-block;min-width:50px;word-break:break-all;white-space:pre-wrap}.link-toast.fixed{position:fixed}.link-toast.success{background-color:#47d279;-webkit-box-shadow:0 0.2em 0.1em 0.1em rgba(71,210,121,0.2);box-shadow:0 0.2em 0.1em 0.1em rgba(71,210,121,0.2)}.link-toast.caution{background-color:#ffb243;-webkit-box-shadow:0 0.2em 0.1em 0.1em rgba(255,190,68,0.2);box-shadow:0 0.2em 0.1em 0.1em rgba(255,190,68,0.2)}.link-toast.error{background-color:#ff6464;-webkit-box-shadow:0 0.2em 1em 0.1em rgba(255,100,100,0.2);box-shadow:0 0.2em 1em 0.1em rgba(255,100,100,0.2)}.link-toast.info{background-color:#48bbf8;-webkit-box-shadow:0 0.2em 0.1em 0.1em rgba(72,187,248,0.2);box-shadow:0 0.2em 0.1em 0.1em rgba(72,187,248,0.2)}.link-toast.out-fade{-webkit-animation:link-msg-fade-out cubic-bezier(0.22,0.58,0.12,0.98) 0.4s;animation:link-msg-fade-out cubic-bezier(0.22,0.58,0.12,0.98) 0.4s}@-webkit-keyframes link-msg-move-in-top{from{opacity:0;-webkit-transform:translate(0,5em);transform:translate(0,5em)}to{opacity:1;-webkit-transform:translate(0,0);transform:translate(0,0)}}@keyframes link-msg-move-in-top{from{opacity:0;-webkit-transform:translate(0,5em);transform:translate(0,5em)}to{opacity:1;-webkit-transform:translate(0,0);transform:translate(0,0)}}@-webkit-keyframes link-msg-fade-out{from{opacity:1}to{opacity:0}}@keyframes link-msg-fade-out{from{opacity:1}to{opacity:0}}.el-fade-enter,.el-fade-leave{max-height:0!important;;margin:0!important;;padding:0!important;;opacity:0!important;;animation-timing-function:linear;animation-duration:.2s;animation-fill-mode:both;animation-play-state:paused}.el-fade-enter.el-fade-enter-active{animation-name:el-fade-in;animation-play-state:running}.el-fade-leave.el-fade-leave-active{animation-name:el-fade-out;animation-play-state:running;pointer-events:none;transition:all .3s!important;}.el-fade-enter-active,.el-fade-leave-active{transition:opacity .3s}@keyframes el-fade-in{0%{opacity:0}to{opacity:1}}@-webkit-keyframes el-fade-in{0%{opacity:0}to{opacity:1}}@keyframes el-fade-out{0%{opacity:1}to{opacity:0}}@-webkit-keyframes el-fade-out{0%{opacity:1}to{opacity:0}}`;const aniStyle=`@keyframes aniLeftToRight{0%{transform:translateX(-32px);opacity:0.2}20%{opacity:0.5}30%{opacity:0.8}100%{opacity:1}}@keyframes aniBottomToTop{0%{transform:translateY(32px);opacity:0.2}20%{opacity:0.5}30%{opacity:0.8}100%{opacity:1}}@-webkit-keyframes aniTopToBottom{0%{transform:translateY(-32px);opacity:0.2}20%{opacity:0.5}30%{opacity:0.8}100%{opacity:1}}@-webkit-keyframes aniHideToShow{0%{display:none;opacity:0.2}20%{opacity:0.5}30%{opacity:0.8}100%{opacity:1}}@-webkit-keyframes aniShowToHide{0%{display:none;opacity:1}20%{opacity:0.8}30%{opacity:0.5}100%{opacity:0.3}}.aniDelete{transition:all 0.15s cubic-bezier(0.4,0,1,1);opacity:0.1}@keyframes spin{0%{transform:rotate(0deg);}100%{transform:rotate(360deg);}}`;const ContentType={json:"application/json;charset=UTF-8",form:"application/x-www-form-urlencoded; charset=UTF-8",download:"application/octet-stream"};const ToastType={success:"success",error:"error",info:"info",warn:"caution"};function toast(message="成功",type=ToastType.info,wait=3e3,target=document.body){let toasts=$one(".link-toasts");if(!toasts){toasts=document.createElement("div");toasts.className="link-toasts";toasts.style.cssText="z-index:9999;top:70px;right:25px;position:fixed;display:flex;flex-direction:column;align-items:flex-end;";target.append(toasts)}const toast=document.createElement("div");toast.className=`link-toast ${type}`;toast.innerHTML=`<span class="toast-text">${message}</span>`;toasts.append(toast);setTimeout(()=>{fadeOutRemove(toast)},wait)}function parseBoolean(val){const str=String(val).toLowerCase();if(["yes","y","true","1","on"].includes(str))return true;if(["no","n","false","0","off"].includes(str))return false;return Boolean(val)}function fadeInShow(element){element.classList.remove("el-hidden");element.classList.add("el-fade-enter","el-fade-enter-active");const f=()=>{element.classList.remove("el-fade-enter","el-fade-enter-active");element.removeEventListener("animationend",f);element.removeEventListener("webkitAnimationEnd",f)};element.addEventListener("animationend",f);element.addEventListener("webkitAnimationEnd",f)}function fadeOutHide(element){element.classList.add("el-fade-leave","el-fade-leave-active");const f=()=>{element.classList.remove("el-fade-leave","el-fade-leave-active");element.classList.add("el-hidden");element.removeEventListener("animationend",f);element.removeEventListener("webkitAnimationEnd",f)};element.addEventListener("animationend",f);element.addEventListener("webkitAnimationEnd",f)}function fadeOutRemove(element){element.classList.add("el-fade-leave","el-fade-leave-active");const f=()=>{aniRemove(element,false,0);element.removeEventListener("animationend",f);element.removeEventListener("webkitAnimationEnd",f)};element.addEventListener("animationend",f);element.addEventListener("webkitAnimationEnd",f)}function $one(selector,element=document){return element.querySelector(selector)}function $all(selector,element=document){return element.querySelectorAll(selector)}function safeRemove(selector,withAni=false,wait=200){safeFunction(()=>{let removeNodes=document.querySelectorAll(selector);for(let i=0;i<removeNodes.length;i++){aniRemove(removeNodes[i],withAni,wait)}})}function aniRemove(node,withAni=false,wait=200){if(withAni){node.classList.add("aniDelete");setTimeout(()=>{node.remove()},wait)}else{node.remove()}}function safeFunction(func,failCb=()=>{}){try{func()}catch(e){failCb&&failCb(e)}}function retryInterval(callback,period=50,now=false,count=-1){if(now&&count--!==0){if(callback())return}const inter=setInterval(()=>{if(count--===0){return clearInterval(inter)}callback()&&clearInterval(inter)},period)}function safeWaitFunc(selector,callbackFunc,time=60,notClear=false){notClear=notClear||false;let doClear=!notClear;retryInterval(()=>{if(typeof selector==="string"&&document.querySelector(selector)!=null){callbackFunc(document.querySelector(selector));if(doClear)return true}else if(typeof selector==="function"&&(selector()!=null||(selector()||[]).length>0)){callbackFunc(selector()[0]);if(doClear)return true}},time,true)}function randomString(n){const chars=["0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];let res="";for(let i=0;i<n;i++){const id=Math.floor(Math.random()*chars.length);res+=chars[id]}return res}function sleep(milliseconds){return new Promise(resolve=>{setTimeout(()=>{resolve()},milliseconds)})}function isEmpty(val){if(val===undefined||val===null||val===""){return true}if(Array.isArray(val)){return val.length===0}if(typeof val==="object"&&val!==null){return Object.keys(val).length===0}return false}function isArray(arr){const toString=Object.prototype.toString;const isArray=Array.isArray||function(arg){return toString.call(arg)==="[object Array]"};return isArray(arr)}function isObject(val){return typeof val==="object"&&val!==null&&Array.isArray(val)===false}function filterNullUndefined(obj){if(!isObject(obj)){return{}}return Object.entries(obj).reduce((acc,[key,value])=>{if(value!==null&&value!==undefined&&value!==""){acc[key]=value}return acc},{})}function acquireChain(key=[],source={}){if(!isArray(key)){return{}}return key.reduce((res,k)=>{if(!res)return{};return res[k]},source)}function isExpired(timestamp,time){if(typeof timestamp!=="number"||typeof time!=="number"||time<0){throw new Error("Invalid input: timestamp must be a number and time must be a non-negative number")}if(timestamp<0){throw new Error("Invalid timestamp: timestamp must be a non-negative number")}const currentTime=Date.now();const timeDifference=currentTime-timestamp;return timeDifference>time}function isSameDay(date1,date2){const d1=new Date(date1);const d2=new Date(date2);if(isNaN(d1.getTime())||isNaN(d2.getTime())){throw new Error("Invalid date")}return d1.getFullYear()===d2.getFullYear()&&d1.getMonth()===d2.getMonth()&&d1.getDate()===d2.getDate()}function isToday(date){if(isEmpty(date)){return false}const today=new Date;return isSameDay(date,today)}function request(path,method="GET",data={},headers={}){function transform(data={}){const esc=encodeURIComponent;return Object.keys(data).map(k=>`${esc(k)}=${esc(data[k])}`).join("&")}method=method.toLocaleUpperCase();const config={method:method,mode:"cors",credentials:"include",headers:Object.assign({"Content-type":ContentType.form},headers)};if(method==="GET"){let param=transform(data);if(param)path+=`?${param}`}else if(config.headers["Content-type"]===ContentType.form){config.body=transform(data)}else{config.body=JSON.stringify(data)}return fetch(path,config).then(response=>response.json())}function arcoSwitchChange(e){const $ev=e;const target=$ev.target||$ev.srcElement;const btn=target.closest(".arco-switch");if(!btn)return;if(btn.classList.contains("arco-switch-checked")){btn.classList.remove("arco-switch-checked");btn.setAttribute("aria-checked",false)}else{btn.classList.add("arco-switch-checked");btn.setAttribute("aria-checked",true)}btn.dispatchEvent(new Event("change"))}function insideCheck(e,selector){const $ev=e;const target=$ev.target||$ev.srcElement;if(!Element.prototype.closest){Element.prototype.closest=function(selector){let el=this;while(el){if(el.matches(selector)){return el}el=el.parentElement}return null}}if(!target){return null}try{return target.closest(selector)}catch(error){log(`insideCheck error: ${error.message}`);return null}}