wvg/popup.js

77 lines
3.3 KiB
JavaScript
Raw Normal View History

2024-04-08 22:58:09 +00:00
let psshs=chrome.extension.getBackgroundPage().getPsshs();
let requests=chrome.extension.getBackgroundPage().getRequests();
2024-04-24 18:37:31 +00:00
let pageURL=chrome.extension.getBackgroundPage().getPageURL();
2024-04-08 22:58:09 +00:00
2024-04-09 15:04:17 +00:00
async function guess(){
2024-04-24 18:37:31 +00:00
//Init Pyodide
2024-04-18 20:48:32 +00:00
let pyodide = await loadPyodide();
await pyodide.loadPackage(["certifi-2024.2.2-py3-none-any.whl","charset_normalizer-3.3.2-py3-none-any.whl","construct-2.8.8-py2.py3-none-any.whl","idna-3.6-py3-none-any.whl","packaging-23.2-py3-none-any.whl","protobuf-4.24.4-cp312-cp312-emscripten_3_1_52_wasm32.whl","pycryptodome-3.20.0-cp35-abi3-emscripten_3_1_52_wasm32.whl","pymp4-1.4.0-py3-none-any.whl","pyodide_http-0.2.1-py3-none-any.whl","pywidevine-1.8.0-py3-none-any.whl","requests-2.31.0-py3-none-any.whl","urllib3-2.2.1-py3-none-any.whl"].map(e=>"wheels/"+e))
2024-04-24 18:37:31 +00:00
//Configure Guesser
2024-04-18 20:48:32 +00:00
let vars=`pssh="${document.getElementById('pssh').value}"\n`
vars+=`licUrl="${requests[userInputs['license']]['url']}"\n`
vars+=`licHeaders='${requests[userInputs['license']]['headers'].replace(/\\/g, "\\\\")}'\n`
2024-04-26 01:53:24 +00:00
vars+=`licBody="${requests[userInputs['license']]['body']}"\n`
2024-04-18 20:48:32 +00:00
let pre=await fetch('python/pre.py').then(res=>res.text())
let after=await fetch('python/after.py').then(res=>res.text())
2024-04-22 13:41:12 +00:00
let scheme=await fetch(`python/schemes/${document.getElementById("scheme").value}.py`).then(res=>res.text())
2024-04-24 18:37:31 +00:00
//Get result
2024-04-18 20:48:32 +00:00
let result = await pyodide.runPythonAsync([vars, pre, scheme, after].join("\n"));
2024-04-09 15:04:17 +00:00
document.getElementById('result').value=result;
2024-04-24 18:37:31 +00:00
//Save history
let historyData={
PSSH: document.getElementById('pssh').value,
KEYS: result.split("\n").slice(0,-1)
}
chrome.storage.local.set({[pageURL]: historyData}, function () {});
2024-04-08 22:58:09 +00:00
}
function copyResult(){
this.select();
navigator.clipboard.writeText(this.value);
}
2024-04-26 12:59:34 +00:00
window.corsFetch = (u, m, h, b) => {
2024-04-27 20:58:48 +00:00
return new Promise((resolve, reject) => {
chrome.tabs.query({ url:pageURL }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {type:"FETCH", u:u, m:m, h:h, b:b}, (res) => {
resolve(res)
})
})
})
2024-04-26 12:59:34 +00:00
}
2024-04-28 02:50:53 +00:00
async function autoSelect(){
let selectRules = await fetch("selectRules.conf").then((r)=>r.text());
selectRules = selectRules.replace(/\n^$/gm, "");
selectRules=selectRules.split("\n").map(function(row){return row.split("$$");});
for(var item of selectRules){
let search = requests.map(r => r['url']).findIndex(e => e.includes(item[0]));
if(search>=0){
if(item[1]) document.getElementById("scheme").value = item[1];
requestList.children[search].click();
break;
}
}
if(psshs.length==1){
document.getElementById('pssh').value=psshs[0];
}
if(requests.length==1){
requestList.children[0].click();
}
}
2024-04-08 22:58:09 +00:00
if(psshs.length!=0){
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('noEME').style.display='none';
document.getElementById('home').style.display='block';
document.getElementById('guess').addEventListener("click", guess);
document.getElementById('result').addEventListener("click", copyResult);
2024-04-08 22:58:09 +00:00
drawList(psshs,'psshSearch','psshList','pssh');
drawList(requests.map(r => r['url']),'requestSearch','requestList','license');
2024-04-28 02:50:53 +00:00
autoSelect();
2024-04-08 22:58:09 +00:00
});
}