From 42349f473298b0a74b398dcdc5a58ac09215b662 Mon Sep 17 00:00:00 2001
From: Miner49ur <101815367+Miner49ur@users.noreply.github.com>
Date: Sun, 8 Sep 2024 15:55:11 -0400
Subject: [PATCH] reverted restructuring of index.js to accomodate wider range
of chrome versions
---
payloads/index.js | 705 ++++++++++++++++++++++++++++------------------
1 file changed, 430 insertions(+), 275 deletions(-)
diff --git a/payloads/index.js b/payloads/index.js
index 1e08257..cc2ae77 100644
--- a/payloads/index.js
+++ b/payloads/index.js
@@ -1,86 +1,384 @@
-// utils
-const utils = {
- handleInAnimationFrame: (cb, thiz = null, args = []) => {
- const handleCallbacks_ = [];
- handleCallbacks_.push({
- f: cb,
- t: performance.now(),
- });
-
- requestAnimationFrame(function animate(t) {
- for (const cb of handleCallbacks_) {
- let m = cb.f.apply(null, [t - cb.t]);
- if (m === 1) return;
- if (m) handleCallbacks_.splice(handleCallbacks_.indexOf(cb), 1);
+onerror = alert;
+
+const uiTemplate = `
+
+`;
+// if (chrome.fileManagerPrivate) {
+// chrome.fileManagerPrivate.openURL();
+// }
+const managementTemplate = `
+
+
-
-
-
+ });
+}
+const fileManagerPrivateTemplate = `
+
+
+
- `,
+
- htmlStyle: `
+`;
+const htmlStyle = `
- `,
-};
-
-// extensionManager
-class ExtensionManager {
- constructor() {
- this.extlist_element = null;
- this.savedExtList = [];
- }
-
- createExtensionCard(name, id, enabled, icon_url) {
- const li = document.createElement("li");
- li.className = "extension-card";
- li.innerHTML = `
-
-
${name} (${id})
-
- `;
- return li;
- }
-
- async updateExtensionStatus() {
- this.extlist_element.innerHTML = "";
- return new Promise((resolve) => {
- chrome.management.getAll((extlist) => {
- extlist.forEach((e) => {
- if (e.id === new URL(new URL(location.href).origin).host) return;
-
- const icon = e.icons.find((ic) => ic.size === 128) ?? e.icons.at(-1);
- let card = this.createExtensionCard(e.name, e.id, e.enabled, icon.url);
-
- let cardInput = card.querySelector("input");
- cardInput.addEventListener("change", (event) => {
- chrome.management.setEnabled(e.id, event.target.checked);
- });
-
- card.querySelector(".extension-icon").addEventListener("click", () => {
- cardInput.checked = !cardInput.checked;
- cardInput.dispatchEvent(new Event('change'));
- });
-
- this.extlist_element.appendChild(card);
- });
- this.savedExtList = extlist;
- resolve();
- });
- });
- }
+ `;
- async initialize() {
- document.body.insertAdjacentHTML("beforeend", templates.managementTemplate);
- this.extlist_element = document.querySelector(".extlist");
- await this.updateExtensionStatus();
-
- const container_extensions = document.body.querySelector("#chrome_management_disable_ext");
- container_extensions.querySelector("#current-extension").onclick = async () => {
- try {
- const grabidtokill = chrome.runtime.id;
- chrome.management.setEnabled(grabidtokill, false);
- } catch {
- alert("unsuccessful");
- }
- };
- }
-}
-
-// defaultExtensionCapabilities
-class DefaultExtensionCapabilities {
- constructor() {
- this.disarmed = false;
- this.tabListInProgress = false;
- this.previewing = false;
- }
-
- activate() {
- document.body.insertAdjacentHTML("beforeend", templates.defaultExtensionTemplate);
-
- document.body
- .querySelector("#ext_default")
- .querySelectorAll("button")
- .forEach((btn) => {
- btn.addEventListener("click", this.onBtnClick_.bind(this, btn));
- });
-
- this.updateTabList();
-
- for (let i in chrome.tabs) {
- if (i.startsWith("on")) {
- chrome.tabs[i].addListener(() => {
- this.updateTabList();
- });
- }
- }
- }
-
- updateTabList() {
- if (this.disarmed || this.tabListInProgress) return;
-
- this.tabListInProgress = true;
- const tablist = document.body.querySelector("#extension_tabs_default ul");
- tablist.innerHTML = "";
-
- chrome.windows.getAll((windows) => {
- windows.forEach((window) => {
- chrome.tabs.query({ windowId: window.id }, (tabInfos) => {
- tabInfos.forEach((info) => {
- const div = this.createTabListItem(info);
- tablist.appendChild(div);
- });
- this.tabListInProgress = false;
- });
- });
- });
+onload = async function x() {
+ let foundNothing = true;
+ document.open();
+ this.document.write(htmlStyle);
+ document.close();
+ if (chrome.fileManagerPrivate) {
+ // alert(1);
+ chrome.fileManagerPrivate.openURL("data:text/html,
Hello
");
+ document.write(fileManagerPrivateTemplate);
+ document.body.querySelector("#btn_FMP_openURL").onclick = function (ev) {};
}
+ if (chrome.management.setEnabled) {
+ document.body.insertAdjacentHTML("beforeend", managementTemplate);
+ // createStyleTag();
+ const extlist_element = document.querySelector(".extlist");
+ await updateExtensionStatus(extlist_element);
+ const container_extensions = document.body.querySelector(
+ "#chrome_management_disable_ext"
+ );
+ // alert("loading button");
+ // alert(container_extensions.querySelector("button"));
+
+ container_extensions.querySelector("#current-extension").onclick =
+ async function df(e) {
+ try {
+ var grabidtokill = chrome.runtime.id;
+ chrome.management.setEnabled(grabidtokill, false);
+ } catch {
+ alert("unsuccessful");
+ }
+ };
- createTabListItem(info) {
- const div = document.createElement("div");
- div.className = "tablist-item";
- div.innerHTML = `
0 ? `src="${info.favIconUrl}"` : ""}/>
${info.title} (${info.url})`;
-
- // const navButton = document.createElement("button");
- // navButton.className = "navigate";
- // navButton.textContent = "Navigate";
- // navButton.onclick = () => {
- // const inp = div.querySelector("input");
- // chrome.tabs.update(info.id, { url: inp.value });
- // };
-
- const previewButton = document.createElement("button");
- previewButton.textContent = "Preview";
- previewButton.onclick = () => this.previewTab(info);
-
- if (chrome.scripting) {
- const runButton = document.createElement("button");
- runButton.textContent = "Run";
- runButton.onclick = () => runCode(true, info.id);
- div.appendChild(runButton);
- }
-
- // div.appendChild(navButton);
- div.appendChild(previewButton);
- return div;
}
+ const otherFeatures = window.chrome.runtime.getManifest();
+ const permissions = otherFeatures.permissions;
- previewTab(info) {
- this.disarm = true;
- this.previewing = true;
-
- chrome.windows.update(info.windowId, { focused: true }, () => {
- chrome.tabs.update(info.id, { active: true });
- });
-
- window.currentTimeout = setTimeout(() => {
- clearTimeout(window.currentTimeout);
- chrome.tabs.getCurrent((tab) => {
- chrome.windows.update(tab.windowId, { focused: true }, () => {
- chrome.tabs.update(tab.id, { active: true });
- this.disarm = false;
- this.previewing = false;
- });
- });
- }, 100);
- }
+ new DefaultExtensionCapabilities().activate();
+ document.body.insertAdjacentHTML("beforeend", ``);
- async onBtnClick_(b) {
- switch (b.id) {
- case "code-run":
- runCode(false);
- break;
- case "tabreload":
- this.updateTabList();
- break;
- }
- }
-}
+ document.querySelector("#code-run").addEventListener("click", () => runCode(false));
+};
-// inject code
-async function runCode(onTab, tabId = "") {
+const runCode = async (onTab, tabId = "") => {
const codeTextarea = document.querySelector("#code");
let code = codeTextarea.value;
+
const outputDiv = document.querySelector("#code-output");
if (onTab) {
code = `chrome.scripting.executeScript({
target: {tabId: ${tabId}},
func: () => {${code}}
- });`;
+ });`
}
try {
@@ -497,10 +660,26 @@ async function runCode(onTab, tabId = "") {
outputDiv.innerHTML += args.join(" ") + "
";
};
- const fs = await utils.getFS();
- const url = await utils.writeFile(fs, "src.js", code);
-
- let script = document.body.querySelector("#evaluate_elem") ?? document.createElement("script");
+ const fs = await DefaultExtensionCapabilities.getFS();
+ function writeFile(file, data) {
+ return new Promise((resolve, reject) => {
+ fs.root.getFile(file, { create: true }, function (entry) {
+ entry.remove(function () {
+ fs.root.getFile(file, { create: true }, function (entry) {
+ entry.createWriter(function (writer) {
+ writer.write(new Blob([data]));
+ writer.onwriteend = resolve.bind(null, entry.toURL());
+ });
+ });
+ });
+ });
+ });
+ }
+
+ const url = await writeFile("src.js", code);
+ let script =
+ document.body.querySelector("#evaluate_elem") ??
+ document.createElement("script");
script.remove();
script = document.createElement("script");
script.id = "evaluate_elem";
@@ -511,28 +690,4 @@ async function runCode(onTab, tabId = "") {
} catch (error) {
outputDiv.innerHTML = `Error: ${error}`;
}
-}
-
-async function initialize() {
- document.open();
- document.write(templates.htmlStyle);
- document.close();
-
- if (chrome.fileManagerPrivate) {
- chrome.fileManagerPrivate.openURL("data:text/html,
Hello
");
- document.write(templates.fileManagerPrivateTemplate);
- document.body.querySelector("#btn_FMP_openURL").onclick = () => {};
- }
-
- if (chrome.management.setEnabled) {
- const extensionManager = new ExtensionManager();
- await extensionManager.initialize();
- }
-
- new DefaultExtensionCapabilities().activate();
-
- document.body.insertAdjacentHTML("beforeend", ``);
- document.querySelector("#code-run").addEventListener("click", () => runCode(false));
-}
-
-window.onload = initialize;
\ No newline at end of file
+}
\ No newline at end of file