wvg/content.js

46 lines
1.3 KiB
JavaScript
Raw Permalink 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
if (window === window.parent){
chrome.runtime.sendMessage({type: "RESET"},null);
}
2024-04-08 22:58:09 +00:00
//Send PSSH into background.js
document.addEventListener('pssh', (e) => {
2024-06-25 02:11:08 +00:00
chrome.runtime.sendMessage({
type: "PSSH",
text: e.detail
},null);
2024-04-08 22:58:09 +00:00
});
2024-04-26 12:59:34 +00:00
2024-05-07 19:43:06 +00:00
//Send Clearkey into background.js
document.addEventListener('clearkey', (e) => {
2024-06-25 02:11:08 +00:00
chrome.runtime.sendMessage({
type: "CLEARKEY",
text: e.detail
},null);
2024-05-07 19:43:06 +00:00
});
2024-04-26 12:59:34 +00:00
//Fetch from original origin
chrome.runtime.onMessage.addListener(
2024-06-25 02:11:08 +00:00
function (request, sender, sendResponse) {
if(request.type=="FETCH"){
let res = fetch(request.u, {
method: request.m,
headers: JSON.parse(request.h),
body: Uint8Array.from(atob(request.b), c => c.charCodeAt(0))
}).then((r)=>r.arrayBuffer()).then((r)=>{
sendResponse(
btoa(String.fromCharCode(...new Uint8Array(r)))
);
})
}
return true
2024-04-26 12:59:34 +00:00
}
);