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 = ` + +
+

chrome.management Disable Extensions

+

this funny was granted by the members of silly goober money gang

+

we love casting fun times

+
+ +

+ + +
+
+ +`; +let savedExtList = []; +const slides = []; +let activeSlideIdx = 0; +const handleCallbacks_ = []; +const WAIT_FOR_FINISH = 1; +requestAnimationFrame(function a(t) { + for (const cb of handleCallbacks_) { + let m; + if ((m = cb.f.apply(null, [t - cb.t]))) { + if (m === 1) { + return; + } else { + handleCallbacks_.splice(handleCallbacks_.indexOf(cb), 1); } - requestAnimationFrame(animate); + } + } + requestAnimationFrame(a); +}); +const handleInAnimationFrame = (cb, thiz = null, args = []) => { + handleCallbacks_.push({ + f: cb, + t: performance.now(), + }); +}; + +// class ExtensionCapabilities { +// static setupSlides(activeidx = 0) { +// if (chrome.management) { +// slides.push(document.querySelector("#chrome_management_disable_ext")); +// } +// slides.push(document.querySelector("#ext_default")); +// for (let i = 0; i < slides.length; i++) { +// if (i === activeidx) { +// slides[i].style.display = "block"; +// } else { +// slides[i].style.display = "none"; +// } +// } +// activeSlideIdx = activeidx; + +// onkeydown = function (ev) { +// if (ev.repeat) return; + +// if (this.getSelection() && this.getSelection().anchorNode.tagName) { +// return; +// } +// if (ev.key.toLowerCase().includes("left")) { +// activeSlideIdx--; +// if (activeSlideIdx < 0) { +// activeSlideIdx += slides.length; +// } +// activeSlideIdx %= slides.length; +// ev.preventDefault(); +// } +// if (ev.key.toLowerCase().includes("right")) { +// activeSlideIdx++; +// if (activeSlideIdx < 0) { +// activeSlideIdx += slides.length; +// } +// activeSlideIdx %= slides.length; +// ev.preventDefault(); +// } +// ExtensionCapabilities.setActiveSlideIndex(activeSlideIdx); +// }; +// } +// static setActiveSlideIndex(idx) { +// function a(t) { +// const seconds = t / 1000; +// if (seconds >= 0.2) { +// // slides[i].style.display = "none"; +// return true; +// } +// slides[idx].style.opacity = String(seconds / 0.2); +// } +// for (let i = 0; i < slides.length; i++) { +// if (i === idx) { +// slides[i].style.display = ""; +// } else { +// if (slides[i].style.display === "block") { +// slides[i].style.position = "absolute"; +// const m = i; +// handleInAnimationFrame(function (t) { +// const seconds = t / 1000; +// if (0.8 - seconds <= 0) { +// slides[i].style.display = "none"; +// handleInAnimationFrame(a); +// return true; +// } +// slides[i].style.opacity = String((0.2 - seconds) / 0.2); +// }); +// } +// // slides[i].style.display = "none"; +// } +// } +// } + +// activate() {} +// } +class DefaultExtensionCapabilities { + static template = ` +
+
+

Default Extension Capabilities

+ +

Evaluate code

