-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontentScript.bundle.js
More file actions
1 lines (1 loc) · 16.2 KB
/
Copy pathcontentScript.bundle.js
File metadata and controls
1 lines (1 loc) · 16.2 KB
1
(()=>{"use strict";let e,t;function n(n,r){if(n.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===n.tagName.toLowerCase())return"html";const i={root:document.body,idName:e=>!0,className:e=>!0,tagName:e=>!0,attr:(e,t)=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};e={...i,...r},t=function(e,t){if(e.nodeType===Node.DOCUMENT_NODE)return e;if(e===t.root)return e.ownerDocument;return e}(e.root,i);let s=o(n,"all",(()=>o(n,"two",(()=>o(n,"one",(()=>o(n,"none")))))));if(s){const e=w(v(s,n));return e.length>0&&(s=e[0]),l(s)}throw new Error("Selector was not found.")}function o(t,n,o){let l=null,i=[],s=t,g=0;for(;s;){let t=p(a(s))||p(...c(s))||p(...u(s))||p(f(s))||[{name:"*",penalty:3}];const y=d(s);if("all"==n)y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("two"==n)t=t.slice(0,1),y&&(t=t.concat(t.filter(h).map((e=>m(e,y)))));else if("one"==n){const[e]=t=t.slice(0,1);y&&h(e)&&(t=[m(e,y)])}else"none"==n&&(t=[{name:"*",penalty:3}],y&&(t=[m(t[0],y)]));for(let e of t)e.level=g;if(i.push(t),i.length>=e.seedMinLength&&(l=r(i,o),l))break;s=s.parentElement,g++}return l||(l=r(i,o)),!l&&o?o():l}function r(t,n){const o=w(y(t));if(o.length>e.threshold)return n?n():null;for(let e of o)if(s(e))return e;return null}function l(e){let t=e[0],n=t.name;for(let o=1;o<e.length;o++){const r=e[o].level||0;n=t.level===r-1?`${e[o].name} > ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function i(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function s(e){const n=l(e);switch(t.querySelectorAll(n).length){case 0:throw new Error(`Can't select any node with this selector: ${n}`);case 1:return!0;default:return!1}}function a(t){const n=t.getAttribute("id");return n&&e.idName(n)?{name:"#"+CSS.escape(n),penalty:0}:null}function c(t){const n=Array.from(t.attributes).filter((t=>e.attr(t.name,t.value)));return n.map((e=>({name:`[${CSS.escape(e.name)}="${CSS.escape(e.value)}"]`,penalty:.5})))}function u(t){return Array.from(t.classList).filter(e.className).map((e=>({name:"."+CSS.escape(e),penalty:1})))}function f(t){const n=t.tagName.toLowerCase();return e.tagName(n)?{name:n,penalty:2}:null}function d(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function m(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function h(e){return"html"!==e.name&&!e.name.startsWith("#")}function p(...e){const t=e.filter(g);return t.length>0?t:null}function g(e){return null!=e}function*y(e,t=[]){if(e.length>0)for(let n of e[0])yield*y(e.slice(1,e.length),t.concat(n));else yield t}function w(e){return[...e].sort(((e,t)=>i(e)-i(t)))}function*v(t,n,o={counter:0,visited:new Map}){if(t.length>2&&t.length>e.optimizedMinLength)for(let r=1;r<t.length-1;r++){if(o.counter>e.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(r,1);const a=l(i);if(o.visited.has(a))return;s(i)&&b(i,n)&&(yield i,o.visited.set(a,!0),yield*v(i,n,o))}}function b(e,n){return t.querySelector(l(e))===n}function N(e,t){let n="",o=null,r=!1;try{if(o=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!o)return null;n=`${o}`,e.getAttribute("id")&&(n=`${n}#${CSS.escape(e.getAttribute("id"))}`,r=!0);const t=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(t.map((e=>`[${e}]`)).join(",")))for(const o of t){const t=e.getAttribute(o);if(t){n=`${n}[${o}="${CSS.escape(t)}"]`;break}}if(["input","button","textarea","select","option"].includes(o)){e.getAttribute("type")&&(n=`${n}[type="${CSS.escape(e.getAttribute("type"))}"]`),e.getAttribute("name")&&(n=`${n}[name="${CSS.escape(e.getAttribute("name"))}"]`);const t=e.closest("form");if(t){let e="form";t.getAttribute("id")&&(e=`${e}#${CSS.escape(t.getAttribute("id"))}`),n=`${e} ${n}`}}const l=e.getAttribute("aria-label");if(l&&!r&&(n=`${n}[aria-label="${CSS.escape(l)}"]`),n){const t=e.closest("body");if(t)try{1!==t.querySelectorAll(n).length&&(n="")}catch(e){n=""}}}catch(e){}return n}function E(e,t){let n,o=e,r=[];for(;o;){let e=0,n=o.previousElementSibling;for(;n;)n.nodeName===o.nodeName&&e++,n=n.previousElementSibling;let l=o.nodeName.toLowerCase();e>0&&(l=l+"["+(e+1)+"]"),o!==t&&r.unshift(l),o=o.parentNode}if(n="/"+r.join("/"),function(e,t){const n=t.evaluate(e,t,null,XPathResult.ANY_TYPE,null),o=n.iterateNext();return o}(n,t)===e)return n}const S={},C={keydown:null,return:null,blur:null,change:null,click:null,dblclick:null,contextmenu:null,focus:null,mouseover:null,mouseout:null};let k=!1,A=null,L=null;const $=new WeakMap;function x(e){const t=e.value;return t&&t.trim()?t:$.get(e)||t}function T(e){const t=e.value;return!(t&&t.trim())&&$.has(e)}function M(e,t){const n=["focus","highlight","editable","caret"],o=Array.from(e.classList||[]).filter((e=>{const t=e.toLowerCase();return!n.some((e=>t.includes(e)))&&!/^[0-9]/.test(e)}));for(const n of o){const o="."+n;try{const n=t.querySelectorAll(o);if(1===n.length&&n[0]===e)return o}catch(e){}}return null}function O(e,t){let n;var o;let r,l;function i(e,t,o){let l=null;const i=[];let a=e,c=0;for(;a&&a!==r.root.parentElement;){let e=w(f(a))||w(...d(a))||w(...m(a))||w(h(a))||[{name:"*",penalty:3}];const u=p(a);if(t===n.All)u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.Two)e=e.slice(0,1),u&&(e=e.concat(e.filter(y).map((e=>g(e,u)))));else if(t===n.One){const[t]=e=e.slice(0,1);u&&y(t)&&(e=[g(t,u)])}for(const t of e)t.level=c;if(i.push(e),i.length>=r.seedMinLength&&(l=s(i,o),l))break;a=a.parentElement,c++}return l||(l=s(i,o)),l}function s(e,t){const n=N(b(e));if(n.length>r.threshold)return t?t():null;for(const e of n)if(u(e))return e;return null}function a(e){let t=e[0],n=t.name;for(let o=1;o<e.length;o++){const r=e[o].level||0;n=t.level===r-1?`${e[o].name} > ${n}`:`${e[o].name} ${n}`,t=e[o]}return n}function c(e){return e.map((e=>e.penalty)).reduce(((e,t)=>e+t),0)}function u(e){switch(l.querySelectorAll(a(e)).length){case 0:throw new Error(`Can't select any node with this selector: ${a(e)}`);case 1:return!0;default:return!1}}function f(e){const t=e.getAttribute("id");return t&&r.idName(t)?{name:`#${L(t,{isIdentifier:!0})}`,penalty:0}:null}function d(e){return Array.from(e.attributes).filter((e=>r.attr(e.name,e.value))).map((e=>({name:"["+L(e.name,{isIdentifier:!0})+'="'+L(e.value)+'"]',penalty:.5})))}function m(e){return Array.from(e.classList).filter(r.className).map((e=>({name:"."+L(e,{isIdentifier:!0}),penalty:1})))}function h(e){const t=e.tagName.toLowerCase();return r.tagName(t)?{name:t,penalty:2}:null}function p(e){const t=e.parentNode;if(!t)return null;let n=t.firstChild;if(!n)return null;let o=0;for(;n&&(n.nodeType===Node.ELEMENT_NODE&&o++,n!==e);)n=n.nextSibling;return o}function g(e,t){return{name:e.name+`:nth-child(${t})`,penalty:e.penalty+1}}function y(e){return"html"!==e.name&&!e.name.startsWith("#")}function w(...e){const t=e.filter(v);return 0<t.length?t:null}function v(e){return null!=e}function*b(e,t=[]){if(0<e.length)for(const n of e[0])yield*b(e.slice(1,e.length),t.concat(n));else yield t}function N(e){return Array.from(e).sort(((e,t)=>c(e)-c(t)))}function E(e,t){return l.querySelector(a(e))===t}(o=n||(n={}))[o.All=0]="All",o[o.Two=1]="Two",o[o.One=2]="One";const S=/[ -,\.\/:-@\[-\^`\{-~]/,C=/[ -,\.\/:-@\[\]\^`\{-~]/,k=/(^|\\+)?(\\[A-F0-9]{1,6})\x20(?![a-fA-F0-9\x20])/g,A={escapeEverything:!1,isIdentifier:!1,quotes:"single",wrap:!1};function L(e,t={}){const n=Object.assign(Object.assign({},A),t);"single"!==n.quotes&&"double"!==n.quotes&&(n.quotes="single");const o="double"==n.quotes?'"':"'",r=n.isIdentifier,l=e.charAt(0);let i="",s=0;for(const t=e.length;s<t;){const l=e.charAt(s++);let a,c=l.charCodeAt(0);if(32>c||126<c){if(55296<=c&&56319>=c&&s<t){const t=e.charCodeAt(s++);56320==(64512&t)?c=((1023&c)<<10)+(1023&t)+65536:s--}a="\\"+c.toString(16).toUpperCase()+" "}else a=n.escapeEverything?S.test(l)?"\\"+l:"\\"+c.toString(16).toUpperCase()+" ":/[\t\n\f\r\x0B]/.test(l)?"\\"+c.toString(16).toUpperCase()+" ":"\\"==l||!r&&('"'==l&&o==l||"'"==l&&o==l)||r&&C.test(l)?"\\"+l:l;i+=a}return r&&(/^-[-\d]/.test(i)?i="\\-"+i.slice(1):/\d/.test(l)&&(i="\\3"+l+" "+i.slice(1))),i=i.replace(k,(function(e,t,n){return t&&t.length%2?e:(t||"")+n})),!r&&n.wrap?o+i+o:i}if(e.nodeType!==Node.ELEMENT_NODE)throw new Error("Can't generate CSS selector for non-element node type.");if("html"===e.tagName.toLowerCase())return"html";const $={root:document.body,idName:()=>!0,className:()=>!0,tagName:()=>!0,attr:()=>!1,seedMinLength:1,optimizedMinLength:2,threshold:1e3,maxNumberOfTries:1e4};r=Object.assign(Object.assign({},$),t),l=function(e,t){return e.nodeType===Node.DOCUMENT_NODE?e:e===t.root?e.ownerDocument:e}(r.root,$);let x=i(e,n.All,(()=>i(e,n.Two,(()=>i(e,n.One)))));if(x){const t=N(function*e(t,n,o={counter:0,visited:new Map}){if(2<t.length&&t.length>r.optimizedMinLength)for(let l=1;l<t.length-1;l++){if(o.counter>r.maxNumberOfTries)return;o.counter+=1;const i=[...t];i.splice(l,1);const s=a(i);if(o.visited.has(s))return;u(i)&&E(i,n)&&(yield i,o.visited.set(s,!0),yield*e(i,n,o))}}(x,e));return 0<t.length&&(x=t[0]),a(x)}throw new Error("Selector was not found.")}!function(){let e=document.title,t=!1,o=!1,r=!1;chrome&&chrome.storage.sync.get(["isRecording"],(l=>{if(!l.isRecording)return;let i=!1,s=null;function a(e){e&&"mouseover"===e.type&&!i||function(e,t,o,r){let l=!1,i=null,s=null;e&&e.composed&&e.composedPath&&(s=e.composedPath());let a=-1;s&&s.length>0&&(a=s.findIndex((e=>e instanceof ShadowRoot))),i=a>-1?s[0]:e.target;const c=e.type;let u=null,f=null;if(!i||!i.getAttribute)return;u=i.nodeName.toLowerCase(),f=i.getAttribute("type");let d=null,m=null;try{m=function(e){let t=null;try{if(t=e.nodeName&&"string"==typeof e.nodeName?e.nodeName.toLowerCase():null,!t)return e;if(["input","button","a","textarea","select","option","progress"].includes(t))return e;const n=e.closest("button,a");if(n)return n;const o=e.closest("svg");o&&(e=o);const r=["data-test-id","data-testid","data-test","data-cy"];if(e.matches(r.map((e=>`[${e}]`)).join(",")))return e;if(e.parentNode.matches(r.map((e=>`[${e}]`)).join(",")))return e.parentNode}catch(e){}return e}(i),d=N(m)}catch(e){}if(!d)try{d=n(m,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(d&&"html"===d.toLowerCase())return;let h=null;try{h=E(m,t)}catch(e){}a>-1&&(h="/html/node/shadow");let p={timestamp:(new Date).getTime(),css:d||i,xpath:h||""},g={};if("click"===c){if(C.click=i,A&&A.element!==i&&r){const e=T(A.element),n={...A.oEventBase,type:e?"bfill_value":"fill_value",value:x(A.element),frame:A.frame};if(e){const e=M(A.element,t);e&&(n.css=e)}r({messageType:"events",event:{...n}}),$.delete(A.element),L=A.element,A=null}if(!(C.return!==C.change||i===C.return||"input"!==u&&"button"!==u||"submit"!==f&&"image"!==f||null===C.return))return;if("input"===u&&("checkbox"===f||"radio"===f))return;const l=i.closest&&i.closest("label");if(l){const e=i.closest("a, button, input, select, textarea");if(!e||!l.contains(e)){const e=l.getAttribute("for");if(e){const t=i.getRootNode(),n=(t&&t.getElementById?t:document).getElementById(e);if(n&&"input"===n.nodeName.toLowerCase()&&("checkbox"===n.type||"radio"===n.type))return}if(l.querySelector('input[type="checkbox"], input[type="radio"]'))return}}let c="click";if(function(e){if("canvas"===e.nodeName.toLowerCase())return!0;if(e.shadowRoot)try{if(e.shadowRoot.querySelector("canvas"))return!0}catch(e){}for(const t of e.children||[])if(t.shadowRoot)try{if(t.shadowRoot.querySelector("canvas"))return!0}catch(e){}return!1}(i)){const t=i.getBoundingClientRect(),n={x:e.clientX-t.left,y:e.clientY-t.top,width:t.width,height:t.height};p={...p,coords:n},c="bclick"}if(g={...p,type:c,value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},"bclick"===c&&a>-1&&s){const e=s[a].host;if(e){let o=null;try{o=N(e)}catch(e){}if(!o)try{o=n(e,{root:t,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}o&&(g.shadow_host_css=o)}}}else if("dblclick"===c)C.dblclick=i,g={...p,type:"dblclick",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("contextmenu"===c)C.contextmenu=i,g={...p,type:"contextmenu",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o};else if("focus"===c);else if("mouseover"===c)k&&(clearTimeout(k),k=!1),k=setTimeout((()=>{k=!1,C.mouseover=i,g={...p,type:"mouseover",value:(i.value||i.textContent||"").trim().substr(0,20).replace(/\n/gi,""),frame:o},g&&g.type&&r&&r({messageType:"events",event:{...g}})}),500);else if("mouseout"===c);else if("keydown"===c){if(C.keydown=i,["input","textarea"].indexOf(u)>-1)if(S[i]=i.value,A={element:i,oEventBase:{...p},frame:o},e.key&&1===e.key.length){const t=$.get(i)||"";$.set(i,t+e.key)}else if("Backspace"===e.key){const e=$.get(i)||"";e.length>0&&$.set(i,e.slice(0,-1))}if("input"===u&&13===e.keyCode){l=!0,C.return=i;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("blur"===c){if(C.blur=i,i===L)return void(L=null);if(A&&A.element===i&&(A=null),["input","textarea"].indexOf(u)>-1){if(S[i]=i.value,i===C.return)return void(C.return=null);if("input"===u&&("submit"===i.type||"button"===i.type||"image"===i.type))return;const e=T(i);if(g={...p,type:e?"bfill_value":"fill_value",value:x(i),frame:o},e){const e=M(i,t);e&&(g.css=e)}$.delete(i)}}else if("change"===c)if(C.change=i,"input"===u)"checkbox"!==f&&"radio"!==f||(g={...p,type:"change",subtype:"check",checked:i.checked,frame:o});else if("select"===u)if(i.multiple){const e=[];for(let t=0;t<i.options.length;t++)e.push(!!i.options[t].selected);g={...p,type:"change",subtype:"select_multi",selected:[].concat(e),value:i.value,frame:o}}else{const e=i.selectedIndex;g={...p,type:"change",subtype:"select",selected:e,value:i.value,frame:o}}if(g&&g.type&&r&&r({messageType:"events",event:{...g}}),l&&r){const e={...p,timestamp:(new Date).getTime(),type:"press_key",value:13,frame:o};r({messageType:"events",event:{...e}})}}(e,window.document,null,(e=>{window!==window.top?window.parent.postMessage({source:"event-from-iframe",obj:{...e},framePath:[]},"*"):chrome.runtime.sendMessage(e)}))}window===window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o={...e.data.obj},r=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let e=null;try{e=N(n)}catch(e){}if(!e)try{e=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}if(e&&o.event){const t=[e,...r];o.event.frame=t.join(" >>> "),chrome.runtime.sendMessage(o)}break}}})),window!==window.top&&window.addEventListener("message",(e=>{if(e.data&&e.data.source&&"event-from-iframe"===e.data.source){const t=document.querySelectorAll("iframe, frame");let n=!1;for(const o of t)if(o.contentWindow===e.source){n=!0;break}if(!n)return;const o=e.data.framePath||[];for(const n of t)if(n.contentWindow===e.source){let t=null;try{t=N(n)}catch(e){}if(!t)try{t=O(n,{root:window.document,idName:e=>!/^[0-9]+.*/i.test(e),className:e=>!e.includes("focus")&&!e.includes("highlight")&&!/^[0-9]+.*/i.test(e)})}catch(e){}t&&o.push(t),window.parent.postMessage({source:"event-from-iframe",obj:e.data.obj,framePath:o},"*");break}}})),l.isRecording&&(t=!0,e=document.title,function(){if(!t)return document.title=`${e}`,r=!1,void(o&&(clearInterval(o),o=!1));o=setInterval((()=>{r?(document.title=`${e}`,r=!1):(document.title=`🔴 ${e}`,r=!0)}),1e3)}(),window===window.top&&chrome.runtime.sendMessage({messageType:"events",event:{type:"goto",timestamp:(new Date).getTime(),windowWidth:window.innerWidth,windowHeight:window.innerHeight,url:window.location.href}}),document.addEventListener("click",a,!0),document.addEventListener("mouseover",a,!0),document.addEventListener("dblclick",a,!0),document.addEventListener("contextmenu",a,!0),document.addEventListener("keydown",a,!0),document.addEventListener("blur",a,!0),document.addEventListener("change",a,!0));const c={attributes:!1,childList:!0,subtree:!0},u=new MutationObserver((async(e,t)=>{i=!0,s&&(clearTimeout(s),s=null),s=setTimeout((()=>{i=!1}),200)}));document.body&&u.observe(document.body,c)}))}()})();