mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 09:09:30 -07:00
shorten permalinks close #206
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import { text } from './utils/fetch.mjs';
|
||||
import Setting from './utils/setting.mjs';
|
||||
import { registerHiddenSetting } from './share.mjs';
|
||||
|
||||
let playlist;
|
||||
let currentTrack = 0;
|
||||
@@ -33,9 +32,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// get the playlist
|
||||
getMedia();
|
||||
|
||||
// register the volume setting
|
||||
registerHiddenSetting(mediaVolume.elemId, mediaVolume);
|
||||
});
|
||||
|
||||
const scanMusicDirectory = async () => {
|
||||
@@ -246,6 +242,7 @@ const mediaVolume = new Setting('mediaVolume', {
|
||||
[0.25, '25%'],
|
||||
],
|
||||
changeAction: setVolume,
|
||||
visible: false,
|
||||
});
|
||||
|
||||
const initializePlayer = () => {
|
||||
|
||||
@@ -273,6 +273,7 @@ const init = () => {
|
||||
['medium', 'Medium (2x)'],
|
||||
['thick', 'Thick (3x)'],
|
||||
],
|
||||
visible: false,
|
||||
});
|
||||
settings.units = new Setting('units', {
|
||||
name: 'Units',
|
||||
@@ -322,7 +323,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
const settingHtml = Object.values(settings).map((setting) => {
|
||||
if (hiddenSettings.includes(setting.shortName)) {
|
||||
// setting is hidden, register it
|
||||
registerHiddenSetting(setting.elemId, setting);
|
||||
registerHiddenSetting(setting.shortName, setting);
|
||||
return false;
|
||||
}
|
||||
// generate HTML for setting
|
||||
@@ -340,7 +341,6 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
} else if (modeSelect) {
|
||||
modeSelect.style.display = 'none';
|
||||
}
|
||||
registerHiddenSetting('settings-scanLineMode-select', settings.scanLineMode);
|
||||
});
|
||||
|
||||
export default settings;
|
||||
|
||||
@@ -25,22 +25,28 @@ const createLink = async (e) => {
|
||||
const queryStringElements = {};
|
||||
|
||||
elemForEach('input[type=checkbox]', (elem) => {
|
||||
if (elem?.id) {
|
||||
queryStringElements[elem.id] = elem?.checked ?? false;
|
||||
// use name, and fallback to id (older prefix/suffix permalinks)
|
||||
const key = elem?.name ?? elem?.id;
|
||||
if (key) {
|
||||
queryStringElements[key] = elem?.checked ?? false;
|
||||
}
|
||||
});
|
||||
|
||||
// get all select boxes
|
||||
elemForEach('select', (elem) => {
|
||||
if (elem?.id) {
|
||||
queryStringElements[elem.id] = encodeURIComponent(elem?.value ?? '');
|
||||
// use name, and fallback to id (older prefix/suffix permalinks)
|
||||
const key = elem?.name ?? elem?.id;
|
||||
if (key) {
|
||||
queryStringElements[key] = encodeURIComponent(elem?.value ?? '');
|
||||
}
|
||||
});
|
||||
|
||||
// get all text boxes
|
||||
elemForEach('input[type=text]', ((elem) => {
|
||||
if (elem?.id) {
|
||||
queryStringElements[elem.id] = elem?.value ?? 0;
|
||||
// use name, and fallback to id (older prefix/suffix permalinks)
|
||||
const key = elem?.name ?? elem?.id;
|
||||
if (key && key !== '') {
|
||||
queryStringElements[key] = elem?.value ?? 0;
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
@@ -41,7 +41,9 @@ class Setting {
|
||||
this.elemId = `settings-${shortName}-${this.type}`;
|
||||
|
||||
// get value from url
|
||||
const urlValue = parseQueryString()?.[this.elemId];
|
||||
// includes a fallback to the older prefix/suffix version
|
||||
const queryString = parseQueryString();
|
||||
const urlValue = queryString?.[shortName] ?? queryString?.[this.elemId];
|
||||
let urlState;
|
||||
if (this.type === 'checkbox' && urlValue !== undefined) {
|
||||
urlState = urlValue === 'true';
|
||||
@@ -92,7 +94,7 @@ class Setting {
|
||||
|
||||
const select = document.createElement('select');
|
||||
select.id = `settings-${this.shortName}-select`;
|
||||
select.name = `settings-${this.shortName}-select`;
|
||||
select.name = this.shortName;
|
||||
select.addEventListener('change', (e) => this.selectChange(e));
|
||||
|
||||
this.values.forEach(([value, text]) => {
|
||||
@@ -125,7 +127,7 @@ class Setting {
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.value = true;
|
||||
checkbox.id = `settings-${this.shortName}-checkbox`;
|
||||
checkbox.name = `settings-${this.shortName}-checkbox`;
|
||||
checkbox.name = this.shortName;
|
||||
checkbox.checked = this.myValue;
|
||||
checkbox.addEventListener('change', (e) => this.checkboxChange(e));
|
||||
const span = document.createElement('span');
|
||||
@@ -148,14 +150,14 @@ class Setting {
|
||||
textInput.type = 'text';
|
||||
textInput.value = this.myValue;
|
||||
textInput.id = `settings-${this.shortName}-string`;
|
||||
textInput.name = `settings-${this.shortName}-string`;
|
||||
textInput.name = this.shortName;
|
||||
textInput.placeholder = this.placeholder;
|
||||
// set button
|
||||
const setButton = document.createElement('input');
|
||||
setButton.type = 'button';
|
||||
setButton.value = 'Set';
|
||||
setButton.id = `settings-${this.shortName}-button`;
|
||||
setButton.name = `settings-${this.shortName}-button`;
|
||||
setButton.name = this.shortName;
|
||||
setButton.addEventListener('click', () => {
|
||||
this.stringChange({ target: { value: textInput.value } });
|
||||
});
|
||||
|
||||
@@ -55,8 +55,9 @@ class WeatherDisplay {
|
||||
// no checkbox if progress
|
||||
if (this.elemId === 'progress') return false;
|
||||
|
||||
// get url provided state
|
||||
const urlValue = parseQueryString()?.[`${this.elemId}-checkbox`];
|
||||
// get url provided state, and fall back to the older suffix naming convention
|
||||
const queryString = parseQueryString();
|
||||
const urlValue = queryString?.[this.elemId] ?? queryString?.[`${this.elemId}-checkbox`];
|
||||
let urlState;
|
||||
if (urlValue !== undefined) {
|
||||
urlState = urlValue === 'true';
|
||||
@@ -78,7 +79,7 @@ class WeatherDisplay {
|
||||
checkbox.type = 'checkbox';
|
||||
checkbox.value = true;
|
||||
checkbox.id = `${this.elemId}-checkbox`;
|
||||
checkbox.name = `${this.elemId}-checkbox`;
|
||||
checkbox.name = this.elemId;
|
||||
checkbox.checked = this.isEnabled;
|
||||
checkbox.addEventListener('change', (e) => this.checkboxChange(e));
|
||||
const span = document.createElement('span');
|
||||
|
||||
Reference in New Issue
Block a user