mirror of
https://github.com/smartfrigde/armcord.git
synced 2024-08-14 23:56:58 +00:00
fix settings webview injection
This commit is contained in:
parent
6beee8d825
commit
dfe104da42
2 changed files with 17 additions and 22 deletions
|
@ -73,11 +73,24 @@ sleep(5000).then(async () => {
|
|||
|
||||
// Settings info version injection
|
||||
setInterval(() => {
|
||||
addScript(`
|
||||
if (document.getElementById("ACsettingsModal") == null) {
|
||||
var html = '<span class="close" id="closeSettings">×</span><div class="ACsettings-modal-content" id="webviewSettingsContainer"></div>';
|
||||
const elem = document.createElement("div");
|
||||
elem.id = "ACsettingsModal";
|
||||
elem.classList.add("ACsettings-modal");
|
||||
elem.innerHTML = html;
|
||||
document.getElementById("app-mount").prepend(elem);
|
||||
document.getElementById("closeSettings").addEventListener("click", () => {
|
||||
document.getElementById("webviewSettingsContainer").innerHTML = "";
|
||||
document.getElementById("ACsettingsModal").style.display = "none";
|
||||
});
|
||||
}
|
||||
`);
|
||||
const host = document.querySelector('[class*="sidebar"] [class*="info"]');
|
||||
if (!host || host.querySelector("#ac-ver")) {
|
||||
return;
|
||||
}
|
||||
|
||||
const el = host.firstElementChild!.cloneNode() as HTMLSpanElement;
|
||||
el.id = "ac-ver";
|
||||
el.textContent = `ArmCord Version: ${version}`;
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
import * as path from "path";
|
||||
import * as fs from "fs";
|
||||
import {addStyle} from "../utils";
|
||||
import {addScript, addStyle} from "../utils";
|
||||
import {WebviewTag} from "electron";
|
||||
var html = `
|
||||
<div id="ACsettingsModal" class="ACsettings-modal">
|
||||
<span class="close" id="closeSettings">×</span>
|
||||
<div class="ACsettings-modal-content" id="webviewSettingsContainer">
|
||||
</div>
|
||||
</div>`;
|
||||
|
||||
var webview = `<webview src="${path.join("file://", __dirname, "../", "/settings/settings.html")}" preload="${path.join(
|
||||
"file://",
|
||||
|
@ -15,27 +9,15 @@ var webview = `<webview src="${path.join("file://", __dirname, "../", "/settings
|
|||
"../",
|
||||
"/settings/preload.js"
|
||||
)}" id="inAppSettings"></webview>`;
|
||||
|
||||
export function injectSettings() {
|
||||
document.getElementById("webviewSettingsContainer")!.innerHTML = webview;
|
||||
document.getElementById("ACsettingsModal")!.style.display = "block";
|
||||
}
|
||||
function removeSettings() {
|
||||
document.getElementById("webviewSettingsContainer")!.innerHTML = "";
|
||||
document.getElementById("ACsettingsModal")!.style.display = "none";
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function (_event) {
|
||||
const elem = document.createElement("div");
|
||||
elem.innerHTML = html;
|
||||
if (document.getElementById("app-mount") == null) {
|
||||
document.body.appendChild(elem);
|
||||
} else {
|
||||
document.getElementById("app-mount")!.prepend(elem);
|
||||
}
|
||||
const settingsCssPath = path.join(__dirname, "../", "/content/css/inAppSettings.css");
|
||||
addStyle(fs.readFileSync(settingsCssPath, "utf8"));
|
||||
document.getElementById("closeSettings")!.addEventListener("click", () => {
|
||||
removeSettings();
|
||||
});
|
||||
const webview = document.querySelector("webview") as WebviewTag;
|
||||
webview.addEventListener("console-message", (e) => {
|
||||
console.log("Settings page logged a message:", e.message);
|
||||
|
|
Loading…
Reference in a new issue