-
Notifications
You must be signed in to change notification settings - Fork 0
/
in_page.js
1 lines (1 loc) · 10.1 KB
/
in_page.js
1
!function e(t,n,r){function o(s,a){if(!n[s]){if(!t[s]){var c="function"==typeof require&&require;if(!a&&c)return c(s,!0);if(i)return i(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var d=n[s]={exports:{}};t[s][0].call(d.exports,(function(e){return o(t[s][1][e]||e)}),d,d.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t,n){(function(t){(function(){const n=e("./user_input");let r,o,i;function s(e){let t="";return e.forEach((e=>{t+=` ${e.innerText}`})),[{innerText:t}]}const a=t.env.PAGE_SCAN_INT||5e3;window.onload=function(){console.log("[LS Alert] in_page loaded"),r=document.createElement("a"),r.href=window.location.href,new n(r),console.log("[InitUserInput] scanning ->",r.hostname),function(){if(window.location.hostname.match(/google|bing(\.\w{2,5}){1,2}$/i)&&window.location.search&&""!==window.location.search){let e=window.location.search.replace(/^\?/,"").match(/q=([^&]+)(&|$)/i);e&&e[1]&&(e=e[1],e=decodeURIComponent(e.replace(/\+/g," ")),chrome.runtime.sendMessage({action:"intent",url:window.location.href,text:e}))}}(),function(){if(r.href.match(/docs\.google\.com\/(document|spreadsheets|presentation)/)){console.log("[InitGoogleDocs] scanning ->",r.href);let e="";const t=document.querySelector("meta[property='og:title']");t&&(e+=t.getAttribute("content"));const n=document.querySelector("meta[property='og:description']");n&&(e+=" "+n.getAttribute("content")),chrome.runtime.sendMessage({action:"scan",url:window.location.href,text:e});const o=document.createElement("input");o.id="alertText",o.type="hidden",document.body.appendChild(o);const s=document.createElement("script");s.innerHTML="\n // LS Alert\n const open = window.XMLHttpRequest.prototype.open;\n const send = window.XMLHttpRequest.prototype.send;\n function openReplacement(method, url, async, user, password) { \n this._url = url;\n return open.apply(this, arguments);\n }\n function sendReplacement(data) { \n if (this._url.includes('assistwriting')) {\n document.getElementById('alertText').value = decodeURIComponent(data);\n }\n return send.apply(this, arguments);\n }\n window.XMLHttpRequest.prototype.open = openReplacement; \n window.XMLHttpRequest.prototype.send = sendReplacement;\n ",document.head.appendChild(s),setInterval((()=>{const e=document.getElementById("alertText").value;if(""!==e&&i!==e){i=e;const t=JSON.parse(e);Array.isArray(t)&&Array.isArray(t[0])&&(console.log("[InitGoogleDocs] change ->",t[0][0]),chrome.runtime.sendMessage({action:"scan",url:window.location.href,text:t[0][0]}))}}),1e3)}}(),setInterval((()=>{let e;if(r.href.match(/(officeapps|onedrive)\.live\.com/)&&(e=s([...document.querySelectorAll(".SlideContent,.Section,.PageConentContainer")]),""===e[0].innerText&&(e=s([...document.getElementsByClassName("NormalTextRun")]))),r.href.match(/docs\.google\.com\/document/)&&(e=document.getElementsByClassName("kix-appview-editor-container")),r.href.match(/docs\.google\.com\/presentation/)&&(e=[document.getElementById("workspace-container")]),e&&e[0]){const t=e[0].innerText;""!==t&&t!==o&&chrome.runtime.sendMessage({action:"scan",url:window.location.href,text:t}),o=t}}),a)}}).call(this)}).call(this,e("_process"))},{"./user_input":2,_process:10}],2:[function(e,t,n){const r=["change","keyup"],o=e("./modules/facebook"),i=e("./modules/twitter"),s=e("./modules/gmail"),a=e("./modules/youtube"),c=e("./modules/tiktok"),u=e("./modules/tumblr"),d=e("./modules/sheets");t.exports=class{constructor(e){if(void 0===e)throw new Error("url object required");this.UrlObject=e,this.lastBodyText="",this.modules=[];const t=new o(e);t.disabled||this.modules.push(t);const n=new i(e);n.disabled||this.modules.push(n);const r=new s(e);r.disabled||this.modules.push(r);const l=new a(e);l.disabled||this.modules.push(l);const h=new c(e);h.disabled||this.modules.push(h);const m=new u(e);m.disabled||this.modules.push(m);const f=new d(e);f.disabled||this.modules.push(f),this.BindToDOM()}DOMExtractAndScan(e){if(void 0===e.target)throw new Error("event has no target");let t,n;if("scan"===e.type)n="GatherIntent";else n=e.target.tagName.toLowerCase();switch(n){case"input":let n=e.target.type||"text";if(n=n.toLowerCase(),"password"===n)break;t=[e.target.value];break;case"textarea":t=[e.target.value];break;case"div":if(e.target.attributes&&e.target.attributes.role&&"textbox"===e.target.attributes.role.value){t=[e.target.innerText];break}default:t=[],this.modules.forEach((e=>{if("function"==typeof e.GatherIntent){const n=e.GatherIntent();"string"==typeof n?t.push(n):Array.isArray(n)&&(t=t.concat(n))}}))}void 0!==t&&t.forEach((t=>{let n;n=void 0!==e.target&&e.target?e.target:document,""===t?n.RelayFlaggedTerms={}:(void 0===n.RelayFlaggedTerms&&(n.RelayFlaggedTerms={}),void 0===n.RelayFlaggedTerms[t]&&(chrome.runtime.sendMessage({action:"intent",url:window.location.href,text:t}),n.RelayFlaggedTerms[t]=!0))}))}HandleDOM_change(e){if(void 0===e)throw new Error("event required");if("change"!==e.type)throw new Error("event must be a change event");if(void 0===e.target)throw new Error("event has no target");void 0!==e.target.tagName&&this.DOMExtractAndScan(e)}HandleDOM_keyup(e){if(void 0===e)throw new Error("event required");if("keyup"!==e.type)throw new Error("event must be a keyup event");if(void 0===e.target)throw new Error("event has no target");void 0!==e.target.tagName&&this.DOMExtractAndScan(e)}HandleDOM(e){if(void 0===e)throw new Error("event required");if(-1===r.indexOf(e.type))throw new Error(`unsupported event type - ${e.type}`);"function"==typeof this[`HandleDOM_${e.type}`]&&this[`HandleDOM_${e.type}`](e)}BindToDOM(){document.addEventListener("change",this.HandleDOM.bind(this)),document.addEventListener("keyup",this.HandleDOM.bind(this)),setInterval((()=>{this.DOMExtractAndScan(new Event("scan"))}),1e3)}}},{"./modules/facebook":3,"./modules/gmail":4,"./modules/sheets":5,"./modules/tiktok":6,"./modules/tumblr":7,"./modules/twitter":8,"./modules/youtube":9}],3:[function(e,t,n){t.exports=class{constructor(e){if(void 0===e)throw new Error("URL Object required");this.disabled=!0,this.moduleName="facebook",e.hostname.match(/\.?facebook\.com$/i)&&(this.disabled=!1)}GatherIntent(){if(this.disabled)return;const e=[];return document.querySelectorAll('[data-text="true"]').forEach((t=>{e.push(t.innerText)})),e}}},{}],4:[function(e,t,n){t.exports=class{constructor(e){if(void 0===e)throw new Error("URL Object required");this.disabled=!0,this.moduleName="gmail",e.hostname.match(/mail\.google\.com$/i)&&(this.disabled=!1)}GatherIntent(){if(this.disabled)return;const e=[];return document.querySelectorAll('[role="textbox"]').forEach((t=>{e.push(t.innerText)})),e}}},{}],5:[function(e,t,n){t.exports=class{constructor(e){if(void 0===e)throw new Error("URL Object required");this.disabled=!0,this.moduleName="sheets",e.href.match(/docs\.google\.com\/spreadsheets/i)&&(this.disabled=!1)}GatherIntent(){if(this.disabled)return;const e=[],t=document.getElementById("waffle-rich-text-editor");return t&&e.push(t.innerText),e}}},{}],6:[function(e,t,n){t.exports=class{constructor(e){if(void 0===e)throw new Error("URL Object required");this.disabled=!0,this.moduleName="tiktok",e.hostname.match(/\.?tiktok\.com$/i)&&(this.disabled=!1)}GatherIntent(){if(this.disabled)return;const e=[];return document.querySelectorAll('[role="combobox"]').forEach((t=>{e.push(t.innerText)})),e}}},{}],7:[function(e,t,n){t.exports=class{constructor(e){if(void 0===e)throw new Error("URL Object required");this.disabled=!0,this.moduleName="tumblr",e.hostname.match(/\.?tumblr\.com$/i)&&(this.disabled=!1)}GatherIntent(){if(this.disabled)return;const e=[];return document.querySelectorAll(".editor-richtext,.editor-plaintext").forEach((t=>{e.push(t.innerText)})),e}}},{}],8:[function(e,t,n){t.exports=class{constructor(e){if(void 0===e)throw new Error("URL Object required");this.disabled=!0,this.moduleName="twitter",e.hostname.match(/\.?twitter\.com$/i)&&(this.disabled=!1)}GatherIntent(){if(this.disabled)return;const e=[];return document.querySelectorAll(".tweet-box.rich-editor").forEach((t=>{e.push(t.innerText)})),e}}},{}],9:[function(e,t,n){t.exports=class{constructor(e){if(void 0===e)throw new Error("URL Object required");this.disabled=!0,this.moduleName="youtube",e.hostname.match(/\.?youtube\.com$/i)&&(this.disabled=!1)}GatherIntent(){if(this.disabled)return;const e=[],t=document.getElementById("contenteditable-root");return t&&e.push(t.innerText),e}}},{}],10:[function(e,t,n){var r,o,i=t.exports={};function s(){throw new Error("setTimeout has not been defined")}function a(){throw new Error("clearTimeout has not been defined")}function c(e){if(r===setTimeout)return setTimeout(e,0);if((r===s||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:s}catch(e){r=s}try{o="function"==typeof clearTimeout?clearTimeout:a}catch(e){o=a}}();var u,d=[],l=!1,h=-1;function m(){l&&u&&(l=!1,u.length?d=u.concat(d):h=-1,d.length&&f())}function f(){if(!l){var e=c(m);l=!0;for(var t=d.length;t;){for(u=d,d=[];++h<t;)u&&u[h].run();h=-1,t=d.length}u=null,l=!1,function(e){if(o===clearTimeout)return clearTimeout(e);if((o===a||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{return o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function w(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];d.push(new p(e,t)),1!==d.length||l||c(f)},p.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=w,i.addListener=w,i.once=w,i.off=w,i.removeListener=w,i.removeAllListeners=w,i.emit=w,i.prependListener=w,i.prependOnceListener=w,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}]},{},[1]);