mirror of
https://github.com/webrecorder/browsertrix-crawler.git
synced 2025-10-19 14:33:17 +00:00
1 line
44 KiB
JavaScript
1 line
44 KiB
JavaScript
![]() |
/*! behaviors.js is part of Webrecorder project. Copyright (C) 2021-2024, Webrecorder Software. Licensed under the Affero General Public License v3. */(()=>{var t={480:(t,e,i)=>{"use strict";function o(t,e=document,i=null){return s(t,!0,e,i)}function s(t,e,i,o=null){t=function(t){function e(){o&&(a.length>0&&/^[~+>]$/.test(a[a.length-1])&&a.push(" "),a.push(o))}var i,o,s,n,a=[],r=[0],l=0,c=/(?:[^\\]|(?:^|[^\\])(?:\\\\)+)$/,h=/^\s+$/,d=[/\s+|\/\*|["'>~+[(]/g,/\s+|\/\*|["'[\]()]/g,/\s+|\/\*|["'[\]()]/g,null,/\*\//g];for(t=t.trim();;){if(o="",(s=d[r[r.length-1]]).lastIndex=l,!(i=s.exec(t))){o=t.substr(l),e();break}if((n=l)<(l=s.lastIndex)-i[0].length&&(o=t.substring(n,l-i[0].length)),r[r.length-1]<3){if(e(),"["===i[0])r.push(1);else if("("===i[0])r.push(2);else if(/^["']$/.test(i[0]))r.push(3),d[3]=new RegExp(i[0],"g");else if("/*"===i[0])r.push(4);else if(/^[\])]$/.test(i[0])&&r.length>0)r.pop();else if(/^(?:\s+|[~+>])$/.test(i[0])&&(a.length>0&&!h.test(a[a.length-1])&&0===r[r.length-1]&&a.push(" "),1===r[r.length-1]&&5===a.length&&"="===a[2].charAt(a[2].length-1)&&(a[4]=" "+a[4]),h.test(i[0])))continue;a.push(i[0])}else a[a.length-1]+=o,c.test(a[a.length-1])&&(4===r[r.length-1]&&(a.length<2||h.test(a[a.length-2])?a.pop():a[a.length-1]=" ",i[0]=""),r.pop()),a[a.length-1]+=i[0]}return a.join("").trim()}(t);let s=i.querySelector(t);if(document.head.createShadowRoot||document.head.attachShadow){if(!e&&s)return s;return n(t,",").reduce(((t,s)=>{if(!e&&t)return t;const l=n(s.replace(/^\s+/g,"").replace(/\s*([>+~]+)\s*/g,"$1")," ").filter((t=>!!t)).map((t=>n(t,">"))),c=l.length-1,h=function(t=null,e,i=null){let o=[];if(i)o=i;else{const t=function(e){for(let i=0;i<e.length;i++){const s=e[i];o.push(s),s.shadowRoot&&t(s.shadowRoot.querySelectorAll("*"))}};e.shadowRoot&&t(e.shadowRoot.querySelectorAll("*")),t(e.querySelectorAll("*"))}return t?o.filter((e=>e.matches(t))):o}(l[c][l[c].length-1],i,o),d=function(t,e,i){return o=>{let s=e,n=o,l=!1;for(;n&&!a(n);){let e=!0;if(1===t[s].length)e=n.matches(t[s]);else{const o=[].concat(t[s]).reverse();let a=n;for(const t of o){if(!a||!a.matches(t)){e=!1;break}a=r(a,i)}}if(e&&0===s){l=!0;break}e&&s--,n=r(n,i)}return l}}(l,c,i);return e?t=t.concat(h.filter(d)):(t=h.find(d))||null}),e?[]:null)}return e?i.querySelectorAll(t):s}function n(t,e){return t.match(/\\?.|^$/g).reduce(((t,i)=>('"'!==i||t.sQuote?"'"!==i||t.quote?t.quote||t.sQuote||i!==e?t.a[t.a.length-1]+=i:t.a.push(""):(t.sQuote^=1,t.a[t.a.length-1]+=i):(t.quote^=1,t.a[t.a.length-1]+=i),t)),{a:[""]}).a}function a(t){return t.nodeType===Node.DOCUMENT_FRAGMENT_NODE||t.nodeType===Node.DOCUMENT_NODE}function r(t,e){const i=t.parentNode;return i&&i.host&&11===i.nodeType?i.host:i===e?null:i}i.d(e,{Jp:()=>o})},702:(t,e,i)=>{"use strict";i.r(e),i.d(e,{AutoClick:()=>n});var o=i(841),s=i(721);class n extends o.BackgroundBehavior{constructor(t="a"){super(),this.seenElem=new WeakSet,this.selector=t,this._donePromise=new Promise((t=>this._markDone=t))}beforeUnload(t){return t.preventDefault(),!1}nextSameOriginLink(t){try{const e=document.querySelectorAll(this.selector);for(const i of e){const e=i;if(e.href&&e.href.startsWith(self.location.origin)&&!e.href.startsWith(t)&&(e.isConnected&&!this.seenElem.has(e)))return this.seenElem.add(e),e}}catch(t){this.debug(t.toString())}return null}async start(){const t=self.location.href,e=new URL(t);e.hash="";const i=e.href+"#";for(window.addEventListener("beforeunload",(t=>this.beforeUnload(t)));;){const e=this.nextSameOriginLink(i);if(!e)break;await this.processElem(e,t)}for(const e of document.querySelectorAll(this.selector)){const o=e;o.href&&!o.href.startsWith(i)||await this.processElem(o,t)}window.removeEventListener("beforeunload",(t=>this.beforeUnload(t))),this._markDone()}async processElem(t,e){if(!t.isConnected)return;try{if(!getEventListeners(t).click)return}catch(t){}const i=self;if(t.href){if(i.__bx_addSet&&!await i.__bx_addSet(t.href))return;this.debug("Clicking on link: "+t.href)}else this.debug("Click empty link");t.click(),await(0,s.sleep)(250),self.location.href!=e&&await new Promise((t=>{window
|