chrome extension for skeeting tweets at the sky
at main 1 lines 3.3 kB view raw
1function e(c,...s){chrome.runtime.sendMessage({type:"log_message",data:{message:c,args:JSON.stringify(s)}})}(function(){if(e("Content script loaded for:",window.location.href),window.location.href.includes("skeet.fyi/oauth-callback")){let s=function(t,n,r){if(c){e("OAuth callback already processed, ignoring duplicate");return}e("Processing OAuth callback with:",{code:t?t.substring(0,10)+"...":null,state:n,iss:r}),c=!0,e("Sending oauth_callback message to popup"),chrome.runtime.sendMessage({type:"oauth_callback_log",data:{code:t,state:n,iss:r}}),chrome.runtime.sendMessage({type:"popup_oauth_callback",data:{code:t,state:n,iss:r}},function(o){if(chrome.runtime.lastError){e("Error sending message to popup:",chrome.runtime.lastError),chrome.storage.local.set({oauth_callback_data:{code:t,state:n,iss:r,timestamp:Date.now()}},function(){e("Stored OAuth callback data for later retrieval")});try{e("Posting success message to window"),window.postMessage({type:"oauth_callback_response",success:!0,message:"Authentication successful! You can close this window."},"*"),e("Posted success message to window")}catch(a){e("Error posting message to window:",a)}return}e("Received response from popup:",o);try{e("Posting message to window"),window.postMessage({type:"oauth_callback_response",success:o==null?void 0:o.success,error:o==null?void 0:o.error,data:o==null?void 0:o.data,message:o!=null&&o.success?"Authentication successful! You can close this window.":"Authentication failed."},"*"),e("Posted message to window successfully")}catch(a){e("Error posting message to window:",a)}})},i=function(){if(e("Checking URL parameters..."),c){e("Skipping URL parameter check as callback was already processed");return}let t=new URLSearchParams(window.location.search),n=new URLSearchParams(window.location.hash.substring(1));e("URL search params:",Object.fromEntries(t.entries())),e("URL hash params:",Object.fromEntries(n.entries()));let r=t.get("code")||n.get("code"),o=t.get("state")||n.get("state"),a=t.get("iss")||n.get("iss");e("Extracted parameters:",{code:r?r.substring(0,10)+"...":null,state:o,iss:a}),r&&o&&a?(e("Found OAuth parameters in URL, calling handleOAuthCallback"),s(r,o,a)):e("Missing required OAuth parameters in URL",{code:!!r,state:!!o,iss:!!a})},l=function(){e("Extension content script is ready, ID:",chrome.runtime.id);try{let t=document.createElement("script");t.src=chrome.runtime.getURL("scripts/extension-id-provider.js"),t.dataset.extensionId=chrome.runtime.id,document.head?(document.head.appendChild(t),e("External script injected successfully")):document.documentElement?(document.documentElement.appendChild(t),e("External script injected to documentElement")):document.addEventListener("DOMContentLoaded",function(){document.head.appendChild(t),e("External script injected after DOMContentLoaded")})}catch(t){e("Error setting up extension ID:",t);try{let n=new CustomEvent("extension_ready",{detail:{extensionId:chrome.runtime.id}});window.dispatchEvent(n),e("Dispatched extension_ready event directly")}catch(n){e("Error dispatching event:",n)}}},c=!1;window.addEventListener("oauth_callback",function(t){let{code:n,state:r,iss:o}=t.detail;s(n,r,o)}),e("Setting timeout to check URL parameters in 500ms"),setTimeout(i,500),l()}})();