« get me outta code hell

userstuff: switch hsmusic websites - dotfiles - Miscellaneous configuration files of my personal use
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-29 18:48:14 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-29 18:51:23 -0400
commit67ccfd8d0b37fb7cda52787e78080c439d97b68d (patch)
treee2b8e9d43c657003dbdb650b1624fd5dd4e21492
parentf168193e64793621652a86a3b2f238fe153f5b65 (diff)
userstuff: switch hsmusic websites HEAD main
-rw-r--r--userstuff/hsmusic/Switch HSMusic websites.user.js71
1 files changed, 71 insertions, 0 deletions
diff --git a/userstuff/hsmusic/Switch HSMusic websites.user.js b/userstuff/hsmusic/Switch HSMusic websites.user.js
new file mode 100644
index 0000000..47c2d0b
--- /dev/null
+++ b/userstuff/hsmusic/Switch HSMusic websites.user.js
@@ -0,0 +1,71 @@
+// ==UserScript==
+// @name         Switch HSMusic websites
+// @description  Then try to take over the world!
+// @include      http://localhost:8002/*
+// @match        https://hsmusic.wiki/*
+// @match        https://preview.hsmusic.wiki/*
+// ==/UserScript==
+
+const header = document.getElementById('header');
+const page = header.parentElement;
+const headerContainer = document.createElement('div');
+const customNav = document.createElement('div');
+
+Object.assign(headerContainer.style, {
+    display: 'flex',
+    flexDirection: 'row',
+});
+Object.assign(header.style, {
+    flexGrow: '1',
+});
+Object.assign(customNav.style, {
+    minWidth: '140px',
+    textAlign: 'right',
+});
+
+page.replaceChild(headerContainer, header);
+headerContainer.appendChild(header);
+headerContainer.appendChild(customNav);
+
+const pathname = () => {
+    let p = location.pathname;
+    p = p.replace(/^\/preview-en/, '');
+    return p;
+};
+
+const customNavLink = (text, basenameOrFn) => {
+    const href = typeof basenameOrFn === 'function' ? basenameOrFn() : basenameOrFn + pathname();
+    const link = document.createElement('a');
+    link.appendChild(document.createTextNode(text));
+    link.setAttribute('href', href);
+    customNav.appendChild(link);
+    Object.assign(link.style, {
+        display: 'inline-block',
+        border: '1px dotted var(--primary-color)',
+        borderRadius: '2px',
+        padding: '2px 8px',
+        margin: '2px 2px',
+        background: '#000c',
+    });
+    if (location.href === href) {
+        Object.assign(link.style, {
+            fontWeight: '800',
+            borderStyle: 'solid',
+        });
+    }
+};
+
+customNavLink('L', 'http://localhost:8002');
+customNavLink('P', 'https://preview.hsmusic.wiki');
+customNavLink('R', 'https://hsmusic.wiki');
+
+let match = location.href.match(/album\/([^/]*)/);
+if (match) {
+    customNavLink('G', () => `https://github.com/hsmusic/hsmusic-data/tree/preview/album/${match[1]}.yaml`);
+}
+
+match = location.href.match(/track\/([^/]*)/);
+if (match) {
+    const directory = getComputedStyle(document.body).getPropertyValue('--album-directory');
+    customNavLink('G', () => `https://github.com/hsmusic/hsmusic-data/tree/preview/album/${directory}.yaml`);
+}