+
+ +
+ +
+ +
+
+ + + + +
+
+ `; // TODO: Fix Navigator (For now I removed it) + updateTabList() { + if (this.disarmed) { + return; + } + + if (this.tabListInProgress) { + console.log("In progress tablist building!"); + return; + } + this.tabListInProgress = true; + + const tablist = document.body.querySelector("#extension_tabs_default ul"); + + tablist.innerHTML = ""; + const thiz = this; + chrome.windows.getAll(function (win) { + win.forEach(function (v) { + chrome.tabs.query({ windowId: v.id }, function (tabInfos) { + tabInfos.forEach(function (info) { + const div = document.createElement("div"); + div.className = "tablist-item"; + div.innerHTML = ` 0 ? `src="${info.favIconUrl}"` : ""}/>${info.title} (${info.url})`; + if (chrome.scripting) { + const runButton = document.createElement("button"); + runButton.textContent = "Run"; + runButton.onclick = () => runCode(true, info.id); + div.appendChild(runButton); + } + // const navButton = document.createElement("button"); + // navButton.className = "navigate"; + // navButton.textContent = "Navigate"; + const previewButton = document.createElement("button"); + previewButton.textContent = "Preview"; + if (chrome.scripting) { + const runButton = document.createElement("button"); + runButton.textContent = "Run"; + runButton.onclick = function (ev) { + runCode(true, info.id); + } + + div.appendChild(runButton); + } + + // navButton.onclick = function (ev) { + // const inp = div.querySelector("input"); + // chrome.tabs.update(info.id, { + // url: inp.value, + // }); + // }; + previewButton.onclick = () => { + thiz.disarm = true; + + thiz.previewing = true; + + chrome.windows.update( + info.windowId, + { + focused: true, + }, + function () { + chrome.tabs.update(info.id, { active: true }); + } + ); + window.currentTimeout = setTimeout(function m() { + clearTimeout(window.currentTimeout); + + chrome.tabs.getCurrent(function (tab) { + chrome.windows.update( + tab.windowId, + { + focused: true, + }, + function () { + chrome.tabs.update(tab.id, { active: true }); + thiz.disarm = false; + thiz.previewing = false; + } + ); + }); + }, 100); + }; + + // div.appendChild(navButton); + div.appendChild(previewButton); + tablist.appendChild(div); + }); + thiz.tabListInProgress = false; + }); + }); }); - }, + } + activate() { + document.body.insertAdjacentHTML("beforeend", DefaultExtensionCapabilities.template); + // document.close(); + document.body + .querySelector("#ext_default") + .querySelectorAll("button") + .forEach(function (btn) { + // alert("prepping button " + btn.id); + btn.addEventListener("click", this.onBtnClick_.bind(this, btn)); + }, this); - getFS: () => { - return new Promise((resolve) => { + this.updateTabList(); + for (let i in chrome.tabs) { + if (i.startsWith("on")) { + chrome.tabs[i].addListener(() => { + this.updateTabList(); + }); + } + } + // document.body.querySelector('') + } + static getFS() { + return new Promise(function (resolve) { webkitRequestFileSystem(TEMPORARY, 2 * 1024 * 1024, resolve); }); - }, - - writeFile: async (fs, file, data) => { - return new Promise((resolve, reject) => { - fs.root.getFile(file, { create: true }, (entry) => { - entry.remove(() => { - fs.root.getFile(file, { create: true }, (entry) => { - entry.createWriter((writer) => { - writer.write(new Blob([data])); - writer.onwriteend = resolve.bind(null, entry.toURL()); + } + /** + * @param {HTMLButtonElement} b + */ + async onBtnClick_(b) { + switch (b.id) { + case "code_evaluate": { + console.log("Evaluating code!"); + const x = document.querySelector("#code_input").value; + 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", x); + let script = + document.body.querySelector("#evaluate_elem") ?? + document.createElement("script"); + script.remove(); + script = document.createElement("script"); + script.id = "evaluate_elem"; + script.src = url; + document.body.appendChild(script); + } + case "tabreload": { + this.updateTabList(); + } + } + } +} +class HostPermissions { + activate() {} +} +function createExtensionCard(name, id, enabled, icon_url) { + const li = document.createElement("li"); + li.className = "extension-card"; + li.innerHTML = ` + + ${name} (${id}) + + `; + return li; +} +function updateExtensionStatus(extlist_element) { + return new Promise(function (resolve, reject) { + extlist_element.innerHTML = ""; + chrome.management.getAll(function (extlist) { + const ordlist = []; + let e = 0; + extlist.forEach(function (e) { + if (e.id === new URL(new URL(location.href).origin).host) { + return; + } + ordlist.push(e); + + const icon = e.icons.find((ic) => ic.size === 128) ?? e.icons.at(-1); + + let card = 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); + // setTimeout(function () { + // updateExtensionStatus(extlist_element); + // }, 200); }); + + card.querySelector(".extension-icon").addEventListener("click", () => { + cardInput.checked = !cardInput.checked; + cardInput.dispatchEvent(new Event('change')); + }) + + // const itemElement = document.createElement("li"); + // itemElement.textContent = `${e.name} (${e.id}) `; + // const aElem = document.createElement('a'); + // aElem.href = "javascript:void(0)"; + // aElem.innerText = `${e.enabled ? "enabled" : "disabled"}`; + // aElem.onclick = function () { + // // alert(e.enabled); + // chrome.management.setEnabled(e.id, !e.enabled); + // setTimeout(function () { + // updateExtensionStatus(extlist_element); + // }, 200); + // } + // // e++; + // itemElement.appendChild(aElem); + extlist_element.appendChild(card); + resolve(); }); + savedExtList = ordlist; }); - }, -}; - -// templates -const templates = { - managementTemplate: ` -
-

Chrome Management: Disable Extensions

-

This functionality was granted by the members of silly goober money gang

-

We love casting fun times

-
- -

- -
- `, - - defaultExtensionTemplate: ` -
-
-

Default Extension Capabilities

-

Evaluate code

-
- -
- -
-
-
- - - -
-
- `, - - fileManagerPrivateTemplate: ` -
-
- -
+ }); +} +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