/
min.min.js
1 lines (1 loc) · 5.04 KB
/
min.min.js
1
const min=function(){"use strict";return{NOT_FOUND:-1,EMPTY:0,FIRST:0,dom:{ALL:-1,FIRST:0,getById:function(t){return document.getElementById(t)},getByClassName:function(t,e,n,o){if(void 0===n||n instanceof(o||window).HTMLElement){const o=(n||document).getElementsByClassName(t);return e===this.ALL?o:o[e||this.FIRST]}return null},getByTagName:function(t,e,n,o){if(void 0===n||n instanceof(o||window).HTMLElement){const o=(n||document).getElementsByTagName(t);return e===this.ALL?o:o[e||this.FIRST]}return null},getByQuery:function(t,e,n,o){if(void 0===n||n instanceof(o||window).HTMLElement){const o=void 0===e||e===this.FIRST,i=(n||document)[o?"querySelector":"querySelectorAll"](t);return e===this.ALL||o?i:i[e]}return null},getByXPath:function(t,e,n,o){if(void 0===n||n instanceof(o||window).HTMLElement){let o=t;n&&n instanceof HTMLElement&&(o=`.${t}`);const i=document.evaluate(o,n||document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),r=function(t){const e=[];for(let n=0;n<t.snapshotLength;n++)e.push(t.snapshotItem(n));return e};return e===this.ALL?r(i):i.snapshotItem(e||this.FIRST)}return null},getByMeta:function(t,e){return this.getByXPath(`//head/meta[@${t} = '${e}']`)},create:function(t,e){const n=document.createElement(t);if(e)for(const t in e){if(!Object.prototype.hasOwnProperty.call(e,t))continue;const o=e[t];if("string"==typeof o)n.setAttribute(t,o);else{let e="";for(const t in o)Object.prototype.hasOwnProperty.call(o,t)&&(e+=`${t}: ${o[t]} !important;`);n.setAttribute(t,e)}}return n},style:function(t,e){let n="";for(const t in e){if(!Object.prototype.hasOwnProperty.call(e,t))continue;n+=`${t}: ${e[t]} !important; `}t.style.cssText+=n.trim()},removeNode:function(t){t&&t.parentNode&&t.parentNode.removeChild(t)},removeNodes:function(t,e,...n){let o;if(t instanceof Function){let n=e instanceof Array?e:[e];n=n.map(e=>t.call(min.dom,e)),o=[],min.forEach(n,t=>{t.length?min.forEach(t,t=>{o.push(t)}):o.push(t)})}else o=n;min.forEach(o,min.dom.removeNode)},insertBefore:function(t,e){e.parentNode&&e.parentNode.insertBefore(t,e)},insertAfter:function(t,e){e.parentNode&&e.nextSibling&&e.parentNode.insertBefore(t,e.nextSibling)},addObserver:function(t,e,n){new MutationObserver(t).observe(e||document.body,n||{childList:!0,subtree:!0})},onNodeExists:function(t,e,n,o){const i=e instanceof Array?e:[e],r=void 0===o||o;t.apply(min.dom,i)?n(t.apply(min.dom,i)):this.addObserver((e,o)=>{t.apply(min.dom,i)&&(r&&o.disconnect(),n(t.apply(min.dom,i)))})},onNodesExist:function(t,e){let n=0;const o={},i=function(t,i,r){min.dom.onNodeExists(t,i,t=>{o[i]=t,(n+=1)===r&&e(o)})};if(t.getter){const{getter:e,params:n}=t,o=n.length;min.forEach(n,t=>{i(e,t,o)})}else{const{rules:e}=t,n=e.length;min.forEach(e,t=>{const[e,o]=t;i(e,o,n)})}},onNodeInserted:function(t,e){this.addObserver(e=>{min.forEach(e,e=>{min.forEach(e.addedNodes,t)})},e)},iframe:function(t,e,n=document){const o=min.dom.create("iframe",{src:t});o.onload=(()=>{e(o),min.dom.removeNode(this)}),n.body.appendChild(o)}},gm:function(){const t=function(t){return console.error(`Forgot to @grant ${t}!`),null};return{get:function(e){return JSON.parse("undefined"==typeof GM_getValue?t("GM_getValue"):GM_getValue(e,"{}"))},set:function(e,n){"undefined"==typeof GM_setValue?t("GM_setValue"):GM_setValue(e,JSON.stringify(n))},add:function(t,e){const n=this.get(t);n.content?n.content.push(e):n[e.key]=e.value,this.set(t,n)},remove:function(t,e){const n=this.get(t);if(n.content){const t=n.content.indexOf(e);t!==min.NOT_FOUND&&n.content.splice(t,1)}else delete n[e];this.set(t,n)},clear:function(t){let e=this.get(t);e=e.content?{content:[]}:{},this.set(t,e)},contains:function(t,e){const n=this.get(t);if(n.content)return n.content.indexOf(e)!==min.NOT_FOUND;let o=!1;return min.forEach(Object.keys(n),t=>{if(n[t]===e)return o=!0,!0}),o},read:function(e){return"undefined"==typeof GM_getResourceText?t("GM_getResourceText"):GM_getResourceText(e)},style:function(e){let n="";for(const t in e){if(!Object.prototype.hasOwnProperty.call(e,t))continue;n+=`${t} {`;const o=e[t];for(const t in o)Object.prototype.hasOwnProperty.call(o,t)&&(n+=`${t}: ${o[t]} !important; `);n+="} "}"undefined"==typeof GM_addStyle?t("GM_addStyle"):GM_addStyle(n.trim())},xhr:function(e,n,o,i,r=null,s=!1){"undefined"==typeof GM_xmlhttpRequest?t("GM_xmlhttpRequest"):GM_xmlhttpRequest({method:i||"GET",url:e,context:o,headers:r,onload:function(t){if(s)n(t.responseText,t.context,t.finalUrl);else{const e=document.createElement("div");e.innerHTML=t.responseText,n(e,t.context,t.finalUrl)}}})}}}(),concatenate:function(t,e){let n=t,o=e;return t instanceof HTMLCollection&&(n=this.toArray(t)),e instanceof HTMLCollection&&(o=this.toArray(e)),n.concat(o)},toArray:function(t){return Array.prototype.slice.call(t)},forEach:function(t,e){for(let n=0;n<t.length;n++){if(!0===e(t[n],n))return}},isOnWebsite:function(t){return window.self===window.top&&window.location.hostname.indexOf(t)!==this.NOT_FOUND},isOnPath:function(t,e){const n=window.location.pathname;return!this.isOnIframe()&&(t instanceof RegExp?t.test(n):e?n===t:n.indexOf(t)!==this.NOT_FOUND)},isOnIframe:function(){return window.self!==window.top}}}();