From 4316530ce8c840cb0c457b02c9562a0e86f714a1 Mon Sep 17 00:00:00 2001 From: FoxRefire <155989196+FoxRefire@users.noreply.github.com> Date: Tue, 29 Oct 2024 23:57:42 +0900 Subject: [PATCH] Refactor: styling --- inject.js | 10 +++++----- popup/history.js | 3 +-- popup/main.js | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/inject.js b/inject.js index c798e36..4b6956e 100644 --- a/inject.js +++ b/inject.js @@ -1,13 +1,13 @@ // Refactored conversion functions -const fromHexString = hexString => Uint8Array.from(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); +const hexStrToU8 = hexString => Uint8Array.from(hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16))); -const toHexString = bytes => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), ''); +const u8ToHexStr = bytes => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), ''); -const b64ToHex = b64 => [...atob(b64)].map(c=> c.charCodeAt(0).toString(16).padStart(2,0)).join`` +const b64ToHexStr = b64 => [...atob(b64)].map(c=> c.charCodeAt(0).toString(16).padStart(2,0)).join`` // initData to PSSH function getPssh(buffer) { - const bytes = fromHexString(toHexString(new Uint8Array(buffer)).match(/000000..70737368.*/)[0]); + const bytes = hexStrToU8(u8ToHexStr(new Uint8Array(buffer)).match(/000000..70737368.*/)[0]); return window.btoa(String.fromCharCode(...bytes)); } @@ -16,7 +16,7 @@ function getClearkey(response) { let obj=JSON.parse((new TextDecoder("utf-8")).decode(response)) obj = obj["keys"].map(o => [o["kid"], o["k"]]); obj = obj.map(o => o.map(a => a.replace(/-/g, '+').replace(/_/g, '/')+"==")) - return obj.map(o => `${b64ToHex(o[0])}:${b64ToHex(o[1])}`).join("\n") + return obj.map(o => `${b64ToHexStr(o[0])}:${b64ToHexStr(o[1])}`).join("\n") } diff --git a/popup/history.js b/popup/history.js index d6c83f4..0300f2e 100644 --- a/popup/history.js +++ b/popup/history.js @@ -9,10 +9,9 @@ function showHistory(){ function saveHistory(){ chrome.storage.local.get(null, (data => { let blob = new Blob([JSON.stringify(data, null, "\t")], {type: "text/plain"}); - let blobLink = URL.createObjectURL(blob); let a = document.createElement('a'); a.download = 'wvgHistory.json'; - a.href = blobLink + a.href = URL.createObjectURL(blob); a.click(); })); } diff --git a/popup/main.js b/popup/main.js index 08fe7c8..ec31493 100644 --- a/popup/main.js +++ b/popup/main.js @@ -78,7 +78,6 @@ if (clearkey) { document.getElementById('ckHome').style.display = 'grid'; document.getElementById('ckResult').value = clearkey; document.getElementById('ckResult').addEventListener("click", copyResult); - document.getElementById('toggleHistory').style.display = 'none' } else if (psshs.length) { document.getElementById('noEME').style.display = 'none'; document.getElementById('home').style.display = 'grid';