1 line
No EOL
2.9 KiB
JavaScript
1 line
No EOL
2.9 KiB
JavaScript
(()=>{"use strict";const e="mnojpmjdmbbfmejpflffifhffcmidifd";let t=null;const r=()=>t;let i=!1;const o=(RegExp(/&(?:amp|lt|gt|quot|#(0+)?39);/g.source),"twitch"),n="www.twitch.tv",a=()=>{const e=document.querySelector(".channel-info-content .tw-avatar [src]");return e&&e.getAttribute("src")||""},s=()=>document.querySelector("h1.tw-title"),c=()=>{const e=s();return e&&e.textContent||""},l=e=>e.replace(/^\/|\/[\s\S]*/g,""),u=new Set(["directory","downloads","jobs","p","search","turbo"]),d=()=>"videos"===l(location.pathname).toLowerCase(),m=e=>{if(!e)return"";const t=/^\/*videos\//i;if(t.test(location.pathname)){const r=location.pathname.replace(t,""),i=l(r);return i?`twitch_${e}_void_${i}`:""}return`twitch_${e}`},h=e=>e?`twitch#author:${e}`:"",p=()=>({mediaId:"",mediaKey:"",publisherUrl:"https://www.twitch.tv",publisherKey:n,publisherName:n,favIconUrl:""}),f=()=>{const e=(()=>{if(d()){const e=s();if(!e||!e.parentElement)return"";const t=e.parentElement.getAttribute("href");return t?l(t).toLowerCase():""}const e=l(location.pathname).toLowerCase();return u.has(e)?"":e})();return e?{mediaId:e,mediaKey:m(e),publisherUrl:`https://www.twitch.tv/${e}`,publisherKey:h(e),publisherName:c(),favIconUrl:a()}:p()},b=new class{constructor(){this.previous=p()}async read(){let e=f();if(!e.mediaId&&!d())return this.previous=e,e;let{previous:t}=this;for(let r=0;r<5e3&&!(e.mediaId&&e.publisherName&&e.favIconUrl&&(e.mediaId&&t.mediaId===e.mediaId||e.publisherName!==t.publisherName&&e.favIconUrl!==t.favIconUrl));r+=250)await new Promise((e=>setTimeout(e,250))),e=f();return this.previous=e,e}};let w="";const v=e=>{e&&"complete"===e.status&&location.href!==w&&(w=location.href,y())},y=()=>{b.read().then((e=>{const t=r();t&&t.postMessage({type:"SavePublisherVisit",mediaType:e.mediaId?o:"",data:{url:e.publisherUrl,publisherKey:e.publisherKey,publisherName:e.publisherName,mediaKey:e.mediaKey,favIconUrl:e.favIconUrl}})})).catch((e=>{const r=e?e.message:"";((e,r)=>{e&&t&&t.postMessage({type:"GreaselionError",mediaType:e,data:{errorMessage:r}})})(o,`Error reading publisher info: ${r})`)}))};var g;chrome.extension.inIncognitoContext||(g=e=>{e?(((e,t)=>{if(!e||i)return;i=!0;const o=r();o&&(o.postMessage({type:"RegisterOnUpdatedTab",mediaType:e}),o.onMessage.addListener((function(e){e.data&&"OnUpdatedTab"===e.type&&t(e.data.changeInfo)})))})(o,v),"complete"===document.readyState&&"visible"===document.visibilityState&&y(),document.addEventListener("visibilitychange",(function(){"visible"===document.visibilityState&&y()})),console.info("Greaselion script loaded: twitchBase.ts")):console.error("Failed to initialize communications port")},t?g(!0):(chrome.runtime.sendMessage(e,{type:"SupportsGreaselion"},(function(r){!chrome.runtime.lastError&&r&&r.supported&&(t=chrome.runtime.connect(e,{name:"Greaselion"}),g(!0))})),setTimeout((()=>{t||(t=chrome.runtime.connect("jidkidbbcafjabdphckchenhfomhnfma",{name:"Greaselion"}),g(!0))}),100)))})(); |