Update pluginsupport.js
Signed-off-by: AvaLilac <amyshimplays@gmail.com>
This commit is contained in:
parent
45b96855eb
commit
eff6fe57f9
1 changed files with 7 additions and 56 deletions
|
|
@ -15,12 +15,10 @@
|
||||||
async function processQueue() {
|
async function processQueue() {
|
||||||
if (processQueue.running) return;
|
if (processQueue.running) return;
|
||||||
processQueue.running = true;
|
processQueue.running = true;
|
||||||
|
|
||||||
while (injectionQueue.length) {
|
while (injectionQueue.length) {
|
||||||
const { plugin, force } = injectionQueue.shift();
|
const { plugin, force } = injectionQueue.shift();
|
||||||
await loadPluginInternal(plugin, force);
|
await loadPluginInternal(plugin, force);
|
||||||
}
|
}
|
||||||
|
|
||||||
processQueue.running = false;
|
processQueue.running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -32,25 +30,19 @@
|
||||||
async function loadPluginInternal(plugin, force = false) {
|
async function loadPluginInternal(plugin, force = false) {
|
||||||
if (runningPlugins[plugin.url] && !force) return;
|
if (runningPlugins[plugin.url] && !force) return;
|
||||||
if (force) stopPlugin(plugin);
|
if (force) stopPlugin(plugin);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(plugin.url);
|
const res = await fetch(plugin.url);
|
||||||
if (!res.ok) throw new Error("Fetch failed");
|
if (!res.ok) throw new Error("Fetch failed");
|
||||||
const code = await res.text();
|
const code = await res.text();
|
||||||
|
|
||||||
delete pluginErrors[plugin.url];
|
delete pluginErrors[plugin.url];
|
||||||
|
|
||||||
const script = document.createElement("script");
|
const script = document.createElement("script");
|
||||||
script.textContent = code;
|
script.textContent = code;
|
||||||
script.dataset.pluginUrl = plugin.url;
|
script.dataset.pluginUrl = plugin.url;
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
|
|
||||||
runningPlugins[plugin.url] = script;
|
runningPlugins[plugin.url] = script;
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
pluginErrors[plugin.url] = true;
|
pluginErrors[plugin.url] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPanel();
|
renderPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +61,6 @@
|
||||||
panel.style.display = panel.style.display === 'none' ? 'flex' : 'none';
|
panel.style.display = panel.style.display === 'none' ? 'flex' : 'none';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
panel = document.createElement('div');
|
panel = document.createElement('div');
|
||||||
panel.id = 'avia-plugins-panel';
|
panel.id = 'avia-plugins-panel';
|
||||||
panel.style.position = 'fixed';
|
panel.style.position = 'fixed';
|
||||||
|
|
@ -87,7 +78,6 @@
|
||||||
panel.style.overflow = 'hidden';
|
panel.style.overflow = 'hidden';
|
||||||
panel.style.border = '1px solid rgba(255,255,255,0.08)';
|
panel.style.border = '1px solid rgba(255,255,255,0.08)';
|
||||||
panel.style.backdropFilter = 'blur(12px)';
|
panel.style.backdropFilter = 'blur(12px)';
|
||||||
|
|
||||||
const header = document.createElement('div');
|
const header = document.createElement('div');
|
||||||
header.textContent = 'Plugins';
|
header.textContent = 'Plugins';
|
||||||
header.style.padding = '14px 16px';
|
header.style.padding = '14px 16px';
|
||||||
|
|
@ -96,7 +86,6 @@
|
||||||
header.style.background = 'var(--md-sys-color-surface-container, rgba(255,255,255,0.04))';
|
header.style.background = 'var(--md-sys-color-surface-container, rgba(255,255,255,0.04))';
|
||||||
header.style.borderBottom = '1px solid rgba(255,255,255,0.08)';
|
header.style.borderBottom = '1px solid rgba(255,255,255,0.08)';
|
||||||
header.style.cursor = 'move';
|
header.style.cursor = 'move';
|
||||||
|
|
||||||
const closeBtn = document.createElement('div');
|
const closeBtn = document.createElement('div');
|
||||||
closeBtn.textContent = '✕';
|
closeBtn.textContent = '✕';
|
||||||
closeBtn.style.position = 'absolute';
|
closeBtn.style.position = 'absolute';
|
||||||
|
|
@ -105,7 +94,6 @@
|
||||||
closeBtn.style.cursor = 'pointer';
|
closeBtn.style.cursor = 'pointer';
|
||||||
closeBtn.style.opacity = '0.7';
|
closeBtn.style.opacity = '0.7';
|
||||||
closeBtn.onclick = () => panel.style.display = 'none';
|
closeBtn.onclick = () => panel.style.display = 'none';
|
||||||
|
|
||||||
const controlsBar = document.createElement('div');
|
const controlsBar = document.createElement('div');
|
||||||
controlsBar.style.padding = '12px 16px';
|
controlsBar.style.padding = '12px 16px';
|
||||||
controlsBar.style.display = 'flex';
|
controlsBar.style.display = 'flex';
|
||||||
|
|
@ -113,23 +101,19 @@
|
||||||
controlsBar.style.alignItems = 'center';
|
controlsBar.style.alignItems = 'center';
|
||||||
controlsBar.style.borderBottom = '1px solid rgba(255,255,255,0.08)';
|
controlsBar.style.borderBottom = '1px solid rgba(255,255,255,0.08)';
|
||||||
controlsBar.style.flex = '0 0 auto';
|
controlsBar.style.flex = '0 0 auto';
|
||||||
|
|
||||||
const content = document.createElement('div');
|
const content = document.createElement('div');
|
||||||
content.id = 'avia-plugins-content';
|
content.id = 'avia-plugins-content';
|
||||||
content.style.flex = '1';
|
content.style.flex = '1';
|
||||||
content.style.overflow = 'auto';
|
content.style.overflow = 'auto';
|
||||||
content.style.padding = '16px';
|
content.style.padding = '16px';
|
||||||
|
|
||||||
const nameInput = document.createElement('input');
|
const nameInput = document.createElement('input');
|
||||||
nameInput.placeholder = 'Name';
|
nameInput.placeholder = 'Name';
|
||||||
styleInput(nameInput);
|
styleInput(nameInput);
|
||||||
nameInput.style.width = '110px';
|
nameInput.style.width = '110px';
|
||||||
|
|
||||||
const urlInput = document.createElement('input');
|
const urlInput = document.createElement('input');
|
||||||
urlInput.placeholder = 'Plugin URL';
|
urlInput.placeholder = 'Plugin URL';
|
||||||
styleInput(urlInput);
|
styleInput(urlInput);
|
||||||
urlInput.style.flex = '1';
|
urlInput.style.flex = '1';
|
||||||
|
|
||||||
const addBtn = document.createElement('button');
|
const addBtn = document.createElement('button');
|
||||||
addBtn.textContent = 'Add';
|
addBtn.textContent = 'Add';
|
||||||
addBtn.onclick = () => {
|
addBtn.onclick = () => {
|
||||||
|
|
@ -143,7 +127,6 @@
|
||||||
urlInput.value = '';
|
urlInput.value = '';
|
||||||
renderPanel();
|
renderPanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshAll = document.createElement('button');
|
const refreshAll = document.createElement('button');
|
||||||
refreshAll.textContent = 'Refresh';
|
refreshAll.textContent = 'Refresh';
|
||||||
refreshAll.onclick = () => {
|
refreshAll.onclick = () => {
|
||||||
|
|
@ -152,18 +135,15 @@
|
||||||
if (p.enabled) queuePlugin(p, true);
|
if (p.enabled) queuePlugin(p, true);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
controlsBar.appendChild(nameInput);
|
controlsBar.appendChild(nameInput);
|
||||||
controlsBar.appendChild(urlInput);
|
controlsBar.appendChild(urlInput);
|
||||||
controlsBar.appendChild(addBtn);
|
controlsBar.appendChild(addBtn);
|
||||||
controlsBar.appendChild(refreshAll);
|
controlsBar.appendChild(refreshAll);
|
||||||
|
|
||||||
panel.appendChild(header);
|
panel.appendChild(header);
|
||||||
panel.appendChild(closeBtn);
|
panel.appendChild(closeBtn);
|
||||||
panel.appendChild(controlsBar);
|
panel.appendChild(controlsBar);
|
||||||
panel.appendChild(content);
|
panel.appendChild(content);
|
||||||
document.body.appendChild(panel);
|
document.body.appendChild(panel);
|
||||||
|
|
||||||
enableDrag(panel, header);
|
enableDrag(panel, header);
|
||||||
renderPanel();
|
renderPanel();
|
||||||
}
|
}
|
||||||
|
|
@ -171,34 +151,26 @@
|
||||||
function renderPanel() {
|
function renderPanel() {
|
||||||
const content = document.getElementById('avia-plugins-content');
|
const content = document.getElementById('avia-plugins-content');
|
||||||
if (!content) return;
|
if (!content) return;
|
||||||
|
|
||||||
content.innerHTML = '';
|
content.innerHTML = '';
|
||||||
|
|
||||||
const plugins = getPlugins();
|
const plugins = getPlugins();
|
||||||
const runningSnapshot = { ...runningPlugins };
|
const runningSnapshot = { ...runningPlugins };
|
||||||
const errorSnapshot = { ...pluginErrors };
|
const errorSnapshot = { ...pluginErrors };
|
||||||
|
|
||||||
plugins.forEach((plugin, index) => {
|
plugins.forEach((plugin, index) => {
|
||||||
|
|
||||||
const isRunning = !!runningSnapshot[plugin.url];
|
const isRunning = !!runningSnapshot[plugin.url];
|
||||||
const hasError = !!errorSnapshot[plugin.url];
|
const hasError = !!errorSnapshot[plugin.url];
|
||||||
|
|
||||||
const row = document.createElement('div');
|
const row = document.createElement('div');
|
||||||
row.style.display = 'flex';
|
row.style.display = 'flex';
|
||||||
row.style.justifyContent = 'space-between';
|
row.style.justifyContent = 'space-between';
|
||||||
row.style.alignItems = 'center';
|
row.style.alignItems = 'center';
|
||||||
row.style.marginBottom = '12px';
|
row.style.marginBottom = '12px';
|
||||||
|
|
||||||
const left = document.createElement('div');
|
const left = document.createElement('div');
|
||||||
left.style.display = 'flex';
|
left.style.display = 'flex';
|
||||||
left.style.alignItems = 'center';
|
left.style.alignItems = 'center';
|
||||||
left.style.gap = '10px';
|
left.style.gap = '10px';
|
||||||
|
|
||||||
const statusDot = document.createElement('div');
|
const statusDot = document.createElement('div');
|
||||||
statusDot.style.width = '10px';
|
statusDot.style.width = '10px';
|
||||||
statusDot.style.height = '10px';
|
statusDot.style.height = '10px';
|
||||||
statusDot.style.borderRadius = '50%';
|
statusDot.style.borderRadius = '50%';
|
||||||
|
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
statusDot.style.background = '#ff4d4d';
|
statusDot.style.background = '#ff4d4d';
|
||||||
statusDot.style.boxShadow = '0 0 6px #ff4d4d';
|
statusDot.style.boxShadow = '0 0 6px #ff4d4d';
|
||||||
|
|
@ -208,17 +180,13 @@
|
||||||
} else {
|
} else {
|
||||||
statusDot.style.background = '#777';
|
statusDot.style.background = '#777';
|
||||||
}
|
}
|
||||||
|
|
||||||
const name = document.createElement('div');
|
const name = document.createElement('div');
|
||||||
name.textContent = plugin.name;
|
name.textContent = plugin.name;
|
||||||
|
|
||||||
left.appendChild(statusDot);
|
left.appendChild(statusDot);
|
||||||
left.appendChild(name);
|
left.appendChild(name);
|
||||||
|
|
||||||
const controls = document.createElement('div');
|
const controls = document.createElement('div');
|
||||||
controls.style.display = 'flex';
|
controls.style.display = 'flex';
|
||||||
controls.style.gap = '6px';
|
controls.style.gap = '6px';
|
||||||
|
|
||||||
const toggle = document.createElement('button');
|
const toggle = document.createElement('button');
|
||||||
toggle.textContent = plugin.enabled ? 'Disable' : 'Enable';
|
toggle.textContent = plugin.enabled ? 'Disable' : 'Enable';
|
||||||
toggle.onclick = () => {
|
toggle.onclick = () => {
|
||||||
|
|
@ -228,7 +196,6 @@
|
||||||
else stopPlugin(plugin);
|
else stopPlugin(plugin);
|
||||||
renderPanel();
|
renderPanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
const remove = document.createElement('button');
|
const remove = document.createElement('button');
|
||||||
remove.textContent = '✕';
|
remove.textContent = '✕';
|
||||||
remove.onclick = () => {
|
remove.onclick = () => {
|
||||||
|
|
@ -237,10 +204,8 @@
|
||||||
setPlugins(plugins);
|
setPlugins(plugins);
|
||||||
renderPanel();
|
renderPanel();
|
||||||
};
|
};
|
||||||
|
|
||||||
controls.appendChild(toggle);
|
controls.appendChild(toggle);
|
||||||
controls.appendChild(remove);
|
controls.appendChild(remove);
|
||||||
|
|
||||||
row.appendChild(left);
|
row.appendChild(left);
|
||||||
row.appendChild(controls);
|
row.appendChild(controls);
|
||||||
content.appendChild(row);
|
content.appendChild(row);
|
||||||
|
|
@ -273,34 +238,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function injectButtons() {
|
function injectButtons() {
|
||||||
const appearanceBtn = Array.from(document.querySelectorAll('a'))
|
if (document.getElementById('stoat-fake-plugins')) return;
|
||||||
|
const appearanceBtn = [...document.querySelectorAll('a')]
|
||||||
.find(a => a.textContent.trim() === 'Appearance');
|
.find(a => a.textContent.trim() === 'Appearance');
|
||||||
if (!appearanceBtn) return;
|
if (!appearanceBtn) return;
|
||||||
if (document.getElementById('stoat-fake-plugins')) return;
|
const referenceNode = document.getElementById('stoat-fake-quickcss');
|
||||||
|
if (!referenceNode) return;
|
||||||
const pluginsBtn = appearanceBtn.cloneNode(true);
|
const pluginsBtn = appearanceBtn.cloneNode(true);
|
||||||
pluginsBtn.id = 'stoat-fake-plugins';
|
pluginsBtn.id = 'stoat-fake-plugins';
|
||||||
|
const textNode = [...pluginsBtn.querySelectorAll('div')]
|
||||||
const textNode = Array.from(pluginsBtn.querySelectorAll('div'))
|
|
||||||
.find(d => d.children.length === 0 && d.textContent.trim() === 'Appearance');
|
.find(d => d.children.length === 0 && d.textContent.trim() === 'Appearance');
|
||||||
if (textNode) textNode.textContent = "(Avia) Plugins";
|
if (textNode) textNode.textContent = "(Avia) Plugins";
|
||||||
|
|
||||||
if (typeof setIcon === "function") setIcon(pluginsBtn, "extension");
|
if (typeof setIcon === "function") setIcon(pluginsBtn, "extension");
|
||||||
|
|
||||||
pluginsBtn.addEventListener('click', togglePluginsPanel);
|
pluginsBtn.addEventListener('click', togglePluginsPanel);
|
||||||
|
referenceNode.parentElement.insertBefore(pluginsBtn, referenceNode.nextSibling);
|
||||||
const lastBtn =
|
|
||||||
document.getElementById('stoat-fake-quickcss') ||
|
|
||||||
document.getElementById('stoat-fake-removefont') ||
|
|
||||||
document.getElementById('stoat-fake-loadfont') ||
|
|
||||||
document.getElementById('stoat-fake-stoatserver') ||
|
|
||||||
document.getElementById('stoat-fake-linktree');
|
|
||||||
|
|
||||||
if (lastBtn) {
|
|
||||||
lastBtn.parentElement.insertBefore(pluginsBtn, lastBtn.nextSibling);
|
|
||||||
} else {
|
|
||||||
appearanceBtn.parentElement.insertBefore(pluginsBtn, appearanceBtn.nextSibling);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function waitForBody(callback) {
|
function waitForBody(callback) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue