35 lines
840 B
JavaScript
35 lines
840 B
JavaScript
const DEFAULT_SETTINGS = {
|
|
plexUrl: "https://app.plex.tv",
|
|
skipIntro: true,
|
|
skipCredits: true,
|
|
introDelaySeconds: 0,
|
|
creditsDelaySeconds: 0
|
|
};
|
|
|
|
function clampDelaySeconds(value) {
|
|
const num = Number(value);
|
|
if (!Number.isFinite(num)) return 0;
|
|
return Math.min(30, Math.max(0, Math.round(num)));
|
|
}
|
|
|
|
function normalizePlexUrl(input) {
|
|
let value = (input || "").trim();
|
|
if (!value) return DEFAULT_SETTINGS.plexUrl;
|
|
if (!/^https?:\/\//i.test(value)) value = "http://" + value;
|
|
return value;
|
|
}
|
|
|
|
function getHostFromUrl(urlString) {
|
|
try {
|
|
return new URL(urlString).hostname;
|
|
} catch (e) {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function hostMatchesConfig(currentHostname, configuredUrl) {
|
|
const configuredHost = getHostFromUrl(configuredUrl);
|
|
if (!configuredHost) return false;
|
|
return currentHostname === configuredHost;
|
|
}
|