wvg/content.js

39 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-04-08 22:58:09 +00:00
const script = document.createElement('script');
script.type = 'text/javascript';
script.defer = false;
script.async = false;
script.src = chrome.runtime.getURL("inject.js");
(document.head || document.documentElement).appendChild(script);
//Reset variables at every page load in background.js
chrome.runtime.sendMessage({type: "RESET"},null);
//Send PSSH into background.js
document.addEventListener('pssh', (e) => {
console.log(e.detail);
chrome.runtime.sendMessage({
type: "PSSH",
2024-04-24 18:37:31 +00:00
text: e.detail,
pageURL: document.URL
2024-04-08 22:58:09 +00:00
},null);
});
2024-04-26 12:59:34 +00:00
//Fetch from original origin
chrome.runtime.onMessage.addListener(
2024-04-27 20:58:48 +00:00
function (request, sender, sendResponse) {
2024-04-26 12:59:34 +00:00
if(request.type=="FETCH"){
2024-04-27 20:58:48 +00:00
console.log("DEBUG:"+JSON.stringify(request))
let res = fetch(request.u, {
2024-04-26 12:59:34 +00:00
method: request.m,
headers: request.h,
body: request.b
2024-04-27 20:58:48 +00:00
}).then((r)=>r.arrayBuffer()).then((r)=>{
sendResponse(
btoa(String.fromCharCode(...new Uint8Array(r)))
);
2024-04-26 12:59:34 +00:00
})
}
2024-04-27 20:58:48 +00:00
return true
2024-04-26 12:59:34 +00:00
}
);