forked from SpoTUI/SpoTUI
feat(theme): add animation toggle command
This commit is contained in:
@@ -72,6 +72,7 @@ Type `help` in the SpoTUI command bar to see a list of available commands.
|
|||||||
|
|
||||||
| Command | Description |
|
| Command | Description |
|
||||||
| -----------------------| -------------------------------|
|
| -----------------------| -------------------------------|
|
||||||
|
| `tui -l -a <on/off>` | Toggle ASCII animation |
|
||||||
| `tui -wp <url> [-o <opacity>]` | Set wallpaper (opacity 0-1) |
|
| `tui -wp <url> [-o <opacity>]` | Set wallpaper (opacity 0-1) |
|
||||||
| `tui -wp off` | Remove wallpaper |
|
| `tui -wp off` | Remove wallpaper |
|
||||||
| `playlist` / `list` | Open playlist viewer |
|
| `playlist` / `list` | Open playlist viewer |
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
(function () {
|
(function () {
|
||||||
|
const ANIMATION_KEY = "spotui:ascii-animation";
|
||||||
|
|
||||||
const style = `
|
const style = `
|
||||||
#spotui-tui {
|
#spotui-tui {
|
||||||
@@ -492,6 +493,19 @@ function getCharColor(row, col, totalRows, totalCols) {
|
|||||||
|
|
||||||
let asciiAnimationInitialized = false;
|
let asciiAnimationInitialized = false;
|
||||||
let asciiCharData = [];
|
let asciiCharData = [];
|
||||||
|
let asciiEnabled = true;
|
||||||
|
|
||||||
|
function resetGrid() {
|
||||||
|
asciiCharData.forEach(({ el, original, color }) => {
|
||||||
|
el.textContent = original;
|
||||||
|
el.style.color = color;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopAsciiAnimation() {
|
||||||
|
asciiEnabled = false;
|
||||||
|
resetGrid();
|
||||||
|
}
|
||||||
|
|
||||||
function initAsciiAnimation() {
|
function initAsciiAnimation() {
|
||||||
if (asciiAnimationInitialized) return;
|
if (asciiAnimationInitialized) return;
|
||||||
@@ -544,13 +558,6 @@ function initAsciiAnimation() {
|
|||||||
|
|
||||||
asciiCharData = charData;
|
asciiCharData = charData;
|
||||||
|
|
||||||
function resetGrid() {
|
|
||||||
charData.forEach(({ el, original, color }) => {
|
|
||||||
el.textContent = original;
|
|
||||||
el.style.color = color;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function getRowSpans(rowIdx) {
|
function getRowSpans(rowIdx) {
|
||||||
return rowSpansCache[rowIdx] || [];
|
return rowSpansCache[rowIdx] || [];
|
||||||
}
|
}
|
||||||
@@ -877,8 +884,13 @@ function initAsciiAnimation() {
|
|||||||
|
|
||||||
async function runLoop() {
|
async function runLoop() {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
if (!asciiEnabled || localStorage.getItem(ANIMATION_KEY) === "off") {
|
||||||
|
await sleep(500);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const shuffled = shuffleArray([...stageFunctions]);
|
const shuffled = shuffleArray([...stageFunctions]);
|
||||||
for (const stageFn of shuffled) {
|
for (const stageFn of shuffled) {
|
||||||
|
if (!asciiEnabled || localStorage.getItem(ANIMATION_KEY) === "off") break;
|
||||||
await stageFn();
|
await stageFn();
|
||||||
await sleep(700 + Math.random() * 400);
|
await sleep(700 + Math.random() * 400);
|
||||||
}
|
}
|
||||||
@@ -1115,17 +1127,16 @@ async function execute(cmd) {
|
|||||||
const argText = args.join(" ").trim();
|
const argText = args.join(" ").trim();
|
||||||
|
|
||||||
if (command === "tui") {
|
if (command === "tui") {
|
||||||
if (args[0] === "-wp") {
|
if (args.includes("-l") || args.includes("-a")) {
|
||||||
const url = args[1];
|
const state = args[args.length - 1];
|
||||||
if (url === "off") {
|
if (state === "off") {
|
||||||
const wp = document.getElementById("spotui-wallpaper");
|
asciiEnabled = false;
|
||||||
if (wp) wp.remove();
|
resetGrid();
|
||||||
try { localStorage.removeItem(WP_URL_KEY); localStorage.removeItem(WP_OPACITY_KEY); } catch {}
|
try { localStorage.setItem(ANIMATION_KEY, "off"); console.log("SpoTUI: Saved off"); } catch(e) { console.error("SpoTUI: Save failed", e); }
|
||||||
return;
|
} else if (state === "on") {
|
||||||
|
asciiEnabled = true;
|
||||||
|
try { localStorage.removeItem(ANIMATION_KEY); console.log("SpoTUI: Removed key"); } catch(e) { console.error("SpoTUI: Remove failed", e); }
|
||||||
}
|
}
|
||||||
const opacityIdx = args.indexOf("-o");
|
|
||||||
const opacity = (opacityIdx !== -1 && args[opacityIdx + 1]) ? args[opacityIdx + 1] : "1";
|
|
||||||
setWallpaper(url, opacity);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@@ -1204,6 +1215,7 @@ let helpPanelOpen = false;
|
|||||||
let aboutPanelOpen = false;
|
let aboutPanelOpen = false;
|
||||||
|
|
||||||
const COMMAND_LIST = [
|
const COMMAND_LIST = [
|
||||||
|
{ cmd: "tui -l -a <on/off>", desc: "Toggle ASCII animation" },
|
||||||
{ cmd: "tui -wp <url> [-o <opacity>]", desc: "Set wallpaper (opacity 0-1)" },
|
{ cmd: "tui -wp <url> [-o <opacity>]", desc: "Set wallpaper (opacity 0-1)" },
|
||||||
{ cmd: "tui -wp off", desc: "Remove wallpaper" },
|
{ cmd: "tui -wp off", desc: "Remove wallpaper" },
|
||||||
{ cmd: "playlist / list", desc: "Open playlist viewer" },
|
{ cmd: "playlist / list", desc: "Open playlist viewer" },
|
||||||
@@ -1805,10 +1817,8 @@ try {
|
|||||||
if (localStorage.getItem(LYRICS_STORAGE_KEY) === "1") {
|
if (localStorage.getItem(LYRICS_STORAGE_KEY) === "1") {
|
||||||
setTimeout(() => openLyricsPanel(), 2000);
|
setTimeout(() => openLyricsPanel(), 2000);
|
||||||
}
|
}
|
||||||
const savedWp = localStorage.getItem(WP_URL_KEY);
|
if (localStorage.getItem(WP_URL_KEY)) {
|
||||||
const savedOpacity = localStorage.getItem(WP_OPACITY_KEY) || "1";
|
setTimeout(() => setWallpaper(localStorage.getItem(WP_URL_KEY), localStorage.getItem(WP_OPACITY_KEY) || "1", false), 1500);
|
||||||
if (savedWp) {
|
|
||||||
setTimeout(() => setWallpaper(savedWp, savedOpacity, false), 1500);
|
|
||||||
}
|
}
|
||||||
} catch { }
|
} catch { }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user