@eyeo/snippets
Version:
eye/o snippets for Ads blocker
33 lines (32 loc) • 28.1 kB
JavaScript
/*!
* This file is part of eyeo's Anti-Circumvention Snippets module (@eyeo/snippets),
* Copyright (C) 2006-present eyeo GmbH
*
* @eyeo/snippets is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* @eyeo/snippets is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with @eyeo/snippets. If not, see <http://www.gnu.org/licenses/>.
*/
const callback = (environment, ...filters) => {
const e=Proxy,{apply:t,bind:n,call:o}=Function,r=o.bind(t),i=o.bind(n),s=o.bind(o),a={get:(e,t)=>i(o,e[t])},c=t=>new e(t,a),l={get:(e,t)=>i(e[t],e)},u=t=>new e(t,l),{assign:d,defineProperties:f,freeze:h,getOwnPropertyDescriptor:p,getOwnPropertyDescriptors:m,getPrototypeOf:g}=u(Object),{hasOwnProperty:w}=c({}),{species:b}=Symbol,y={get(e,t){const n=e[t];class o extends n{}const r=m(n.prototype);delete r.constructor,h(f(o.prototype,r));const i=m(n);return delete i.length,delete i.prototype,i[b]={value:o},h(f(o,i))}},v=t=>new e(t,y),k="undefined"!=typeof environment?environment:{};"undefined"==typeof globalThis&&(window.globalThis=window);const{apply:x,ownKeys:S}=u(Reflect),E="world"in k,T=E&&"ISOLATED"===k.world,M=E&&"MAIN"===k.world,C="object"==typeof chrome&&!!chrome.runtime,L="object"==typeof browser&&!!browser.runtime,P=!M&&(T||C||L),O=e=>P?e:W(e,A(e)),{create:W,defineProperties:R,defineProperty:D,freeze:I,getOwnPropertyDescriptor:N,getOwnPropertyDescriptors:A}=u(Object),$=u(globalThis),F=P?globalThis:v(globalThis),{Map:V,RegExp:j,Set:H,WeakMap:B,WeakSet:q}=F,_=(e,t,n=null)=>{const o=S(t);for(const r of S(e)){if(o.includes(r))continue;const i=N(e,r);if(n&&"value"in i){const{value:e}=i;"function"==typeof e&&(i.value=n(e))}D(t,r,i)}},z=e=>{const t=F[e];class n extends t{}const{toString:o,valueOf:r}=t.prototype;R(n.prototype,{toString:{value:o},valueOf:{value:r}});const i=e.toLowerCase(),s=e=>function(){const t=x(e,this,arguments);return typeof t===i?new n(t):t};return _(t,n,s),_(t.prototype,n.prototype,s),n},X=I({frozen:new B,hidden:new q,iframePropertiesToAbort:{read:new H,write:new H},abortedIframes:new B}),U=new j("^[A-Z]"),G=P&&(C&&chrome||L&&browser)||void 0;var J=new Proxy(new V([["chrome",G],["browser",G],["isExtensionContext",P],["variables",X],["console",O(console)],["document",globalThis.document],["JSON",O(JSON)],["Map",V],["Math",O(Math)],["Number",P?Number:z("Number")],["RegExp",j],["Set",H],["String",P?String:z("String")],["WeakMap",B],["WeakSet",q],["MouseEvent",MouseEvent]]),{get(e,t){if(e.has(t))return e.get(t);let n=globalThis[t];return"function"==typeof n&&(n=(U.test(t)?F:$)[t]),e.set(t,n),n},has:(e,t)=>e.has(t)});const K={WeakSet:WeakSet,WeakMap:WeakMap,WeakValue:class{has(){return!1}set(){}}},{apply:Q}=Reflect;const{Map:Y,WeakMap:Z,WeakSet:ee,setTimeout:te}=J;let ne=!0,oe=e=>{e.clear(),ne=!ne};var re=function(e){const{WeakSet:t,WeakMap:n,WeakValue:o}=this||K,r=new t,i=new n,s=new o;return function(t){if(r.has(t))return t;if(i.has(t))return i.get(t);if(s.has(t))return s.get(t);const n=Q(e,this,arguments);return r.add(n),n!==t&&("object"==typeof t&&t?i:s).set(t,n),n}}.bind({WeakMap:Z,WeakSet:ee,WeakValue:class extends Y{set(e,t){return ne&&(ne=!ne,te(oe,0,this)),super.set(e,t)}}});const{concat:ie,includes:se,join:ae,reduce:ce,unshift:le}=c([]),ue=v(globalThis),{Map:de,WeakMap:fe}=ue,he=new de,pe=t=>{const n=(e=>{const t=[];let n=e;for(;n;){if(he.has(n))le(t,he.get(n));else{const e=m(n);he.set(n,e),le(t,e)}n=g(n)}return le(t,{}),r(d,null,t)})("function"==typeof t?t.prototype:t),o={get(e,t){if(t in n){const{value:o,get:r}=n[t];if(r)return s(r,e);if("function"==typeof o)return i(o,e)}return e[t]},set(e,t,o){if(t in n){const{set:r}=n[t];if(r)return s(r,e,o),!0}return e[t]=o,!0}};return t=>new e(t,o)},{isExtensionContext:me,Array:ge,Number:we,String:be,Object:ye}=J,{isArray:ve}=ge,{getOwnPropertyDescriptor:ke,setPrototypeOf:xe}=ye,{toString:Se}=ye.prototype,{slice:Ee}=be.prototype,{get:Te}=ke(Node.prototype,"nodeType"),Me=me?{}:{Attr:pe(Attr),CanvasRenderingContext2D:pe(CanvasRenderingContext2D),CSSStyleDeclaration:pe(CSSStyleDeclaration),Document:pe(Document),Element:pe(Element),HTMLCanvasElement:pe(HTMLCanvasElement),HTMLElement:pe(HTMLElement),HTMLImageElement:pe(HTMLImageElement),HTMLScriptElement:pe(HTMLScriptElement),MutationRecord:pe(MutationRecord),Node:pe(Node),ShadowRoot:pe(ShadowRoot),get CSS2Properties(){return Me.CSSStyleDeclaration}},Ce=(e,t)=>{if("Element"!==t&&t in Me)return Me[t](e);if(ve(e))return xe(e,ge.prototype);const n=(e=>s(Ee,s(Se,e),8,-1))(e);if(n in Me)return Me[n](e);if(n in J)return xe(e,J[n].prototype);if("nodeType"in e)switch(s(Te,e)){case 1:if(!(t in Me))throw new Error("unknown hint "+t);return Me[t](e);case 2:return Me.Attr(e);case 3:return Me.Node(e);case 9:return Me.Document(e)}throw new Error("unknown brand "+n)};var Le=me?e=>e===window||e===globalThis?J:e:re(((e,t="Element")=>{if(e===window||e===globalThis)return J;switch(typeof e){case"object":return e&&Ce(e,t);case"string":return new be(e);case"number":return new we(e);default:throw new Error("unsupported value")}}));let Pe=!1;function Oe(){return Pe}let{console:We,document:Re,getComputedStyle:De,isExtensionContext:Ie,variables:Ne,Array:Ae,MutationObserver:$e,Object:Fe,XPathEvaluator:Ve,XPathExpression:je,XPathResult:He}=Le(window);const{querySelectorAll:Be}=Re,qe=Be&&i(Be,Re);function _e(e,t=!1){try{const n=navigator.userAgent.includes("Firefox")?e.openOrClosedShadowRoot:browser.dom.openOrClosedShadowRoot(e);return null===n&&Oe()&&!t&&We.log("Shadow root not found or not added in element yet",e),n}catch(n){return Oe()&&!t&&We.log("Error while accessing shadow root",e,n),null}}function ze(e,t=!1){return Ge(e,qe.bind(Re),Re,t)}function Xe(e,t,n,o){const r=t.getAttribute("xlink:href")||t.getAttribute("href");if(r){const s=qe(r)[0];if(!s&&Oe())return We.log("No elements found matching",r),!1;if(!(i=e)||0===i.length||i.every((e=>""===e.trim()))){const e=o.length>0?o:[];return n.push({element:s,rootParents:[...e,t]}),!1}const a=s.querySelectorAll.bind(s);return{nextBoundElement:s,nestedSelectorsString:e.join("^^"),next$$:a}}var i}function Ue(e,t){const n=_e(t);if(n){const{querySelectorAll:o}=n,r=o&&i(o,n).bind(n);return{nextBoundElement:t,nestedSelectorsString:":host "+e.join("^^"),next$$:r}}return!1}function Ge(e,t,n,o,r=[]){if(e.includes("^^")){const[i,s,...a]=e.split("^^");let c,l;switch(s){case"svg":l=Xe;break;case"sh":l=Ue;break;default:return Oe()&&We.log(s," is not supported. Supported commands are: \n^^sh^^\n^^svg^^"),[]}c=""===i.trim()?[n]:t(i);const u=[];for(const e of c){const t=l(a,e,u,r);if(!t)continue;const{next$$:n,nestedSelectorsString:i,nextBoundElement:s}=t,c=Ge(i,n,s,o,[...r,e]);c&&u.push(...c)}return u}const i=t(e);return o?[...i].map((e=>({element:e,rootParents:r.length>0?r:[]}))):i}function Je(e,t,n=[]){if(t.includes("^^svg^^")&&(t=t.split("^^svg^^")[0]),t.includes("^^sh^^")){const o=t.split("^^sh^^"),r=o.length-1;if(t=`:host ${o[r]}`,r===n.length)return e.closest(t);return n[r].closest(t)}return n[0]?n[0].closest(t):e.closest(t)}const{assign:Ke,setPrototypeOf:Qe}=Fe;class Ye extends je{evaluate(...e){return Qe(r(super.evaluate,this,e),He.prototype)}}class Ze extends Ve{createExpression(...e){return Qe(r(super.createExpression,this,e),Ye.prototype)}}function et(e){if(Ne.hidden.has(e))return!1;!function(e){Ie&&"function"==typeof checkElement&&checkElement(e)}(e),Ne.hidden.add(e);let{style:t}=Le(e),n=Le(t,"CSSStyleDeclaration"),o=Le([]),{debugCSSProperties:r}=k;for(let[e,t]of r||[["display","none"]])n.setProperty(e,t,"important"),o.push([e,n.getPropertyValue(e)]);return new $e((()=>{for(let[e,t]of o){let o=n.getPropertyValue(e),r=n.getPropertyPriority(e);o==t&&"important"==r||n.setProperty(e,t,"important")}})).observe(e,{attributes:!0,attributeFilter:["style"]}),!0}function tt(e){let t=e;if(t.startsWith("xpath(")&&t.endsWith(")")){let e=t.slice(6,-1),n=(new Ze).createExpression(e,null),o=He.ORDERED_NODE_SNAPSHOT_TYPE;return e=>{if(!e)return;let t=n.evaluate(Re,o,null),{snapshotLength:r}=t;for(let n=0;n<r;n++)e(t.snapshotItem(n))}}return t=>ze(e).forEach(t)}function nt(e,t,n,o){let r;null==n&&(n=t);const i=()=>{for(const{element:i,rootParents:s}of ze(n,!0)){const n=Je(Le(i),t,s);n&&e(i,n,s)&&(r(),et(n)&&"function"==typeof o&&o(n))}};return Ke(new $e(i),{race(e){r=e,this.observe(Re,{childList:!0,characterData:!0,subtree:!0}),i()}})}function ot(e,t,n,o){let r=Le(t,"CSSStyleDeclaration");if("none"==r.getPropertyValue("display"))return!1;let i=r.getPropertyValue("visibility");if("hidden"==i||"collapse"==i)return!1;if(!n||e==n)return!0;let s=Le(e).parentElement;if(!s){if(!o||!o.length)return!0;s=o[o.length-1],o=o.slice(0,-1)}return ot(s,De(s),n,o)}function rt(e){let t=De(e),{cssText:n}=t;if(n)return n;for(let e of t)n+=`${e}: ${t[e]}; `;return Le(n).trim()}let{Array:it,Math:st,RegExp:at}=Le(window);function ct(e){let{length:t}=e;if(t>1&&"/"===e[0]){let n="/"===e[t-1];if(n||t>2&&Le(e).endsWith("/i")){let t=[Le(e).slice(1,n?-1:-2)];return n||t.push("i"),new at(...t)}}return new at(Le(e).replace(/[-/\\^$*+?.()|[\]{}]/g,"\\$&"))}function lt(e){return Le(it.from(e)).map((e=>`'${e}'`)).join(" ")}let{Math:ut,setInterval:dt,performance:ft}=Le(window);const ht={mark(){},end(){},toString:()=>"{mark(){},end(){}}"};let pt=!0;function mt(e,t=10){if(pt)return ht;function n(){let e=Le([]);for(let{name:t,duration:n}of ft.getEntriesByType("measure"))e.push({name:t,duration:n});e.length&&ft.clearMeasures()}return mt[e]||(mt[e]=dt(n,ut.round(6e4/ut.min(60,t)))),{mark(){ft.mark(e)},end(t=!1){ft.measure(e,e);const o=ft.getEntriesByName(e,"measure"),r=o.length>0?o[o.length-1]:null;console.log("PROFILER:",r),ft.clearMarks(e),t&&(clearInterval(mt[e]),delete mt[e],n())}}}const{console:gt}=Le(window),wt=()=>{};function bt(...e){let{mark:t,end:n}=mt("log");if(Oe()){const t=["%c DEBUG","font-weight: bold;"],n=e.indexOf("error"),o=e.indexOf("warn"),r=e.indexOf("success"),i=e.indexOf("info");-1!==n?(t[0]+=" - ERROR",t[1]+="color: red; border:2px solid red",Le(e).splice(n,1)):-1!==o?(t[0]+=" - WARNING",t[1]+="color: orange; border:2px solid orange ",Le(e).splice(o,1)):-1!==r?(t[0]+=" - SUCCESS",t[1]+="color: green; border:2px solid green",Le(e).splice(r,1)):-1!==i&&(t[1]+="color: black;",Le(e).splice(i,1)),Le(e).unshift(...t)}t(),gt.log(...e),n()}function yt(e){return i(Oe()?bt:wt,null,e)}let{Array:vt,Error:kt,Map:xt,parseInt:St}=Le(window),Et=null,Tt=null;function Mt(e,t){if(null===Et)return wt;let n=Et,{participants:o}=n;return o.set(r,t),r;function r(){if(n.winners<1)return;if(yt("race")("success",`${e} won the race`),n===Et)Tt.push(r);else if(o.delete(r),--n.winners<1){for(let e of o.values())e();o.clear()}}}const Ct={get(e,t){const n=e;for(;!w(e,t);)e=g(e);const{get:o,set:i}=p(e,t);return function(){return arguments.length?r(i,n,arguments):s(o,n)}}};var Lt;function Pt(e,t,n){var o,r;n?"load"===n?(e("info","Waiting until window.load"),window.addEventListener("load",(()=>{e("info","Window.load fired."),t()}))):"loading"===n||"interactive"===n||"complete"===n?(e("info","Waiting document state until :",n),document.addEventListener("readystatechange",(()=>{e("info","Document state changed:",document.readyState),document.readyState===n&&t()}))):(e("info","Waiting until ",n," event is triggered on document"),(o=document,r=n,new Promise((e=>{const t=()=>{o.removeEventListener(r,t),e()};o.addEventListener(r,t)}))).then((()=>{e("info",n," is triggered on document, starting the snippet"),t()})).catch((t=>{e("error","There was an error while waiting for the event.",t)}))):t()}Le(window),Lt=window,new e(Lt,Ct),Le(/^\d+$/);let{MutationObserver:Ot,WeakSet:Wt,getComputedStyle:Rt}=Le(window);let{clearTimeout:Dt,fetch:It,getComputedStyle:Nt,setTimeout:At,Map:$t,MutationObserver:Ft,Uint8Array:Vt}=Le(window);let jt=new $t;function Ht(e,{as:t="arrayBuffer",cleanup:n=6e4}={}){let o=t+":"+e,r=jt.get(o)||{remove:()=>jt.delete(o),result:null,timer:0};return Dt(r.timer),r.timer=At(r.remove,n),r.result||(r.result=It(e).then((e=>e[t]())).catch(r.remove),jt.set(o,r)),r.result}const{parseFloat:Bt,Math:qt,MutationObserver:_t,WeakSet:zt}=Le(window),{min:Xt}=qt,Ut=(e,t)=>{const n=e.length+1,o=t.length+1,r=[[0]];let i=0,s=0;for(;++i<o;)r[0][i]=i;for(i=0;++i<n;){const n=e[s];let a=0,c=0;for(r[i]=[i];++a<o;)r[i][a]=Xt(r[s][a]+1,r[i][c]+1,r[s][c]+(n!=t[c])),++c;++s}return r[n-1][o-1]};let{getComputedStyle:Gt,Map:Jt,WeakSet:Kt,parseFloat:Qt,DOMMatrix:Yt,Math:Zt}=Le(window);const{ELEMENT_NODE:en,TEXT_NODE:tn}=Node;let{MutationObserver:nn,WeakSet:on,getComputedStyle:rn}=Le(window);let{getComputedStyle:sn,MutationObserver:an,WeakSet:cn}=Le(window);let{MutationObserver:ln,WeakSet:un}=Le(window);const{ELEMENT_NODE:dn}=Node;let{MutationObserver:fn,WeakSet:hn}=Le(window);const{ELEMENT_NODE:pn}=Node;let{parseInt:mn,setTimeout:gn,Error:wn,MouseEvent:bn,MutationObserver:yn,WeakSet:vn}=Le(window);const kn=["auxclick","click","dblclick","gotpointercapture","lostpointercapture","mouseenter","mousedown","mouseleave","mousemove","mouseout","mouseover","mouseup","pointerdown","pointerenter","pointermove","pointerover","pointerout","pointerup","pointercancel","pointerleave"];let{isNaN:xn,MutationObserver:Sn,parseInt:En,parseFloat:Tn,setTimeout:Mn}=Le(window);const Cn={log:bt,race:function(e,t="1"){switch(e){case"start":Et={winners:St(t,10)||1,participants:new xt},Tt=new vt;break;case"end":case"finish":case"stop":Et=null;for(let e of Tt)e();Tt=null;break;default:throw new kt(`Invalid action: ${e}`)}},debug:function(){Pe=!0},profile:function(){pt=!1},"hide-if-matches-xpath":function(e,t,n){const{mark:o,end:r}=mt("hide-if-matches-xpath"),i=lt(arguments),s=yt("hide-if-matches-xpath");Pt(s,(()=>{const n=n=>{const a=tt(`xpath(${e})`),c=new un,l=e=>{c.add(e),f(),Le(e).nodeType===dn?et(e):Le(e).textContent="",s("success","Matched: ",e,"\nFILTER: hide-if-matches-xpath",i)},u=()=>{o(),a((e=>{if(c.has(e))return!1;if(t){tt(`xpath(${t})`)((t=>{if(!t.contains(e))return!1;l(e)}))}else l(e)})),r()},d=new ln(u),f=Mt("hide-if-matches-xpath",(()=>d.disconnect()));d.observe(n,{characterData:!0,childList:!0,subtree:!0}),u()};if(t){let e,o=0;const r=tt(`xpath(${t})`),i=()=>{r((e=>{n(e),o++})),o>0&&e.disconnect()};e=new ln(i),e.observe(document,{characterData:!0,childList:!0,subtree:!0}),i()}else n(document)}),n)},"hide-if-matches-computed-xpath":function(e,t,n,o){const{mark:r,end:i}=mt("hide-if-matches-computed-xpath"),s=lt(arguments),a=yt("hide-if-matches-computed-xpath");if(!t||!e)return void a("error","No query or searchQuery provided.");const c=t=>{const n=(t=>e.replace("{{}}",t))(t);a("info","Starting hiding elements that match query: ",n);const o=tt(`xpath(${n})`),c=new hn,l=()=>{r(),o((e=>{if(c.has(e))return!1;c.add(e),d(),Le(e).nodeType===pn?et(e):Le(e).textContent="",a("success","Matched: ",e,"\nFILTER: hide-if-matches-computed-xpath",s)})),i()},u=new fn(l),d=Mt("hide-if-matches-computed-xpath",(()=>u.disconnect()));u.observe(document,{characterData:!0,childList:!0,subtree:!0}),l()},l=ct(n);Pt(a,(()=>{if(t){a("info","Started searching for: ",t);const e=new hn;let n;const o=tt(`xpath(${t})`),r=()=>{o((t=>{if(e.has(t))return!1;if(e.add(t),a("info","Found node: ",t),t.innerHTML){a("info","Searching in: ",t.innerHTML);const e=t.innerHTML.match(l);if(e&&e.length){let t="";t=e[1]?e[1]:e[0],a("info","Matched search query: ",t),c(t)}}}))};n=new fn(r),n.observe(document,{characterData:!0,childList:!0,subtree:!0}),r()}}),o)},"hide-if-contains":function(e,t="*",n=null){const o=lt(arguments),r=yt("hide-if-contains"),{mark:i,end:s}=mt("hide-if-contains");let a=ct(e);const c=nt((e=>a.test(Le(e).textContent)),t,n,(e=>{i(),r("success","Matched: ",e,"\nFILTER: hide-if-contains",o),s()}));c.race(Mt("hide-if-contains",(()=>{c.disconnect()})))},"hide-if-contains-similar-text":function(e,t,n=null,o=0,r=0){const i=new zt,s=lt(arguments),a=yt("hide-if-contains-similar-text"),{mark:c,end:l}=mt("hide-if-contains-similar-text"),u=Le(e),{length:d}=u,f=d+Bt(o)||0,h=Le([...u]).sort(),p=Bt(r)||1/0;null==n&&(n=t),a("info","Looking for similar text: "+u);const m=()=>{c();for(const{element:e,rootParents:r}of ze(n,!0)){if(i.has(e))continue;i.add(e);const{innerText:n}=Le(e),c=Xt(p,n.length-f+1);for(let i=0;i<c;i++){const c=Le(n).substr(i,f);if(Ut(h,Le([...c]).sort())-o<=0){const n=Je(Le(e),t,r);if(a("success","Found similar text: "+u,n,"\nFILTER: hide-if-contains-similar-text",s),n){w(),et(n);break}}}}l()};let g=new _t(m),w=Mt("hide-if-contains-similar-text",(()=>g.disconnect()));g.observe(document,{childList:!0,characterData:!0,subtree:!0}),m()},"hide-if-contains-visible-text":function(e,t,n=null,...o){const{mark:r,end:i}=mt("hide-if-contains-visible-text"),s=lt(arguments);let a=Le([]);const c=new Jt([["-snippet-box-margin","2"],["-disable-bg-color-check","false"],["-check-is-contained","false"],["-pseudo-box-margin","2"],["-ignore-padding","false"]]);for(let e of o){e=Le(e);let t=e.indexOf(":");if(t<0)continue;let n=e.slice(0,t).trim().toString(),o=e.slice(t+1).trim().toString();n&&o&&(c.has(n)?c.set(n,o):a.push([n,o]))}let l=Le([["opacity","0"],["font-size","0px"],["color","rgba(0, 0, 0, 0)"]]),u=new Jt(l.concat(a));function d(e,t,{bgColorCheck:n=!0,pseudoElemCheck:o=!1}={}){t||(t=Gt(e)),t=Le(t);for(const[e,n]of u){if(ct(n).test(t.getPropertyValue(e)))return!1}const r=t.getPropertyValue("color");if(n&&t.getPropertyValue("background-color")===r)return!1;if(!o){const t=Gt(e,"::first-line");if(t)return d(e,t,{bgColorCheck:n,pseudoElemCheck:!0})}const i=t.getPropertyValue("text-shadow");return!r.includes("rgba(0, 0, 0, 0)")||"none"!==i&&!i.includes("rgba(0, 0, 0, 0)")}function f(e,t=null){let n=Gt(e,t).transform;return"none"===n&&(n="matrix(1, 0, 0, 1, 0, 0)"),new Yt(n)}function h(e,t,n,{bgColorCheck:o=!0,translateThresh:r=2}={}){let i=Gt(e,t);if(!ot(e,i)||!d(e,i,{bgColorCheck:o}))return"";let{content:s}=Le(i);if(s&&"none"!==s){let o=Le([]);const i=f(e,t),a=n.multiply(i),c=Zt.atan2(a.b,a.a)*(180/Zt.PI);if(Zt.abs(c)>5)return"";return Zt.abs(a.e)>r||Zt.abs(a.f)>r?"":(s=Le(s).trim().replace(/(["'])(?:(?=(\\?))\2.)*?\1/g,(e=>""+(o.push(Le(e).slice(1,-1))-1))),s=s.replace(/\s*attr\(\s*([^\s,)]+)[^)]*?\)\s*/g,((t,n)=>Le(e).getAttribute(n)||"")),s.replace(/\x01(\d+)/g,((e,t)=>o[t])))}return""}function p(e,t,{boxMargin:n=2,ignorePadding:o=!1}={}){let r=Le(e).getBoundingClientRect();if(o){const t=Gt(e),n=Qt(t.paddingTop)||0,o=Qt(t.paddingRight)||0,i=Qt(t.paddingBottom)||0,s=Qt(t.paddingLeft)||0;r={left:r.left+s,right:r.right-o,top:r.top+n,bottom:r.bottom-i}}const i=Le(t).getBoundingClientRect(),s=i.left-n,a=i.right+n,c=i.top-n,l=i.bottom+n;return s<=r.left&&r.left<=a&&c<=r.top&&r.top<=l&&c<=r.bottom&&r.bottom<=l&&s<=r.right&&r.right<=a}function m(e,t,n,o,r,i,s,{boxMargin:a=2,bgColorCheck:c,checkIsContained:l,translateThresh:u}={}){let g=!n;if(g&&(n=Gt(e)),!ot(e,n,g&&t,i))return"";o||"hidden"!==Le(n).getPropertyValue("overflow-x")&&"hidden"!==Le(n).getPropertyValue("overflow-y")||(o=e);let w=h(e,":before",s=s?s.multiply(f(e)):f(e),{bgColorCheck:c,translateThresh:u});for(let t of function(e,t=!0){const n=_e(e,t);return n?n.childNodes:Le(e).childNodes}(Le(e)))switch(Le(t).nodeType){case en:w+=m(t,e,Gt(t),o,r,i,s,{boxMargin:a,bgColorCheck:c,checkIsContained:l,translateThresh:u});break;case tn:if(o)p(e,o,{boxMargin:a,ignorePadding:v})&&d(e,n,{bgColorCheck:c})&&(w+=Le(t).nodeValue);else if(d(e,n,{bgColorCheck:c})){if(l&&!p(e,r,{boxMargin:a,ignorePadding:v}))continue;w+=Le(t).nodeValue}}return w+=h(e,":after",s,{bgColorCheck:c,translateThresh:u}),w}const g=c.get("-snippet-box-margin"),w=Qt(g)||0,b=!("true"===c.get("-disable-bg-color-check")),y="true"===c.get("-check-is-contained"),v="true"===c.get("-ignore-padding"),k=c.get("-pseudo-box-margin"),x=Qt(k)||0;let S=ct(e),E=new Kt;const T=nt(((e,t,n)=>{if(r(),E.has(e))return!1;E.add(e);let o=m(e,t,null,null,e,n,null,{boxMargin:w,bgColorCheck:b,checkIsContained:y,translateThresh:x}),a=S.test(o);return Oe()&&o.length&&(a?bt("success",a,S,o,"\nFILTER: hide-if-contains-visible-text",s):bt("info",a,S,o)),i(),a}),t,n);T.race(Mt("hide-if-contains-visible-text",(()=>{T.disconnect()})))},"hide-if-contains-and-matches-style":function(e,t="*",n=null,o=null,r=null,i,s=null,a=null){const c=lt(arguments),l=yt("hide-if-contains-and-matches-style"),{mark:u,end:d}=mt("hide-if-contains-and-matches-style"),f=new Wt,h=Oe()&&new Wt;null==n&&(n=t);const p=ct(e),m=o?ct(o):null,g=r?ct(r):null;Pt(l,(()=>{const e=()=>{if(u(),!(s&&window.innerWidth<s||a&&window.innerWidth>a)){for(const{element:e,rootParents:o}of ze(n,!0))if(!f.has(e)&&p.test(Le(e).textContent))if(!g||g.test(rt(e))){const n=Je(Le(e),t,o);if(!n)continue;if(!m||m.test(rt(n)))r(),et(n),f.add(e),l("success","Matched: ",n,"which contains: ",e,"\nFILTER: hide-if-contains-and-matches-style",c);else{if(!h||h.has(n))continue;l("info","In this element the searchStyle matched but style didn't:\n",n,Rt(n),c),h.add(n)}}else{if(!h||h.has(e))continue;l("info","In this element the searchStyle didn't match:\n",e,Rt(e),c),h.add(e)}d()}},o=new Ot(e),r=Mt("hide-if-contains-and-matches-style",(()=>o.disconnect()));o.observe(document,{childList:!0,characterData:!0,subtree:!0}),e()}),i)},"hide-if-has-and-matches-style":function(e,t="*",n=null,o=null,r=null,i=null,s=null,a=null){const c=lt(arguments),l=yt("hide-if-has-and-matches-style"),{mark:u,end:d}=mt("hide-if-has-and-matches-style"),f=new on,h=Oe()&&new on;null==n&&(n=t);const p=o?ct(o):null,m=r?ct(r):null;Pt(l,(()=>{const o=()=>{if(u(),!(s&&window.innerWidth<s||a&&window.innerWidth>a)){for(const{element:o,rootParents:r}of ze(n,!0))if(!f.has(o))if(!Le(o).querySelector(e)||m&&!m.test(rt(o))){if(!h||h.has(o))continue;l("info","In this element the searchStyle didn't match:\n",o,rn(o),...arguments),h.add(o)}else{const e=Je(Le(o),t,r);if(!e||p&&!p.test(rt(e))){if(!h||h.has(e))continue;l("info","In this element the searchStyle matchedbut style didn't:\n",e,rn(e),...arguments),h.add(e)}else i(),et(e),f.add(o),l("success","Matched: ",e,"which contains: ",o,"\nFILTER: hide-if-has-and-matches-style",c)}d()}},r=new nn(o),i=Mt("hide-if-has-and-matches-style",(()=>r.disconnect()));r.observe(document,{childList:!0,subtree:!0}),o()}),i)},"hide-if-labelled-by":function(e,t,n=null){const{mark:o,end:r}=mt("hide-if-labelled-by");let i=null==n,s=ct(e),a=new cn,c=()=>{o();for(const{element:e,rootParents:o}of ze(t,!0)){let t=i?e:Je(Le(e),n,o);if(!t||!ot(e,sn(e),t))continue;let r=Le(e).getAttribute("aria-labelledby"),c=()=>{a.has(t)||s.test(Le(e).getAttribute("aria-label")||"")&&(u(),a.add(t),et(t))};if(r)for(let e of Le(r).split(/\s+/)){let n=Le(document).getElementById(e);n?!a.has(n)&&s.test(n.innerText)&&(u(),a.add(n),et(t)):c()}else c()}r()},l=new an(c),u=Mt("hide-if-labelled-by",(()=>l.disconnect()));l.observe(document,{characterData:!0,childList:!0,subtree:!0}),c()},"hide-if-contains-image":function(e,t,n){null==n&&(n=t);let o=ct(e);const r=lt(arguments),i=yt("hide-if-contains-image"),{mark:s,end:a}=mt("hide-if-contains-image");let c=()=>{s();for(const{element:e,rootParents:s}of ze(n,!0)){let n=Nt(e),a=Le(n["background-image"]).match(/^url\("(.*)"\)$/);a&&Ht(a[1]).then((n=>{if(o.test(new Vt(n).reduce(((e,t)=>e+function(e,t=2){let n=Le(e).toString(16);n.length<t&&(n=Le("0").repeat(t-n.length)+n);return n}(t)),""))){let n=Je(Le(e),t,s);n&&(u(),et(n),i("success","Matched: ",n,"\nFILTER: hide-if-contains-image",r))}}))}a()},l=new Ft(c),u=Mt("hide-if-contains-image",(()=>l.disconnect()));l.observe(document,{childList:!0,subtree:!0}),c()},"simulate-mouse-event":function(...e){const t=lt(arguments),n=yt("simulate-mouse-event"),{mark:o,end:r}=mt("simulate-mouse-event");if(e.length<1)throw new wn("[simulate-mouse-event snippet]: No selector provided.");e.length>7&&(e=e.slice(0,7));const i=Le([]);function s(){return i.forEach((e=>{if(!e.found){(function(e){let t=e;if(t.startsWith("xpath(")&&t.endsWith(")")){let t=tt(e);return()=>{let e=Le([]);return t((t=>e.push(t))),e}}return()=>Ae.from(ze(e))})(e.selector)().length>0&&(e.found=!0)}})),i.every((e=>e.found))}function a(e,o,r){e&&o&&("click"===o&&e.click?(e.click(),n("success","Clicked on this node:\n",e,"\nwith a delay of",r,"ms",`n\nFILTER: simulate-mouse-event ${t}`)):(e.dispatchEvent(new bn(o,{bubbles:!0,cancelable:!0})),n("success","A",o,"event was dispatched with a delay of",r,"ms on this node:\n",e,`n\nFILTER: simulate-mouse-event ${t}`)))}Le(e).forEach((e=>{const t=function(e){if(!e)return null;const t={selector:"",continue:!1,trigger:!1,event:"click",delay:"500",clicked:!1,found:!1},o=e.split("$");let r=[];o.length>=2&&(r=o[1].toLowerCase().split(",")),[t.selector]=o;for(const e of r)if("trigger"===e)t.trigger=!0;else if("continue"===e)t.continue=!0;else if(e.startsWith("event")){const n=e.toLowerCase().split("=");n[1]?t.event=n[1]:t.event="click"}else if(e.startsWith("delay")){const n=e.toLowerCase().split("=");n[1]?t.delay=n[1]:t.delay="500"}return kn.includes(t.event)||n("warn",t.event," might be misspelled, check for typos.\n","These are the supported events:",kn),t}(e);i.push(t)}));let c=!1;const[l]=i.slice(-1);l.trigger=!0;let u=new vn;function d(){if(o(),c||(c=s()),c)for(const e of i){const t=tt(e.selector),n=mn(e.delay,10);e.trigger&&t((t=>{u.has(t)||(u.add(t),e.continue?setInterval((()=>{i.forEach((e=>{e.found=!1,e.clicked=!1}));s()&&a(t,e.event,e.delay)}),n):gn((()=>{a(t,e.event,e.delay)}),n))}))}r()}new yn(d).observe(document,{childList:!0,subtree:!0}),d()},"skip-video":function(e,t,...n){const o=lt(arguments),r=new Map([["-max-attempts","10"],["-retry-ms","10"],["-run-once","false"],["-wait-until",""],["-skip-to","-0.1"],["-stop-on-video-end","false"],["-start-from","0"],["-mute-video-when-skipping","true"]]);for(let e of n){e=Le(e);let t=e.indexOf(":");if(t<0)continue;let n=e.slice(0,t).trim().toString(),o=e.slice(t+1).trim().toString();n&&o&&r.has(n)&&r.set(n,o)}const i=r.get("-max-attempts"),s=En(i||10,10),a=r.get("-retry-ms"),c=En(a||10,10),l="true"===r.get("-run-once"),u=r.get("-skip-to"),d=Tn(u||-.1),f=r.get("-start-from"),h=En(f||0,10),p=r.get("-wait-until"),m="true"===r.get("-stop-on-video-end"),g=!("false"===r.get("-mute-video-when-skipping")),w=yt("skip-video"),{mark:b,end:y}=mt("skip-video"),v=tt(`xpath(${t})`);let k=!1;Pt(w,(()=>{b();const n=new WeakSet,r=(u=0)=>{k&&l?i&&i.disconnect():v((i=>{let l,f=n.has(i);f||(w("info","Matched:",i," for selector: ",t),w("info","Running video skipping logic."));const p=ze(e);let b=!1;for(const e of p){if(!e||xn(e.duration)||xn(e.currentTime))continue;b=!0;const t=e.duration-e.currentTime<.5;!(e.duration>0&&e.currentTime<e.duration)||m&&t||(g&&(e.muted=!0,f||w("success","Muted video...")),h<=1e3*e.currentTime&&(d<=0?e.currentTime=e.duration+d:e.currentTime+=d,l!==e.duration&&(w("success","Skipped video, currentTime: ",e.currentTime,"s.","\nFILTER: skip-video",o),n.add(i),l=e.duration),e.paused&&e.play(),k=!0,a()))}!b&&u<s&&Mn((()=>{const e=u+1;w("info","Running video skipping logic. Attempt: ",e),r(e)}),c)}))},i=new Sn(r),a=Mt("skip-video",(()=>i.disconnect()));i.observe(document,{characterData:!0,childList:!0,subtree:!0}),r(),y()}),p)}};
const snippets=Cn;
let context;
for (const [name, ...args] of filters) {
if (snippets.hasOwnProperty(name)) {
try { context = snippets[name].apply(context, args); }
catch (error) { console.error(error); }
}
}
context = void 0;
};
const graph = new Map([["log",null],["race",null],["debug",null],["profile",null],["hide-if-matches-xpath",null],["hide-if-matches-computed-xpath",null],["hide-if-contains",null],["hide-if-contains-similar-text",null],["hide-if-contains-visible-text",null],["hide-if-contains-and-matches-style",null],["hide-if-has-and-matches-style",null],["hide-if-labelled-by",null],["hide-if-contains-image",null],["simulate-mouse-event",null],["skip-video",null]]);
callback.get = snippet => graph.get(snippet);
callback.has = snippet => graph.has(snippet);
export default callback;