mirror of
https://github.com/SoPat712/videospeed.git
synced 2026-04-24 21:42:53 -04:00
Compare commits
30 Commits
dev
...
v5.1.7.0-beta.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
25d3acf576
|
|||
|
8b9e4bea1d
|
|||
|
8c94cc2088
|
|||
|
19d3af02a2
|
|||
|
306e0e3ea0
|
|||
|
1536c13c3e
|
|||
|
939ee08466
|
|||
|
fad0c49e65
|
|||
|
76a7b933bb
|
|||
|
edd997037a
|
|||
|
e34ec17f33
|
|||
|
53f66f1eeb
|
|||
|
3275d1f322
|
|||
|
8eb3901121
|
|||
|
6bf48fa479
|
|||
|
3a583ce3b8
|
|||
|
5c20d7ae0b
|
|||
|
b0498cd1d7
|
|||
|
85215ae54b
|
|||
|
9f8c235cea
|
|||
|
597c7a8af5
|
|||
|
d215ad4224
|
|||
|
df18e638c2
|
|||
|
9ff3ce4f74
|
|||
|
91dc47f5a8
|
|||
|
36a60bbe34
|
|||
|
3bcb36f6d0
|
|||
|
2747c15924
|
|||
|
5e7d5d6d21
|
|||
|
38174a2a76
|
+124
-55
@@ -1,5 +1,55 @@
|
|||||||
// Import/Export functionality for Video Speed Controller settings
|
// Import/Export functionality for Video Speed Controller settings
|
||||||
|
|
||||||
|
const EXPORTABLE_LOCAL_SETTINGS_KEYS = ["customButtonIcons"];
|
||||||
|
|
||||||
|
function getExportableLocalSettings(localStorage) {
|
||||||
|
const exportable = {};
|
||||||
|
const customButtonIcons =
|
||||||
|
localStorage &&
|
||||||
|
localStorage.customButtonIcons &&
|
||||||
|
typeof localStorage.customButtonIcons === "object" &&
|
||||||
|
!Array.isArray(localStorage.customButtonIcons)
|
||||||
|
? localStorage.customButtonIcons
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (customButtonIcons) {
|
||||||
|
exportable.customButtonIcons = customButtonIcons;
|
||||||
|
}
|
||||||
|
|
||||||
|
return exportable;
|
||||||
|
}
|
||||||
|
|
||||||
|
function replaceImportableLocalSettings(localSettings, callback) {
|
||||||
|
chrome.storage.local.remove(EXPORTABLE_LOCAL_SETTINGS_KEYS, function () {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
showStatus(
|
||||||
|
"Error: Failed to clear local icon overrides - " +
|
||||||
|
chrome.runtime.lastError.message,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!localSettings || Object.keys(localSettings).length === 0) {
|
||||||
|
callback();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chrome.storage.local.set(localSettings, function () {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
showStatus(
|
||||||
|
"Error: Failed to save local icon overrides - " +
|
||||||
|
chrome.runtime.lastError.message,
|
||||||
|
true
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
callback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function generateBackupFilename() {
|
function generateBackupFilename() {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const year = now.getFullYear();
|
const year = now.getFullYear();
|
||||||
@@ -11,30 +61,69 @@ function generateBackupFilename() {
|
|||||||
return `speeder-backup_${year}-${month}-${day}_${hours}.${minutes}.${seconds}.json`;
|
return `speeder-backup_${year}-${month}-${day}_${hours}.${minutes}.${seconds}.json`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBackupManifestVersion() {
|
||||||
|
var manifest = chrome.runtime.getManifest();
|
||||||
|
return manifest && manifest.version ? manifest.version : "unknown";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getExportableSyncSettings(syncStorage) {
|
||||||
|
return vscBuildStoredSettingsDiff(vscExpandStoredSettings(syncStorage));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getImportableSyncSettings(backup, rawSettings) {
|
||||||
|
var importable = vscClonePlainData(rawSettings) || {};
|
||||||
|
|
||||||
|
if (
|
||||||
|
backup &&
|
||||||
|
backup.siteRulesFormat &&
|
||||||
|
importable.siteRulesFormat === undefined
|
||||||
|
) {
|
||||||
|
importable.siteRulesFormat = backup.siteRulesFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
backup &&
|
||||||
|
backup.siteRulesMeta &&
|
||||||
|
importable.siteRulesMeta === undefined
|
||||||
|
) {
|
||||||
|
importable.siteRulesMeta = backup.siteRulesMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vscExpandStoredSettings(importable);
|
||||||
|
}
|
||||||
|
|
||||||
function exportSettings() {
|
function exportSettings() {
|
||||||
chrome.storage.sync.get(null, function (storage) {
|
chrome.storage.sync.get(null, function (storage) {
|
||||||
chrome.storage.local.get(null, function (localStorage) {
|
chrome.storage.local.get(
|
||||||
const backup = {
|
EXPORTABLE_LOCAL_SETTINGS_KEYS,
|
||||||
version: "1.1",
|
function (localStorage) {
|
||||||
exportDate: new Date().toISOString(),
|
const localSettings = getExportableLocalSettings(localStorage);
|
||||||
settings: storage,
|
const syncSettings = getExportableSyncSettings(storage);
|
||||||
localSettings: localStorage || {}
|
const backup = {
|
||||||
};
|
version: getBackupManifestVersion(),
|
||||||
|
exportDate: new Date().toISOString(),
|
||||||
|
settings: syncSettings
|
||||||
|
};
|
||||||
|
|
||||||
const dataStr = JSON.stringify(backup, null, 2);
|
if (Object.keys(localSettings).length > 0) {
|
||||||
const blob = new Blob([dataStr], { type: "application/json" });
|
backup.localSettings = localSettings;
|
||||||
const url = URL.createObjectURL(blob);
|
}
|
||||||
|
|
||||||
const link = document.createElement("a");
|
const dataStr = JSON.stringify(backup, null, 2);
|
||||||
link.href = url;
|
const blob = new Blob([dataStr], { type: "application/json" });
|
||||||
link.download = generateBackupFilename();
|
const url = URL.createObjectURL(blob);
|
||||||
document.body.appendChild(link);
|
|
||||||
link.click();
|
|
||||||
document.body.removeChild(link);
|
|
||||||
URL.revokeObjectURL(url);
|
|
||||||
|
|
||||||
showStatus("Settings exported successfully");
|
const link = document.createElement("a");
|
||||||
});
|
link.href = url;
|
||||||
|
link.download = generateBackupFilename();
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
URL.revokeObjectURL(url);
|
||||||
|
|
||||||
|
showStatus("Settings exported successfully");
|
||||||
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,9 +144,9 @@ function importSettings() {
|
|||||||
|
|
||||||
// Detect backup format: check for 'settings' wrapper or raw storage keys
|
// Detect backup format: check for 'settings' wrapper or raw storage keys
|
||||||
if (backup.settings && typeof backup.settings === "object") {
|
if (backup.settings && typeof backup.settings === "object") {
|
||||||
settingsToImport = backup.settings;
|
settingsToImport = getImportableSyncSettings(backup, backup.settings);
|
||||||
} else if (typeof backup === "object" && (backup.keyBindings || backup.rememberSpeed !== undefined)) {
|
} else if (typeof backup === "object" && (backup.keyBindings || backup.rememberSpeed !== undefined)) {
|
||||||
settingsToImport = backup; // Raw storage object
|
settingsToImport = getImportableSyncSettings(backup, backup);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settingsToImport) {
|
if (!settingsToImport) {
|
||||||
@@ -65,49 +154,29 @@ function importSettings() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var localToImport =
|
var localToImport = getExportableLocalSettings(backup.localSettings);
|
||||||
backup.localSettings && typeof backup.localSettings === "object"
|
|
||||||
? backup.localSettings
|
|
||||||
: null;
|
|
||||||
|
|
||||||
function afterLocalImport() {
|
function afterLocalImport() {
|
||||||
chrome.storage.sync.clear(function () {
|
persistManagedSyncSettings(settingsToImport, function (error) {
|
||||||
chrome.storage.sync.set(settingsToImport, function () {
|
if (error) {
|
||||||
if (chrome.runtime.lastError) {
|
|
||||||
showStatus(
|
|
||||||
"Error: Failed to save imported settings - " +
|
|
||||||
chrome.runtime.lastError.message,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
showStatus("Settings imported successfully. Reloading...");
|
|
||||||
setTimeout(function () {
|
|
||||||
if (typeof restore_options === "function") {
|
|
||||||
restore_options();
|
|
||||||
} else {
|
|
||||||
location.reload();
|
|
||||||
}
|
|
||||||
}, 500);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localToImport && Object.keys(localToImport).length > 0) {
|
|
||||||
chrome.storage.local.set(localToImport, function () {
|
|
||||||
if (chrome.runtime.lastError) {
|
|
||||||
showStatus(
|
showStatus(
|
||||||
"Error: Failed to save local extension data - " +
|
"Error: Failed to save imported settings - " + error.message,
|
||||||
chrome.runtime.lastError.message,
|
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
afterLocalImport();
|
showStatus("Settings imported successfully. Reloading...");
|
||||||
|
setTimeout(function () {
|
||||||
|
if (typeof restore_options === "function") {
|
||||||
|
restore_options();
|
||||||
|
} else {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
}, 500);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
afterLocalImport();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
replaceImportableLocalSettings(localToImport, afterLocalImport);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
showStatus("Error: Failed to parse backup file - " + err.message, true);
|
showStatus("Error: Failed to parse backup file - " + err.message, true);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var isUserSeek = false; // Track if seek was user-initiated
|
var isUserSeek = false; // Track if seek was user-initiated
|
||||||
var lastToggleSpeed = {}; // Store last toggle speeds per video
|
var lastToggleSpeed = {}; // Store last toggle speeds per video
|
||||||
|
var sharedSettingsDefaults = vscGetSettingsDefaults();
|
||||||
|
|
||||||
function getPrimaryVideoElement() {
|
function getPrimaryVideoElement() {
|
||||||
if (!tc.mediaElements || tc.mediaElements.length === 0) return null;
|
if (!tc.mediaElements || tc.mediaElements.length === 0) return null;
|
||||||
@@ -12,31 +13,37 @@ function getPrimaryVideoElement() {
|
|||||||
|
|
||||||
var tc = {
|
var tc = {
|
||||||
settings: {
|
settings: {
|
||||||
lastSpeed: 1.0,
|
lastSpeed: sharedSettingsDefaults.lastSpeed,
|
||||||
enabled: true,
|
enabled: sharedSettingsDefaults.enabled,
|
||||||
speeds: {},
|
speeds: {},
|
||||||
displayKeyCode: 86,
|
displayKeyCode: sharedSettingsDefaults.displayKeyCode,
|
||||||
rememberSpeed: false,
|
rememberSpeed: sharedSettingsDefaults.rememberSpeed,
|
||||||
forceLastSavedSpeed: false,
|
forceLastSavedSpeed: sharedSettingsDefaults.forceLastSavedSpeed,
|
||||||
audioBoolean: false,
|
audioBoolean: sharedSettingsDefaults.audioBoolean,
|
||||||
startHidden: false,
|
startHidden: sharedSettingsDefaults.startHidden,
|
||||||
hideWithYouTubeControls: false,
|
hideWithYouTubeControls: sharedSettingsDefaults.hideWithYouTubeControls,
|
||||||
hideWithControls: false,
|
hideWithControls: sharedSettingsDefaults.hideWithControls,
|
||||||
hideWithControlsTimer: 2.0,
|
hideWithControlsTimer: sharedSettingsDefaults.hideWithControlsTimer,
|
||||||
controllerLocation: "top-left",
|
controllerLocation: sharedSettingsDefaults.controllerLocation,
|
||||||
controllerOpacity: 0.3,
|
controllerOpacity: sharedSettingsDefaults.controllerOpacity,
|
||||||
controllerMarginTop: 0,
|
controllerMarginTop: sharedSettingsDefaults.controllerMarginTop,
|
||||||
controllerMarginRight: 0,
|
controllerMarginRight: sharedSettingsDefaults.controllerMarginRight,
|
||||||
controllerMarginBottom: 65,
|
controllerMarginBottom: sharedSettingsDefaults.controllerMarginBottom,
|
||||||
controllerMarginLeft: 0,
|
controllerMarginLeft: sharedSettingsDefaults.controllerMarginLeft,
|
||||||
keyBindings: [],
|
keyBindings: Array.isArray(sharedSettingsDefaults.keyBindings)
|
||||||
siteRules: [],
|
? sharedSettingsDefaults.keyBindings.slice()
|
||||||
controllerButtons: ["rewind", "slower", "faster", "advance", "display"],
|
: [],
|
||||||
|
siteRules: Array.isArray(sharedSettingsDefaults.siteRules)
|
||||||
|
? sharedSettingsDefaults.siteRules.slice()
|
||||||
|
: [],
|
||||||
|
controllerButtons: Array.isArray(sharedSettingsDefaults.controllerButtons)
|
||||||
|
? sharedSettingsDefaults.controllerButtons.slice()
|
||||||
|
: ["rewind", "slower", "faster", "advance", "display"],
|
||||||
defaultLogLevel: 3,
|
defaultLogLevel: 3,
|
||||||
logLevel: 3,
|
logLevel: 3,
|
||||||
enableSubtitleNudge: true, // Enabled by default, but only activates on YouTube
|
enableSubtitleNudge: sharedSettingsDefaults.enableSubtitleNudge,
|
||||||
subtitleNudgeInterval: 50, // Default 50ms balances subtitle tracking with CPU cost
|
subtitleNudgeInterval: sharedSettingsDefaults.subtitleNudgeInterval,
|
||||||
subtitleNudgeAmount: 0.001,
|
subtitleNudgeAmount: sharedSettingsDefaults.subtitleNudgeAmount,
|
||||||
customButtonIcons: {}
|
customButtonIcons: {}
|
||||||
},
|
},
|
||||||
mediaElements: [],
|
mediaElements: [],
|
||||||
@@ -184,6 +191,8 @@ function createDefaultBinding(action, key, keyCode, value) {
|
|||||||
action: action,
|
action: action,
|
||||||
key: key,
|
key: key,
|
||||||
keyCode: keyCode,
|
keyCode: keyCode,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
value: value,
|
value: value,
|
||||||
force: false,
|
force: false,
|
||||||
predefined: true
|
predefined: true
|
||||||
@@ -220,7 +229,7 @@ function defaultKeyBindings(storage) {
|
|||||||
"reset",
|
"reset",
|
||||||
"R",
|
"R",
|
||||||
Number(storage.resetKeyCode) || 82,
|
Number(storage.resetKeyCode) || 82,
|
||||||
1.0
|
0
|
||||||
),
|
),
|
||||||
createDefaultBinding(
|
createDefaultBinding(
|
||||||
"fast",
|
"fast",
|
||||||
@@ -429,6 +438,165 @@ function applyControllerLocation(videoController, location) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getYouTubeAutoHidePlayer(video) {
|
||||||
|
if (!video || !isOnYouTube()) return null;
|
||||||
|
|
||||||
|
return video.closest(".html5-video-player") || video.closest("#movie_player");
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAutoHideModeForVideo(video) {
|
||||||
|
if (!tc.settings.hideWithControls) return "off";
|
||||||
|
return getYouTubeAutoHidePlayer(video) ? "youtube" : "generic";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getControllerMountParent(video, parentHint) {
|
||||||
|
var parentEl = parentHint || (video && (video.parentElement || video.parentNode));
|
||||||
|
if (!parentEl) return null;
|
||||||
|
|
||||||
|
switch (true) {
|
||||||
|
case location.hostname == "www.amazon.com":
|
||||||
|
case location.hostname == "www.reddit.com":
|
||||||
|
case /hbogo\./.test(location.hostname):
|
||||||
|
return parentEl.parentElement || parentEl;
|
||||||
|
case location.hostname == "www.facebook.com":
|
||||||
|
var facebookParent = parentEl;
|
||||||
|
for (
|
||||||
|
var depth = 0;
|
||||||
|
depth < 8 && facebookParent && facebookParent.parentElement;
|
||||||
|
depth++
|
||||||
|
) {
|
||||||
|
facebookParent = facebookParent.parentElement;
|
||||||
|
}
|
||||||
|
return facebookParent || parentEl;
|
||||||
|
case location.hostname == "tv.apple.com":
|
||||||
|
var root = parentEl.getRootNode();
|
||||||
|
var scrim = root && root.querySelector ? root.querySelector(".scrim") : null;
|
||||||
|
return scrim || parentEl;
|
||||||
|
case location.hostname == "www.youtube.com":
|
||||||
|
case location.hostname == "m.youtube.com":
|
||||||
|
case location.hostname == "music.youtube.com":
|
||||||
|
return getYouTubeAutoHidePlayer(video) || parentEl;
|
||||||
|
default:
|
||||||
|
return parentEl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function getControllerBehaviorSignature(video) {
|
||||||
|
return JSON.stringify({
|
||||||
|
startHidden: Boolean(tc.settings.startHidden),
|
||||||
|
hideWithControls: Boolean(tc.settings.hideWithControls),
|
||||||
|
hideWithControlsTimer: Number(tc.settings.hideWithControlsTimer),
|
||||||
|
controllerLocation: normalizeControllerLocation(tc.settings.controllerLocation),
|
||||||
|
controllerOpacity: Number(tc.settings.controllerOpacity),
|
||||||
|
controllerMarginTop: normalizeControllerMarginPx(tc.settings.controllerMarginTop, 0),
|
||||||
|
controllerMarginBottom: normalizeControllerMarginPx(
|
||||||
|
tc.settings.controllerMarginBottom,
|
||||||
|
0
|
||||||
|
),
|
||||||
|
controllerButtons: Array.isArray(tc.settings.controllerButtons)
|
||||||
|
? tc.settings.controllerButtons.slice()
|
||||||
|
: [],
|
||||||
|
enableSubtitleNudge: Boolean(tc.settings.enableSubtitleNudge),
|
||||||
|
subtitleNudgeInterval: Number(tc.settings.subtitleNudgeInterval),
|
||||||
|
autoHideMode: getAutoHideModeForVideo(video),
|
||||||
|
mediaTag: video && video.tagName ? video.tagName : ""
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function rebuildControllerForVideo(video, parentHint, reason) {
|
||||||
|
if (!video) return null;
|
||||||
|
|
||||||
|
var previous = video.vsc || null;
|
||||||
|
var preservedState = previous
|
||||||
|
? {
|
||||||
|
mark: previous.mark,
|
||||||
|
resetToggleArmed: previous.resetToggleArmed === true,
|
||||||
|
subtitleNudgeEnabledOverride: previous.subtitleNudgeEnabledOverride,
|
||||||
|
userHidden:
|
||||||
|
Boolean(previous.div) &&
|
||||||
|
previous.div.classList.contains("vsc-hidden")
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (previous) {
|
||||||
|
previous.remove();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!video.isConnected || !hasUsableMediaSource(video)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var nextController = new tc.videoController(
|
||||||
|
video,
|
||||||
|
parentHint || video.parentElement || video.parentNode
|
||||||
|
);
|
||||||
|
if (!nextController) return null;
|
||||||
|
|
||||||
|
if (preservedState) {
|
||||||
|
nextController.mark = preservedState.mark;
|
||||||
|
nextController.resetToggleArmed = preservedState.resetToggleArmed;
|
||||||
|
|
||||||
|
if (
|
||||||
|
typeof preservedState.subtitleNudgeEnabledOverride === "boolean"
|
||||||
|
) {
|
||||||
|
nextController.subtitleNudgeEnabledOverride =
|
||||||
|
preservedState.subtitleNudgeEnabledOverride;
|
||||||
|
updateSubtitleNudgeIndicator(video);
|
||||||
|
if (!preservedState.subtitleNudgeEnabledOverride) {
|
||||||
|
nextController.stopSubtitleNudge();
|
||||||
|
} else if (!video.paused && video.playbackRate !== 1.0) {
|
||||||
|
nextController.startSubtitleNudge();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (preservedState.userHidden && nextController.div) {
|
||||||
|
nextController.div.classList.add("vsc-hidden");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log("Rebuilt controller: " + (reason || "refresh"), 4);
|
||||||
|
return nextController;
|
||||||
|
}
|
||||||
|
|
||||||
|
function refreshManagedController(video, parentHint) {
|
||||||
|
if (!video || !video.vsc) return null;
|
||||||
|
if (!video.isConnected) {
|
||||||
|
removeController(video);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var controller = video.vsc;
|
||||||
|
controller.parent = video.parentElement || parentHint || controller.parent;
|
||||||
|
|
||||||
|
var expectedMountParent = getControllerMountParent(video, controller.parent);
|
||||||
|
var nextSignature = getControllerBehaviorSignature(video);
|
||||||
|
var wrapper = controller.div;
|
||||||
|
var needsRebuild =
|
||||||
|
!wrapper ||
|
||||||
|
!wrapper.isConnected ||
|
||||||
|
!expectedMountParent ||
|
||||||
|
wrapper.parentNode !== expectedMountParent ||
|
||||||
|
controller.behaviorSignature !== nextSignature;
|
||||||
|
|
||||||
|
if (needsRebuild) {
|
||||||
|
return rebuildControllerForVideo(
|
||||||
|
video,
|
||||||
|
controller.parent,
|
||||||
|
"DOM/source/site-rule change"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
controller.mountParent = expectedMountParent;
|
||||||
|
controller.behaviorSignature = nextSignature;
|
||||||
|
applyControllerLocation(controller, tc.settings.controllerLocation);
|
||||||
|
var controllerEl = getControllerElement(controller);
|
||||||
|
if (controllerEl) {
|
||||||
|
controllerEl.style.opacity = String(tc.settings.controllerOpacity);
|
||||||
|
}
|
||||||
|
updateSubtitleNudgeIndicator(video);
|
||||||
|
return controller;
|
||||||
|
}
|
||||||
|
|
||||||
function captureSiteRuleBase() {
|
function captureSiteRuleBase() {
|
||||||
tc.siteRuleBase = {
|
tc.siteRuleBase = {
|
||||||
startHidden: tc.settings.startHidden,
|
startHidden: tc.settings.startHidden,
|
||||||
@@ -910,8 +1078,8 @@ function applySourceTransitionPolicy(video, forceUpdate) {
|
|||||||
setSpeed(video, desiredSpeed, false, false);
|
setSpeed(video, desiredSpeed, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Same-tab SPA (e.g. YouTube watch → Shorts): URL can change while remember-speed
|
// Same-tab SPA or DOM-driven player swaps can change the effective rule output
|
||||||
// already ran on src mutation — re-apply margins / location / opacity for new rules.
|
// after the media source updates, so refresh or rebuild controllers here too.
|
||||||
reapplySiteRulesAndControllerGeometry();
|
reapplySiteRulesAndControllerGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1033,8 +1201,14 @@ function hasUsableMediaSource(node) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ensureController(node, parent) {
|
function ensureController(node, parent) {
|
||||||
if (!isMediaElement(node) || node.vsc) return node && node.vsc;
|
if (!isMediaElement(node)) return node && node.vsc;
|
||||||
if (!hasUsableMediaSource(node)) {
|
|
||||||
|
if (!node.isConnected) {
|
||||||
|
removeController(node);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!node.vsc && !hasUsableMediaSource(node)) {
|
||||||
log(
|
log(
|
||||||
`Deferring controller creation for ${node.tagName}: no usable source yet`,
|
`Deferring controller creation for ${node.tagName}: no usable source yet`,
|
||||||
5
|
5
|
||||||
@@ -1045,9 +1219,13 @@ function ensureController(node, parent) {
|
|||||||
// href selects site rules; re-run on every new/usable media so margins/opacity match current URL.
|
// href selects site rules; re-run on every new/usable media so margins/opacity match current URL.
|
||||||
var siteDisabled = applySiteRuleOverrides();
|
var siteDisabled = applySiteRuleOverrides();
|
||||||
if (!tc.settings.enabled || siteDisabled) {
|
if (!tc.settings.enabled || siteDisabled) {
|
||||||
|
removeController(node);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
refreshAllControllerGeometry();
|
|
||||||
|
if (node.vsc) {
|
||||||
|
return refreshManagedController(node, parent);
|
||||||
|
}
|
||||||
|
|
||||||
log(
|
log(
|
||||||
`Creating controller for ${node.tagName}: ${node.src || node.currentSrc || "no src"}`,
|
`Creating controller for ${node.tagName}: ${node.src || node.currentSrc || "no src"}`,
|
||||||
@@ -1191,7 +1369,8 @@ function log(message, level) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
chrome.storage.sync.get(tc.settings, function (storage) {
|
chrome.storage.sync.get(null, function (storage) {
|
||||||
|
storage = vscExpandStoredSettings(storage);
|
||||||
var storedBindings = Array.isArray(storage.keyBindings)
|
var storedBindings = Array.isArray(storage.keyBindings)
|
||||||
? storage.keyBindings
|
? storage.keyBindings
|
||||||
: [];
|
: [];
|
||||||
@@ -1202,19 +1381,6 @@ chrome.storage.sync.get(tc.settings, function (storage) {
|
|||||||
|
|
||||||
if (tc.settings.keyBindings.length === 0) {
|
if (tc.settings.keyBindings.length === 0) {
|
||||||
tc.settings.keyBindings = defaultKeyBindings(storage);
|
tc.settings.keyBindings = defaultKeyBindings(storage);
|
||||||
tc.settings.version = "0.5.3";
|
|
||||||
chrome.storage.sync.set({
|
|
||||||
keyBindings: tc.settings.keyBindings,
|
|
||||||
version: tc.settings.version,
|
|
||||||
displayKeyCode: tc.settings.displayKeyCode,
|
|
||||||
rememberSpeed: tc.settings.rememberSpeed,
|
|
||||||
forceLastSavedSpeed: tc.settings.forceLastSavedSpeed,
|
|
||||||
audioBoolean: tc.settings.audioBoolean,
|
|
||||||
startHidden: tc.settings.startHidden,
|
|
||||||
enabled: tc.settings.enabled,
|
|
||||||
controllerLocation: tc.settings.controllerLocation,
|
|
||||||
controllerOpacity: tc.settings.controllerOpacity
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
tc.settings.lastSpeed = Number(storage.lastSpeed);
|
tc.settings.lastSpeed = Number(storage.lastSpeed);
|
||||||
if (!isValidSpeed(tc.settings.lastSpeed) && tc.settings.lastSpeed !== 1.0) {
|
if (!isValidSpeed(tc.settings.lastSpeed) && tc.settings.lastSpeed !== 1.0) {
|
||||||
@@ -1292,7 +1458,14 @@ chrome.storage.sync.get(tc.settings, function (storage) {
|
|||||||
addedDefaultBinding;
|
addedDefaultBinding;
|
||||||
|
|
||||||
if (addedDefaultBinding) {
|
if (addedDefaultBinding) {
|
||||||
chrome.storage.sync.set({ keyBindings: tc.settings.keyBindings });
|
var keyBindingsDiff = vscBuildStoredSettingsDiff({
|
||||||
|
keyBindings: tc.settings.keyBindings
|
||||||
|
});
|
||||||
|
if (Object.prototype.hasOwnProperty.call(keyBindingsDiff, "keyBindings")) {
|
||||||
|
chrome.storage.sync.set({ keyBindings: keyBindingsDiff.keyBindings });
|
||||||
|
} else {
|
||||||
|
chrome.storage.sync.remove("keyBindings");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
captureSiteRuleBase();
|
captureSiteRuleBase();
|
||||||
patchAttachShadow();
|
patchAttachShadow();
|
||||||
@@ -1483,7 +1656,14 @@ function defineVideoController() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
log(`Controller created and attached to DOM. Hidden: ${this.div.classList.contains('vsc-hidden')}`, 4);
|
this.mountParent =
|
||||||
|
this.div.parentNode || getControllerMountParent(target, this.parent);
|
||||||
|
this.behaviorSignature = getControllerBehaviorSignature(target);
|
||||||
|
|
||||||
|
log(
|
||||||
|
`Controller created and attached to DOM. Hidden: ${this.div.classList.contains('vsc-hidden')}`,
|
||||||
|
4
|
||||||
|
);
|
||||||
|
|
||||||
var mediaEventAction = function (event) {
|
var mediaEventAction = function (event) {
|
||||||
if (
|
if (
|
||||||
@@ -1757,10 +1937,10 @@ function defineVideoController() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tc.videoController.prototype.setupYouTubeAutoHide = function (wrapper) {
|
tc.videoController.prototype.setupYouTubeAutoHide = function (wrapper) {
|
||||||
if (!wrapper || !isOnYouTube()) return;
|
if (!wrapper) return;
|
||||||
|
|
||||||
const video = this.video;
|
const video = this.video;
|
||||||
const ytPlayer = video.closest(".html5-video-player");
|
const ytPlayer = getYouTubeAutoHidePlayer(video);
|
||||||
if (!ytPlayer) {
|
if (!ytPlayer) {
|
||||||
log("YouTube player not found for auto-hide setup", 4);
|
log("YouTube player not found for auto-hide setup", 4);
|
||||||
return;
|
return;
|
||||||
@@ -1900,7 +2080,8 @@ function defineVideoController() {
|
|||||||
wrapper.classList.add("vsc-nosource");
|
wrapper.classList.add("vsc-nosource");
|
||||||
if (tc.settings.startHidden) wrapper.classList.add("vsc-hidden");
|
if (tc.settings.startHidden) wrapper.classList.add("vsc-hidden");
|
||||||
// Use lower z-index for non-YouTube sites to avoid overlapping modals
|
// Use lower z-index for non-YouTube sites to avoid overlapping modals
|
||||||
if (!isOnYouTube()) wrapper.classList.add("vsc-non-youtube");
|
if (!getYouTubeAutoHidePlayer(this.video))
|
||||||
|
wrapper.classList.add("vsc-non-youtube");
|
||||||
var shadow = wrapper.attachShadow({ mode: "open" });
|
var shadow = wrapper.attachShadow({ mode: "open" });
|
||||||
var shadowStylesheet = doc.createElement("link");
|
var shadowStylesheet = doc.createElement("link");
|
||||||
shadowStylesheet.rel = "stylesheet";
|
shadowStylesheet.rel = "stylesheet";
|
||||||
@@ -2016,7 +2197,7 @@ function defineVideoController() {
|
|||||||
|
|
||||||
// Setup auto-hide observers if enabled
|
// Setup auto-hide observers if enabled
|
||||||
if (tc.settings.hideWithControls) {
|
if (tc.settings.hideWithControls) {
|
||||||
if (isOnYouTube()) {
|
if (getAutoHideModeForVideo(this.video) === "youtube") {
|
||||||
this.setupYouTubeAutoHide(wrapper);
|
this.setupYouTubeAutoHide(wrapper);
|
||||||
} else {
|
} else {
|
||||||
this.setupGenericAutoHide(wrapper);
|
this.setupGenericAutoHide(wrapper);
|
||||||
@@ -2088,60 +2269,26 @@ function defineVideoController() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function escapeStringRegExp(str) {
|
|
||||||
const m = /[|\\{}()[\]^$+*?.]/g;
|
|
||||||
return str.replace(m, "\\$&");
|
|
||||||
}
|
|
||||||
function applySiteRuleOverrides() {
|
function applySiteRuleOverrides() {
|
||||||
resetSettingsFromSiteRuleBase();
|
resetSettingsFromSiteRuleBase();
|
||||||
|
tc.activeSiteRule = null;
|
||||||
|
|
||||||
if (!Array.isArray(tc.settings.siteRules) || tc.settings.siteRules.length === 0) {
|
if (!Array.isArray(tc.settings.siteRules) || tc.settings.siteRules.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentUrl = location.href;
|
var currentUrl = location.href;
|
||||||
var matchedRule = null;
|
var matchedRule = vscMatchSiteRule(currentUrl, tc.settings.siteRules);
|
||||||
|
|
||||||
for (var i = 0; i < tc.settings.siteRules.length; i++) {
|
|
||||||
var rule = tc.settings.siteRules[i];
|
|
||||||
var pattern = rule.pattern;
|
|
||||||
if (!pattern || pattern.length === 0) continue;
|
|
||||||
|
|
||||||
var regex;
|
|
||||||
if (pattern.startsWith("/") && pattern.lastIndexOf("/") > 0) {
|
|
||||||
try {
|
|
||||||
var lastSlash = pattern.lastIndexOf("/");
|
|
||||||
regex = new RegExp(
|
|
||||||
pattern.substring(1, lastSlash),
|
|
||||||
pattern.substring(lastSlash + 1)
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
log(`Invalid site rule regex: ${pattern}. ${e.message}`, 2);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
regex = new RegExp(escapeStringRegExp(pattern));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regex && regex.test(currentUrl)) {
|
|
||||||
matchedRule = rule;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!matchedRule) return false;
|
if (!matchedRule) return false;
|
||||||
|
|
||||||
tc.activeSiteRule = matchedRule;
|
tc.activeSiteRule = matchedRule;
|
||||||
log(`Matched site rule: ${matchedRule.pattern}`, 4);
|
log("Matched site rule overrides for current URL", 4);
|
||||||
|
|
||||||
// Check if extension should be enabled/disabled on this site
|
// Check if extension should be enabled/disabled on this site
|
||||||
if (matchedRule.enabled === false) {
|
if (vscIsSiteRuleDisabled(matchedRule)) {
|
||||||
log(`Extension disabled for site: ${currentUrl}`, 4);
|
log(`Extension disabled for site: ${currentUrl}`, 4);
|
||||||
return true;
|
return true;
|
||||||
} else if (matchedRule.disableExtension === true) {
|
|
||||||
// Handle old format
|
|
||||||
log(`Extension disabled (legacy) for site: ${currentUrl}`, 4);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override general settings with site-specific overrides
|
// Override general settings with site-specific overrides
|
||||||
@@ -2199,23 +2346,22 @@ function applySiteRuleOverrides() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Apply current tc.settings controller layout/opacity to every attached controller (after site rules). */
|
/** Re-match site rules for current URL and refresh or rebuild every controller. */
|
||||||
function refreshAllControllerGeometry() {
|
|
||||||
tc.mediaElements.forEach(function (video) {
|
|
||||||
if (!video || !video.vsc) return;
|
|
||||||
applyControllerLocation(video.vsc, tc.settings.controllerLocation);
|
|
||||||
var controllerEl = getControllerElement(video.vsc);
|
|
||||||
if (controllerEl) {
|
|
||||||
controllerEl.style.opacity = String(tc.settings.controllerOpacity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Re-match site rules for current URL and refresh controller position/opacity on every video. */
|
|
||||||
function reapplySiteRulesAndControllerGeometry() {
|
function reapplySiteRulesAndControllerGeometry() {
|
||||||
var siteDisabled = applySiteRuleOverrides();
|
var siteDisabled = applySiteRuleOverrides();
|
||||||
if (!tc.settings.enabled || siteDisabled) return;
|
var videos = tc.mediaElements.slice();
|
||||||
refreshAllControllerGeometry();
|
|
||||||
|
if (!tc.settings.enabled || siteDisabled) {
|
||||||
|
videos.forEach(function (video) {
|
||||||
|
removeController(video);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
videos.forEach(function (video) {
|
||||||
|
if (!video) return;
|
||||||
|
ensureController(video, video.parentElement || video.parentNode);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function shouldPreserveDesiredSpeed(video, speed) {
|
function shouldPreserveDesiredSpeed(video, speed) {
|
||||||
@@ -2556,7 +2702,6 @@ function initializeNow(doc, forceReinit = false) {
|
|||||||
if ((!forceReinit && vscInitializedDocuments.has(doc)) || !doc.body) return;
|
if ((!forceReinit && vscInitializedDocuments.has(doc)) || !doc.body) return;
|
||||||
|
|
||||||
var siteDisabled = applySiteRuleOverrides();
|
var siteDisabled = applySiteRuleOverrides();
|
||||||
if (!tc.settings.enabled || siteDisabled) return;
|
|
||||||
|
|
||||||
if (!doc.body.classList.contains("vsc-initialized")) {
|
if (!doc.body.classList.contains("vsc-initialized")) {
|
||||||
doc.body.classList.add("vsc-initialized");
|
doc.body.classList.add("vsc-initialized");
|
||||||
@@ -2568,7 +2713,9 @@ function initializeNow(doc, forceReinit = false) {
|
|||||||
|
|
||||||
if (forceReinit) {
|
if (forceReinit) {
|
||||||
log("Force re-initialization requested", 4);
|
log("Force re-initialization requested", 4);
|
||||||
refreshAllControllerGeometry();
|
reapplySiteRulesAndControllerGeometry();
|
||||||
|
} else if (!tc.settings.enabled || siteDisabled) {
|
||||||
|
reapplySiteRulesAndControllerGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
vscInitializedDocuments.add(doc);
|
vscInitializedDocuments.add(doc);
|
||||||
|
|||||||
@@ -59,6 +59,7 @@
|
|||||||
"inject.css"
|
"inject.css"
|
||||||
],
|
],
|
||||||
"js": [
|
"js": [
|
||||||
|
"settings-core.js",
|
||||||
"ui-icons.js",
|
"ui-icons.js",
|
||||||
"inject.js"
|
"inject.js"
|
||||||
]
|
]
|
||||||
|
|||||||
+23
-11
@@ -5,6 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>Speeder Settings</title>
|
<title>Speeder Settings</title>
|
||||||
<link rel="stylesheet" href="options.css" />
|
<link rel="stylesheet" href="options.css" />
|
||||||
|
<script src="settings-core.js"></script>
|
||||||
<script src="ui-icons.js"></script>
|
<script src="ui-icons.js"></script>
|
||||||
<script src="lucide-client.js"></script>
|
<script src="lucide-client.js"></script>
|
||||||
<script src="options.js"></script>
|
<script src="options.js"></script>
|
||||||
@@ -550,18 +551,29 @@
|
|||||||
<span>Override auto-hide for this site</span>
|
<span>Override auto-hide for this site</span>
|
||||||
<input type="checkbox" class="override-autohide" />
|
<input type="checkbox" class="override-autohide" />
|
||||||
</label>
|
</label>
|
||||||
<div class="site-autohide-container" style="display: none">
|
<div class="site-autohide-container" style="display: none">
|
||||||
<div class="site-rule-option site-rule-option-checkbox">
|
<div class="site-rule-option site-rule-option-checkbox">
|
||||||
<label class="site-rule-split-label">
|
<label class="site-rule-split-label">
|
||||||
<span>Hide with controls (idle-based)</span>
|
<span
|
||||||
<input type="checkbox" class="site-hideWithControls" />
|
>Hide with controls<br /><em
|
||||||
</label>
|
>Fade the controller in and out with the video
|
||||||
|
interface: perfect sync on YouTube, idle-based
|
||||||
|
elsewhere.</em
|
||||||
|
></span
|
||||||
|
>
|
||||||
|
<input type="checkbox" class="site-hideWithControls" />
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="site-rule-option site-rule-option-field">
|
||||||
|
<label
|
||||||
|
>Auto-hide timer (seconds)<br /><em
|
||||||
|
>Seconds of inactivity before hiding: 0.1–15
|
||||||
|
for non-YouTube sites.</em
|
||||||
|
></label
|
||||||
|
>
|
||||||
|
<input type="text" class="site-hideWithControlsTimer" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="site-rule-option site-rule-option-field">
|
|
||||||
<label>Auto-hide timer (0.1–15s):</label>
|
|
||||||
<input type="text" class="site-hideWithControlsTimer" />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
<div class="site-rule-override-section">
|
<div class="site-rule-override-section">
|
||||||
<label class="site-override-lead">
|
<label class="site-override-lead">
|
||||||
|
|||||||
+101
-101
@@ -226,64 +226,48 @@ function createDefaultBinding(action, key, keyCode, value) {
|
|||||||
action: action,
|
action: action,
|
||||||
key: key,
|
key: key,
|
||||||
keyCode: keyCode,
|
keyCode: keyCode,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
value: value,
|
value: value,
|
||||||
force: false,
|
force: false,
|
||||||
predefined: true
|
predefined: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var tcDefaults = {
|
var tcDefaults = vscGetSettingsDefaults();
|
||||||
speed: 1.0,
|
var legacySyncKeys = [
|
||||||
lastSpeed: 1.0,
|
"resetSpeed",
|
||||||
displayKeyCode: 86,
|
"speedStep",
|
||||||
rememberSpeed: false,
|
"fastSpeed",
|
||||||
audioBoolean: false,
|
"rewindTime",
|
||||||
startHidden: false,
|
"advanceTime",
|
||||||
hideWithYouTubeControls: false,
|
"resetKeyCode",
|
||||||
hideWithControls: false,
|
"slowerKeyCode",
|
||||||
hideWithControlsTimer: 2.0,
|
"fasterKeyCode",
|
||||||
controllerLocation: "top-left",
|
"rewindKeyCode",
|
||||||
forceLastSavedSpeed: false,
|
"advanceKeyCode",
|
||||||
enabled: true,
|
"fastKeyCode",
|
||||||
controllerOpacity: 0.3,
|
"blacklist"
|
||||||
controllerMarginTop: 0,
|
];
|
||||||
controllerMarginRight: 0,
|
|
||||||
controllerMarginBottom: 65,
|
function persistManagedSyncSettings(settings, callback) {
|
||||||
controllerMarginLeft: 0,
|
var nextSettings = vscBuildStoredSettingsDiff(settings);
|
||||||
keyBindings: [
|
chrome.storage.sync.remove(vscGetManagedSyncKeys(), function () {
|
||||||
createDefaultBinding("display", "V", 86, 0),
|
if (chrome.runtime.lastError) {
|
||||||
createDefaultBinding("move", "P", 80, 0),
|
callback(chrome.runtime.lastError);
|
||||||
createDefaultBinding("slower", "S", 83, 0.1),
|
return;
|
||||||
createDefaultBinding("faster", "D", 68, 0.1),
|
|
||||||
createDefaultBinding("rewind", "Z", 90, 10),
|
|
||||||
createDefaultBinding("advance", "X", 88, 10),
|
|
||||||
createDefaultBinding("reset", "R", 82, 1),
|
|
||||||
createDefaultBinding("fast", "G", 71, 1.8),
|
|
||||||
createDefaultBinding("toggleSubtitleNudge", "N", 78, 0)
|
|
||||||
],
|
|
||||||
siteRules: [
|
|
||||||
{
|
|
||||||
pattern: "/^https:\\/\\/(www\\.)?youtube\\.com\\/(?!shorts\\/).*/",
|
|
||||||
enabled: true,
|
|
||||||
enableSubtitleNudge: true,
|
|
||||||
subtitleNudgeInterval: 50
|
|
||||||
},
|
|
||||||
{
|
|
||||||
pattern: "/^https:\\/\\/(www\\.)?youtube\\.com\\/shorts\\/.*/",
|
|
||||||
enabled: true,
|
|
||||||
rememberSpeed: true,
|
|
||||||
controllerMarginTop: 60,
|
|
||||||
controllerMarginBottom: 85
|
|
||||||
}
|
}
|
||||||
],
|
|
||||||
controllerButtons: ["rewind", "slower", "faster", "advance", "display"],
|
if (Object.keys(nextSettings).length === 0) {
|
||||||
showPopupControlBar: true,
|
callback(null);
|
||||||
popupMatchHoverControls: true,
|
return;
|
||||||
popupControllerButtons: ["rewind", "slower", "faster", "advance", "display"],
|
}
|
||||||
enableSubtitleNudge: false,
|
|
||||||
subtitleNudgeInterval: 50,
|
chrome.storage.sync.set(nextSettings, function () {
|
||||||
subtitleNudgeAmount: 0.001
|
callback(chrome.runtime.lastError || null);
|
||||||
};
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const actionLabels = {
|
const actionLabels = {
|
||||||
display: "Show/hide controller",
|
display: "Show/hide controller",
|
||||||
@@ -889,15 +873,20 @@ function save_options() {
|
|||||||
settings.siteRules.push(rule);
|
settings.siteRules.push(rule);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Legacy keys to remove
|
chrome.storage.sync.remove(legacySyncKeys, function () {
|
||||||
const legacyKeys = [
|
if (chrome.runtime.lastError) {
|
||||||
"resetSpeed", "speedStep", "fastSpeed", "rewindTime", "advanceTime",
|
status.textContent =
|
||||||
"resetKeyCode", "slowerKeyCode", "fasterKeyCode", "rewindKeyCode",
|
"Error: Failed to clear legacy settings - " +
|
||||||
"advanceKeyCode", "fastKeyCode", "blacklist"
|
chrome.runtime.lastError.message;
|
||||||
];
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
chrome.storage.sync.remove(legacyKeys, function () {
|
persistManagedSyncSettings(settings, function (error) {
|
||||||
chrome.storage.sync.set(settings, function () {
|
if (error) {
|
||||||
|
status.textContent =
|
||||||
|
"Error: Failed to save settings - " + error.message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
status.textContent = "Options saved";
|
status.textContent = "Options saved";
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
status.textContent = "";
|
status.textContent = "";
|
||||||
@@ -1559,53 +1548,49 @@ function initLucideButtonIconsUI() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function restore_options() {
|
function restore_options() {
|
||||||
chrome.storage.sync.get(tcDefaults, function (storage) {
|
chrome.storage.sync.get(null, function (storage) {
|
||||||
|
var settings = vscExpandStoredSettings(storage);
|
||||||
chrome.storage.local.get(["customButtonIcons"], function (loc) {
|
chrome.storage.local.get(["customButtonIcons"], function (loc) {
|
||||||
customButtonIconsLive =
|
customButtonIconsLive =
|
||||||
loc && loc.customButtonIcons && typeof loc.customButtonIcons === "object"
|
loc && loc.customButtonIcons && typeof loc.customButtonIcons === "object"
|
||||||
? loc.customButtonIcons
|
? loc.customButtonIcons
|
||||||
: {};
|
: {};
|
||||||
|
|
||||||
document.getElementById("rememberSpeed").checked = storage.rememberSpeed;
|
document.getElementById("rememberSpeed").checked = settings.rememberSpeed;
|
||||||
document.getElementById("forceLastSavedSpeed").checked =
|
document.getElementById("forceLastSavedSpeed").checked =
|
||||||
storage.forceLastSavedSpeed;
|
settings.forceLastSavedSpeed;
|
||||||
document.getElementById("audioBoolean").checked = storage.audioBoolean;
|
document.getElementById("audioBoolean").checked = settings.audioBoolean;
|
||||||
document.getElementById("enabled").checked = storage.enabled;
|
document.getElementById("enabled").checked = settings.enabled;
|
||||||
document.getElementById("startHidden").checked = storage.startHidden;
|
document.getElementById("startHidden").checked = settings.startHidden;
|
||||||
|
document.getElementById("hideWithControls").checked =
|
||||||
// Migration/Normalization for hideWithControls
|
settings.hideWithControls;
|
||||||
const hideWithControls = typeof storage.hideWithControls !== "undefined"
|
|
||||||
? storage.hideWithControls
|
|
||||||
: storage.hideWithYouTubeControls;
|
|
||||||
|
|
||||||
document.getElementById("hideWithControls").checked = hideWithControls;
|
|
||||||
document.getElementById("hideWithControlsTimer").value =
|
document.getElementById("hideWithControlsTimer").value =
|
||||||
storage.hideWithControlsTimer || tcDefaults.hideWithControlsTimer;
|
settings.hideWithControlsTimer || tcDefaults.hideWithControlsTimer;
|
||||||
|
|
||||||
document.getElementById("controllerLocation").value =
|
document.getElementById("controllerLocation").value =
|
||||||
normalizeControllerLocation(storage.controllerLocation);
|
normalizeControllerLocation(settings.controllerLocation);
|
||||||
document.getElementById("controllerOpacity").value =
|
document.getElementById("controllerOpacity").value =
|
||||||
storage.controllerOpacity;
|
settings.controllerOpacity;
|
||||||
document.getElementById("controllerMarginTop").value =
|
document.getElementById("controllerMarginTop").value =
|
||||||
storage.controllerMarginTop ?? tcDefaults.controllerMarginTop;
|
settings.controllerMarginTop ?? tcDefaults.controllerMarginTop;
|
||||||
document.getElementById("controllerMarginBottom").value =
|
document.getElementById("controllerMarginBottom").value =
|
||||||
storage.controllerMarginBottom ?? tcDefaults.controllerMarginBottom;
|
settings.controllerMarginBottom ?? tcDefaults.controllerMarginBottom;
|
||||||
document.getElementById("showPopupControlBar").checked =
|
document.getElementById("showPopupControlBar").checked =
|
||||||
storage.showPopupControlBar !== false;
|
settings.showPopupControlBar !== false;
|
||||||
document.getElementById("enableSubtitleNudge").checked =
|
document.getElementById("enableSubtitleNudge").checked =
|
||||||
storage.enableSubtitleNudge;
|
settings.enableSubtitleNudge;
|
||||||
document.getElementById("subtitleNudgeInterval").value =
|
document.getElementById("subtitleNudgeInterval").value =
|
||||||
storage.subtitleNudgeInterval;
|
settings.subtitleNudgeInterval;
|
||||||
|
|
||||||
if (!Array.isArray(storage.keyBindings) || storage.keyBindings.length === 0) {
|
if (!Array.isArray(settings.keyBindings) || settings.keyBindings.length === 0) {
|
||||||
storage.keyBindings = tcDefaults.keyBindings.slice();
|
settings.keyBindings = tcDefaults.keyBindings.slice();
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureAllDefaultBindings(storage);
|
ensureAllDefaultBindings(settings);
|
||||||
|
|
||||||
document.querySelectorAll(".customs:not([id])").forEach((row) => row.remove());
|
document.querySelectorAll(".customs:not([id])").forEach((row) => row.remove());
|
||||||
|
|
||||||
storage.keyBindings.forEach((item) => {
|
settings.keyBindings.forEach((item) => {
|
||||||
var row = document.getElementById(item.action);
|
var row = document.getElementById(item.action);
|
||||||
var normalizedBinding = normalizeStoredBinding(item);
|
var normalizedBinding = normalizeStoredBinding(item);
|
||||||
|
|
||||||
@@ -1634,11 +1619,9 @@ function restore_options() {
|
|||||||
|
|
||||||
refreshAddShortcutSelector();
|
refreshAddShortcutSelector();
|
||||||
|
|
||||||
// Load site rules (use defaults if none in storage or empty array)
|
var siteRules = Array.isArray(settings.siteRules)
|
||||||
var siteRules =
|
? settings.siteRules
|
||||||
Array.isArray(storage.siteRules) && storage.siteRules.length > 0
|
: tcDefaults.siteRules || [];
|
||||||
? storage.siteRules
|
|
||||||
: tcDefaults.siteRules || [];
|
|
||||||
|
|
||||||
vscClearElement(document.getElementById("siteRulesContainer"));
|
vscClearElement(document.getElementById("siteRulesContainer"));
|
||||||
if (siteRules.length > 0) {
|
if (siteRules.length > 0) {
|
||||||
@@ -1649,16 +1632,16 @@ function restore_options() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var controllerButtons = Array.isArray(storage.controllerButtons)
|
var controllerButtons = Array.isArray(settings.controllerButtons)
|
||||||
? storage.controllerButtons
|
? settings.controllerButtons
|
||||||
: tcDefaults.controllerButtons;
|
: tcDefaults.controllerButtons;
|
||||||
populateControlBarEditor(controllerButtons);
|
populateControlBarEditor(controllerButtons);
|
||||||
|
|
||||||
document.getElementById("popupMatchHoverControls").checked =
|
document.getElementById("popupMatchHoverControls").checked =
|
||||||
storage.popupMatchHoverControls !== false;
|
settings.popupMatchHoverControls !== false;
|
||||||
|
|
||||||
var popupButtons = Array.isArray(storage.popupControllerButtons)
|
var popupButtons = Array.isArray(settings.popupControllerButtons)
|
||||||
? storage.popupControllerButtons
|
? settings.popupControllerButtons
|
||||||
: tcDefaults.popupControllerButtons;
|
: tcDefaults.popupControllerButtons;
|
||||||
populatePopupControlBarEditor(popupButtons);
|
populatePopupControlBarEditor(popupButtons);
|
||||||
updatePopupEditorDisabledState();
|
updatePopupEditorDisabledState();
|
||||||
@@ -1676,13 +1659,30 @@ function restore_defaults() {
|
|||||||
function () {}
|
function () {}
|
||||||
);
|
);
|
||||||
|
|
||||||
chrome.storage.sync.set(tcDefaults, function () {
|
chrome.storage.sync.remove(legacySyncKeys, function () {
|
||||||
restore_options();
|
if (chrome.runtime.lastError) {
|
||||||
var status = document.getElementById("status");
|
var errorStatus = document.getElementById("status");
|
||||||
status.textContent = "Default options restored";
|
errorStatus.textContent =
|
||||||
setTimeout(function () {
|
"Error: Failed to clear legacy settings - " +
|
||||||
status.textContent = "";
|
chrome.runtime.lastError.message;
|
||||||
}, 1000);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
persistManagedSyncSettings(tcDefaults, function (error) {
|
||||||
|
if (error) {
|
||||||
|
var errorStatus = document.getElementById("status");
|
||||||
|
errorStatus.textContent =
|
||||||
|
"Error: Failed to restore defaults - " + error.message;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
restore_options();
|
||||||
|
var status = document.getElementById("status");
|
||||||
|
status.textContent = "Default options restored";
|
||||||
|
setTimeout(function () {
|
||||||
|
status.textContent = "";
|
||||||
|
}, 1000);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Speeder</title>
|
<title>Speeder</title>
|
||||||
<link rel="stylesheet" href="popup.css" />
|
<link rel="stylesheet" href="popup.css" />
|
||||||
|
<script src="settings-core.js"></script>
|
||||||
<script src="ui-icons.js"></script>
|
<script src="ui-icons.js"></script>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -20,49 +20,15 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
|
|
||||||
var defaultButtons = ["rewind", "slower", "faster", "advance", "display"];
|
var defaultButtons = ["rewind", "slower", "faster", "advance", "display"];
|
||||||
var popupExcludedButtonIds = new Set(["settings"]);
|
var popupExcludedButtonIds = new Set(["settings"]);
|
||||||
var storageDefaults = {
|
|
||||||
enabled: true,
|
|
||||||
showPopupControlBar: true,
|
|
||||||
controllerButtons: defaultButtons,
|
|
||||||
popupMatchHoverControls: true,
|
|
||||||
popupControllerButtons: defaultButtons,
|
|
||||||
siteRules: []
|
|
||||||
};
|
|
||||||
var renderToken = 0;
|
var renderToken = 0;
|
||||||
|
|
||||||
function escapeStringRegExp(str) {
|
|
||||||
const m = /[|\\{}()[\]^$+*?.]/g;
|
|
||||||
return str.replace(m, "\\$&");
|
|
||||||
}
|
|
||||||
|
|
||||||
function matchSiteRule(url, siteRules) {
|
function matchSiteRule(url, siteRules) {
|
||||||
if (!url || !Array.isArray(siteRules)) return null;
|
if (!url || !Array.isArray(siteRules)) return null;
|
||||||
for (var i = 0; i < siteRules.length; i++) {
|
return vscMatchSiteRule(url, siteRules);
|
||||||
var rule = siteRules[i];
|
|
||||||
if (!rule || !rule.pattern) continue;
|
|
||||||
var pattern = rule.pattern.replace(regStrip, "");
|
|
||||||
if (pattern.length === 0) continue;
|
|
||||||
var re;
|
|
||||||
if (pattern.startsWith("/") && pattern.lastIndexOf("/") > 0) {
|
|
||||||
try {
|
|
||||||
var ls = pattern.lastIndexOf("/");
|
|
||||||
re = new RegExp(pattern.substring(1, ls), pattern.substring(ls + 1));
|
|
||||||
} catch (e) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
re = new RegExp(escapeStringRegExp(pattern));
|
|
||||||
}
|
|
||||||
if (re && re.test(url)) return rule;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSiteRuleDisabled(rule) {
|
function isSiteRuleDisabled(rule) {
|
||||||
return Boolean(
|
return vscIsSiteRuleDisabled(rule);
|
||||||
rule &&
|
|
||||||
(rule.enabled === false || rule.disableExtension === true)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolvePopupButtons(storage, siteRule) {
|
function resolvePopupButtons(storage, siteRule) {
|
||||||
@@ -334,8 +300,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
? loc.customButtonIcons
|
? loc.customButtonIcons
|
||||||
: {};
|
: {};
|
||||||
|
|
||||||
chrome.storage.sync.get(storageDefaults, function (storage) {
|
chrome.storage.sync.get(null, function (storage) {
|
||||||
if (currentRenderToken !== renderToken) return;
|
if (currentRenderToken !== renderToken) return;
|
||||||
|
storage = vscExpandStoredSettings(storage);
|
||||||
|
|
||||||
getActiveTabContext(function (context) {
|
getActiveTabContext(function (context) {
|
||||||
if (currentRenderToken !== renderToken) return;
|
if (currentRenderToken !== renderToken) return;
|
||||||
@@ -397,7 +364,9 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
changes.controllerButtons ||
|
changes.controllerButtons ||
|
||||||
changes.popupMatchHoverControls ||
|
changes.popupMatchHoverControls ||
|
||||||
changes.popupControllerButtons ||
|
changes.popupControllerButtons ||
|
||||||
changes.siteRules
|
changes.siteRules ||
|
||||||
|
changes.siteRulesMeta ||
|
||||||
|
changes.siteRulesFormat
|
||||||
) {
|
) {
|
||||||
renderForActiveTab();
|
renderForActiveTab();
|
||||||
}
|
}
|
||||||
@@ -406,9 +375,37 @@ document.addEventListener("DOMContentLoaded", function () {
|
|||||||
renderForActiveTab();
|
renderForActiveTab();
|
||||||
|
|
||||||
function toggleEnabled(enabled, callback) {
|
function toggleEnabled(enabled, callback) {
|
||||||
chrome.storage.sync.set({ enabled: enabled }, function () {
|
chrome.storage.sync.get(null, function (storage) {
|
||||||
toggleEnabledUI(enabled);
|
var nextSettings = vscExpandStoredSettings(storage);
|
||||||
if (callback) callback(enabled);
|
nextSettings.enabled = enabled;
|
||||||
|
var storedSettings = vscBuildStoredSettingsDiff(nextSettings);
|
||||||
|
|
||||||
|
chrome.storage.sync.remove(vscGetManagedSyncKeys(), function () {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
setStatusMessage(
|
||||||
|
"Failed to update settings: " + chrome.runtime.lastError.message
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(storedSettings).length === 0) {
|
||||||
|
toggleEnabledUI(enabled);
|
||||||
|
if (callback) callback(enabled);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chrome.storage.sync.set(storedSettings, function () {
|
||||||
|
if (chrome.runtime.lastError) {
|
||||||
|
setStatusMessage(
|
||||||
|
"Failed to update settings: " + chrome.runtime.lastError.message
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleEnabledUI(enabled);
|
||||||
|
if (callback) callback(enabled);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,644 @@
|
|||||||
|
(function (global) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var SITE_RULES_DIFF_FORMAT = "defaults-diff-v1";
|
||||||
|
var DEFAULT_BUTTONS = ["rewind", "slower", "faster", "advance", "display"];
|
||||||
|
var SITE_RULE_OVERRIDE_KEYS = [
|
||||||
|
"controllerLocation",
|
||||||
|
"controllerMarginTop",
|
||||||
|
"controllerMarginBottom",
|
||||||
|
"startHidden",
|
||||||
|
"hideWithControls",
|
||||||
|
"hideWithControlsTimer",
|
||||||
|
"rememberSpeed",
|
||||||
|
"forceLastSavedSpeed",
|
||||||
|
"audioBoolean",
|
||||||
|
"controllerOpacity",
|
||||||
|
"enableSubtitleNudge",
|
||||||
|
"subtitleNudgeInterval",
|
||||||
|
"controllerButtons",
|
||||||
|
"showPopupControlBar",
|
||||||
|
"popupControllerButtons",
|
||||||
|
"shortcuts",
|
||||||
|
"preferredSpeed"
|
||||||
|
];
|
||||||
|
var DIFFABLE_OPTION_KEYS = [
|
||||||
|
"rememberSpeed",
|
||||||
|
"forceLastSavedSpeed",
|
||||||
|
"audioBoolean",
|
||||||
|
"enabled",
|
||||||
|
"startHidden",
|
||||||
|
"hideWithControls",
|
||||||
|
"hideWithControlsTimer",
|
||||||
|
"controllerLocation",
|
||||||
|
"controllerOpacity",
|
||||||
|
"controllerMarginTop",
|
||||||
|
"controllerMarginBottom",
|
||||||
|
"keyBindings",
|
||||||
|
"siteRules",
|
||||||
|
"siteRulesMeta",
|
||||||
|
"siteRulesFormat",
|
||||||
|
"controllerButtons",
|
||||||
|
"showPopupControlBar",
|
||||||
|
"popupMatchHoverControls",
|
||||||
|
"popupControllerButtons",
|
||||||
|
"enableSubtitleNudge",
|
||||||
|
"subtitleNudgeInterval",
|
||||||
|
"subtitleNudgeAmount"
|
||||||
|
];
|
||||||
|
var MANAGED_SYNC_KEYS = DIFFABLE_OPTION_KEYS.concat([
|
||||||
|
"hideWithYouTubeControls"
|
||||||
|
]);
|
||||||
|
|
||||||
|
var DEFAULT_SETTINGS = {
|
||||||
|
speed: 1.0,
|
||||||
|
lastSpeed: 1.0,
|
||||||
|
displayKeyCode: 86,
|
||||||
|
rememberSpeed: false,
|
||||||
|
audioBoolean: false,
|
||||||
|
startHidden: false,
|
||||||
|
hideWithYouTubeControls: false,
|
||||||
|
hideWithControls: false,
|
||||||
|
hideWithControlsTimer: 2.0,
|
||||||
|
controllerLocation: "top-left",
|
||||||
|
forceLastSavedSpeed: false,
|
||||||
|
enabled: true,
|
||||||
|
controllerOpacity: 0.3,
|
||||||
|
controllerMarginTop: 0,
|
||||||
|
controllerMarginRight: 0,
|
||||||
|
controllerMarginBottom: 65,
|
||||||
|
controllerMarginLeft: 0,
|
||||||
|
keyBindings: [
|
||||||
|
{
|
||||||
|
action: "display",
|
||||||
|
key: "V",
|
||||||
|
keyCode: 86,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 0,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "move",
|
||||||
|
key: "P",
|
||||||
|
keyCode: 80,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 0,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "slower",
|
||||||
|
key: "S",
|
||||||
|
keyCode: 83,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 0.1,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "faster",
|
||||||
|
key: "D",
|
||||||
|
keyCode: 68,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 0.1,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "rewind",
|
||||||
|
key: "Z",
|
||||||
|
keyCode: 90,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 10,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "advance",
|
||||||
|
key: "X",
|
||||||
|
keyCode: 88,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 10,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "reset",
|
||||||
|
key: "R",
|
||||||
|
keyCode: 82,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 0,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "fast",
|
||||||
|
key: "G",
|
||||||
|
keyCode: 71,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 1.8,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
action: "toggleSubtitleNudge",
|
||||||
|
key: "N",
|
||||||
|
keyCode: 78,
|
||||||
|
code: null,
|
||||||
|
disabled: false,
|
||||||
|
value: 0,
|
||||||
|
force: false,
|
||||||
|
predefined: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
siteRules: [
|
||||||
|
{
|
||||||
|
pattern: "/^https:\\/\\/(www\\.)?youtube\\.com\\/(?!shorts\\/).*/",
|
||||||
|
enabled: true,
|
||||||
|
enableSubtitleNudge: true,
|
||||||
|
subtitleNudgeInterval: 50
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pattern: "/^https:\\/\\/(www\\.)?youtube\\.com\\/shorts\\/.*/",
|
||||||
|
enabled: true,
|
||||||
|
rememberSpeed: true,
|
||||||
|
controllerMarginTop: 60,
|
||||||
|
controllerMarginBottom: 85
|
||||||
|
}
|
||||||
|
],
|
||||||
|
controllerButtons: DEFAULT_BUTTONS.slice(),
|
||||||
|
showPopupControlBar: true,
|
||||||
|
popupMatchHoverControls: true,
|
||||||
|
popupControllerButtons: DEFAULT_BUTTONS.slice(),
|
||||||
|
enableSubtitleNudge: false,
|
||||||
|
subtitleNudgeInterval: 50,
|
||||||
|
subtitleNudgeAmount: 0.001
|
||||||
|
};
|
||||||
|
|
||||||
|
function clonePlainData(value) {
|
||||||
|
if (value === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
return JSON.parse(JSON.stringify(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
function hasOwn(obj, key) {
|
||||||
|
return Boolean(obj) && Object.prototype.hasOwnProperty.call(obj, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isPlainObject(value) {
|
||||||
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function sortComparableValue(value) {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
return value.map(sortComparableValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPlainObject(value)) {
|
||||||
|
var sorted = {};
|
||||||
|
Object.keys(value)
|
||||||
|
.sort()
|
||||||
|
.forEach(function (key) {
|
||||||
|
if (value[key] === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sorted[key] = sortComparableValue(value[key]);
|
||||||
|
});
|
||||||
|
return sorted;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function areComparableValuesEqual(a, b) {
|
||||||
|
return (
|
||||||
|
JSON.stringify(sortComparableValue(a)) ===
|
||||||
|
JSON.stringify(sortComparableValue(b))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deepMergeDefaults(defaults, overrides) {
|
||||||
|
if (Array.isArray(defaults)) {
|
||||||
|
return Array.isArray(overrides)
|
||||||
|
? clonePlainData(overrides)
|
||||||
|
: clonePlainData(defaults);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPlainObject(defaults)) {
|
||||||
|
var result = clonePlainData(defaults) || {};
|
||||||
|
if (!isPlainObject(overrides)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(overrides).forEach(function (key) {
|
||||||
|
if (overrides[key] === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasOwn(defaults, key)) {
|
||||||
|
result[key] = deepMergeDefaults(defaults[key], overrides[key]);
|
||||||
|
} else {
|
||||||
|
result[key] = clonePlainData(overrides[key]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return overrides === undefined
|
||||||
|
? clonePlainData(defaults)
|
||||||
|
: clonePlainData(overrides);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deepDiff(current, defaults) {
|
||||||
|
if (current === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(current)) {
|
||||||
|
return areComparableValuesEqual(current, defaults)
|
||||||
|
? undefined
|
||||||
|
: clonePlainData(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isPlainObject(current)) {
|
||||||
|
var result = {};
|
||||||
|
Object.keys(current).forEach(function (key) {
|
||||||
|
var diff = deepDiff(current[key], defaults && defaults[key]);
|
||||||
|
if (diff !== undefined) {
|
||||||
|
result[key] = diff;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Object.keys(result).length > 0 ? result : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return areComparableValuesEqual(current, defaults)
|
||||||
|
? undefined
|
||||||
|
: clonePlainData(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultSiteRules() {
|
||||||
|
return clonePlainData(DEFAULT_SETTINGS.siteRules) || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDefaultSiteRulesByPattern() {
|
||||||
|
var map = Object.create(null);
|
||||||
|
getDefaultSiteRules().forEach(function (rule) {
|
||||||
|
if (!rule || typeof rule.pattern !== "string" || !rule.pattern) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
map[rule.pattern] = rule;
|
||||||
|
});
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeSiteRuleForDiff(rule, baseSettings) {
|
||||||
|
if (!rule || typeof rule !== "object" || Array.isArray(rule)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pattern = typeof rule.pattern === "string" ? rule.pattern.trim() : "";
|
||||||
|
if (!pattern) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var normalized = { pattern: pattern };
|
||||||
|
var baseEnabled = hasOwn(baseSettings, "enabled")
|
||||||
|
? Boolean(baseSettings.enabled)
|
||||||
|
: true;
|
||||||
|
var ruleEnabled = hasOwn(rule, "enabled")
|
||||||
|
? Boolean(rule.enabled)
|
||||||
|
: hasOwn(rule, "disableExtension")
|
||||||
|
? !Boolean(rule.disableExtension)
|
||||||
|
: baseEnabled;
|
||||||
|
|
||||||
|
if (!areComparableValuesEqual(ruleEnabled, baseEnabled)) {
|
||||||
|
normalized.enabled = ruleEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
SITE_RULE_OVERRIDE_KEYS.forEach(function (key) {
|
||||||
|
var baseValue = clonePlainData(baseSettings[key]);
|
||||||
|
var effectiveValue = hasOwn(rule, key)
|
||||||
|
? clonePlainData(rule[key])
|
||||||
|
: baseValue;
|
||||||
|
|
||||||
|
if (!areComparableValuesEqual(effectiveValue, baseValue)) {
|
||||||
|
normalized[key] = effectiveValue;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.keys(rule).forEach(function (key) {
|
||||||
|
if (
|
||||||
|
key === "pattern" ||
|
||||||
|
key === "enabled" ||
|
||||||
|
key === "disableExtension" ||
|
||||||
|
SITE_RULE_OVERRIDE_KEYS.indexOf(key) !== -1 ||
|
||||||
|
rule[key] === undefined
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
normalized[key] = clonePlainData(rule[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
return normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
function compressSiteRules(siteRules, baseSettings) {
|
||||||
|
if (!Array.isArray(siteRules)) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultRules = getDefaultSiteRules();
|
||||||
|
var defaultRulesByPattern = getDefaultSiteRulesByPattern();
|
||||||
|
var currentPatterns = new Set();
|
||||||
|
var exportRules = [];
|
||||||
|
|
||||||
|
siteRules.forEach(function (rule) {
|
||||||
|
if (!rule || typeof rule !== "object" || Array.isArray(rule)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pattern = typeof rule.pattern === "string" ? rule.pattern.trim() : "";
|
||||||
|
if (pattern) {
|
||||||
|
currentPatterns.add(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
var normalizedRule = normalizeSiteRuleForDiff(rule, baseSettings);
|
||||||
|
if (!normalizedRule || Object.keys(normalizedRule).length === 1) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultRule = pattern ? defaultRulesByPattern[pattern] : null;
|
||||||
|
var normalizedDefaultRule = defaultRule
|
||||||
|
? normalizeSiteRuleForDiff(defaultRule, baseSettings)
|
||||||
|
: null;
|
||||||
|
if (normalizedDefaultRule) {
|
||||||
|
if (areComparableValuesEqual(normalizedRule, normalizedDefaultRule)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var defaultRuleDiff = deepDiff(normalizedRule, normalizedDefaultRule);
|
||||||
|
if (defaultRuleDiff && Object.keys(defaultRuleDiff).length > 0) {
|
||||||
|
defaultRuleDiff.pattern = pattern;
|
||||||
|
exportRules.push(defaultRuleDiff);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
exportRules.push(normalizedRule);
|
||||||
|
});
|
||||||
|
|
||||||
|
var removedDefaultPatterns = defaultRules
|
||||||
|
.map(function (rule) {
|
||||||
|
return rule && typeof rule.pattern === "string" ? rule.pattern : "";
|
||||||
|
})
|
||||||
|
.filter(function (pattern) {
|
||||||
|
return pattern && !currentPatterns.has(pattern);
|
||||||
|
});
|
||||||
|
|
||||||
|
var result = {};
|
||||||
|
if (exportRules.length > 0) {
|
||||||
|
result.siteRules = exportRules;
|
||||||
|
result.siteRulesFormat = SITE_RULES_DIFF_FORMAT;
|
||||||
|
}
|
||||||
|
if (removedDefaultPatterns.length > 0) {
|
||||||
|
result.siteRulesMeta = {
|
||||||
|
removedDefaultPatterns: removedDefaultPatterns
|
||||||
|
};
|
||||||
|
result.siteRulesFormat = SITE_RULES_DIFF_FORMAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
function expandSiteRules(siteRules, siteRulesMeta) {
|
||||||
|
var defaultRules = getDefaultSiteRules();
|
||||||
|
var defaultRulesByPattern = getDefaultSiteRulesByPattern();
|
||||||
|
if (defaultRules.length === 0) {
|
||||||
|
return Array.isArray(siteRules) ? clonePlainData(siteRules) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
var removedDefaultPatterns = new Set(
|
||||||
|
siteRulesMeta && Array.isArray(siteRulesMeta.removedDefaultPatterns)
|
||||||
|
? siteRulesMeta.removedDefaultPatterns
|
||||||
|
: []
|
||||||
|
);
|
||||||
|
var modifiedDefaultRules = Object.create(null);
|
||||||
|
var customRules = [];
|
||||||
|
|
||||||
|
if (Array.isArray(siteRules)) {
|
||||||
|
siteRules.forEach(function (rule) {
|
||||||
|
if (!rule || typeof rule !== "object" || Array.isArray(rule)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pattern = typeof rule.pattern === "string" ? rule.pattern.trim() : "";
|
||||||
|
if (
|
||||||
|
pattern &&
|
||||||
|
Object.prototype.hasOwnProperty.call(defaultRulesByPattern, pattern)
|
||||||
|
) {
|
||||||
|
modifiedDefaultRules[pattern] = clonePlainData(rule);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
customRules.push(clonePlainData(rule));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
var mergedRules = [];
|
||||||
|
|
||||||
|
defaultRules.forEach(function (rule) {
|
||||||
|
var pattern = rule && typeof rule.pattern === "string" ? rule.pattern : "";
|
||||||
|
if (!pattern || removedDefaultPatterns.has(pattern)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifiedDefaultRules[pattern]) {
|
||||||
|
mergedRules.push(
|
||||||
|
Object.assign(
|
||||||
|
{},
|
||||||
|
clonePlainData(rule),
|
||||||
|
clonePlainData(modifiedDefaultRules[pattern])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
mergedRules.push(clonePlainData(rule));
|
||||||
|
});
|
||||||
|
|
||||||
|
customRules.forEach(function (rule) {
|
||||||
|
mergedRules.push(rule);
|
||||||
|
});
|
||||||
|
|
||||||
|
return mergedRules;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildStoredSettingsDiff(currentSettings) {
|
||||||
|
var defaults = clonePlainData(DEFAULT_SETTINGS);
|
||||||
|
var normalized = deepMergeDefaults(defaults, currentSettings || {});
|
||||||
|
var siteRuleData = compressSiteRules(normalized.siteRules, normalized);
|
||||||
|
var diffDefaults = {};
|
||||||
|
var diff = {};
|
||||||
|
|
||||||
|
delete normalized.siteRules;
|
||||||
|
delete normalized.siteRulesMeta;
|
||||||
|
delete normalized.siteRulesFormat;
|
||||||
|
delete normalized.hideWithYouTubeControls;
|
||||||
|
|
||||||
|
if (siteRuleData.siteRules) {
|
||||||
|
normalized.siteRules = siteRuleData.siteRules;
|
||||||
|
}
|
||||||
|
if (siteRuleData.siteRulesMeta) {
|
||||||
|
normalized.siteRulesMeta = siteRuleData.siteRulesMeta;
|
||||||
|
}
|
||||||
|
if (siteRuleData.siteRulesFormat) {
|
||||||
|
normalized.siteRulesFormat = siteRuleData.siteRulesFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
DIFFABLE_OPTION_KEYS.forEach(function (key) {
|
||||||
|
if (hasOwn(DEFAULT_SETTINGS, key)) {
|
||||||
|
diffDefaults[key] = clonePlainData(DEFAULT_SETTINGS[key]);
|
||||||
|
}
|
||||||
|
if (!hasOwn(normalized, key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var valueDiff = deepDiff(normalized[key], diffDefaults[key]);
|
||||||
|
if (valueDiff !== undefined) {
|
||||||
|
diff[key] = valueDiff;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function expandStoredSettings(storage) {
|
||||||
|
var raw = clonePlainData(storage) || {};
|
||||||
|
var expanded = deepMergeDefaults(DEFAULT_SETTINGS, raw);
|
||||||
|
|
||||||
|
if (
|
||||||
|
!hasOwn(raw, "hideWithControls") &&
|
||||||
|
hasOwn(raw, "hideWithYouTubeControls")
|
||||||
|
) {
|
||||||
|
expanded.hideWithControls = Boolean(raw.hideWithYouTubeControls);
|
||||||
|
}
|
||||||
|
expanded.hideWithYouTubeControls = expanded.hideWithControls;
|
||||||
|
|
||||||
|
if (raw.siteRulesFormat === SITE_RULES_DIFF_FORMAT) {
|
||||||
|
expanded.siteRules = expandSiteRules(raw.siteRules, raw.siteRulesMeta);
|
||||||
|
} else if (Array.isArray(raw.siteRules)) {
|
||||||
|
expanded.siteRules = clonePlainData(raw.siteRules);
|
||||||
|
} else {
|
||||||
|
expanded.siteRules = getDefaultSiteRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
return expanded;
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeStringRegExp(str) {
|
||||||
|
var matcher = /[|\\{}()[\]^$+*?.]/g;
|
||||||
|
return String(str).replace(matcher, "\\$&");
|
||||||
|
}
|
||||||
|
|
||||||
|
function siteRuleMatchesUrl(rule, currentUrl) {
|
||||||
|
if (!rule || !rule.pattern || !currentUrl) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pattern = String(rule.pattern).trim();
|
||||||
|
if (!pattern) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var regex;
|
||||||
|
if (pattern.startsWith("/") && pattern.lastIndexOf("/") > 0) {
|
||||||
|
try {
|
||||||
|
var lastSlash = pattern.lastIndexOf("/");
|
||||||
|
regex = new RegExp(
|
||||||
|
pattern.substring(1, lastSlash),
|
||||||
|
pattern.substring(lastSlash + 1)
|
||||||
|
);
|
||||||
|
} catch (_error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
regex = new RegExp(escapeStringRegExp(pattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Boolean(regex && regex.test(currentUrl));
|
||||||
|
}
|
||||||
|
|
||||||
|
function mergeMatchingSiteRules(currentUrl, siteRules) {
|
||||||
|
if (!currentUrl || !Array.isArray(siteRules)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var matchedRules = [];
|
||||||
|
for (var i = 0; i < siteRules.length; i++) {
|
||||||
|
if (siteRuleMatchesUrl(siteRules[i], currentUrl)) {
|
||||||
|
matchedRules.push(siteRules[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!matchedRules.length) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var mergedRule = {};
|
||||||
|
matchedRules.forEach(function (rule) {
|
||||||
|
Object.keys(rule).forEach(function (key) {
|
||||||
|
var value = rule[key];
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
mergedRule[key] = clonePlainData(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isPlainObject(value)) {
|
||||||
|
mergedRule[key] = clonePlainData(value);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
mergedRule[key] = value;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
return mergedRule;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isSiteRuleDisabled(rule) {
|
||||||
|
return Boolean(
|
||||||
|
rule &&
|
||||||
|
(
|
||||||
|
rule.enabled === false ||
|
||||||
|
(typeof rule.enabled === "undefined" && rule.disableExtension === true)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
global.vscClonePlainData = clonePlainData;
|
||||||
|
global.vscAreComparableValuesEqual = areComparableValuesEqual;
|
||||||
|
global.vscDeepMergeDefaults = deepMergeDefaults;
|
||||||
|
global.vscBuildStoredSettingsDiff = buildStoredSettingsDiff;
|
||||||
|
global.vscExpandStoredSettings = expandStoredSettings;
|
||||||
|
global.vscGetSettingsDefaults = function () {
|
||||||
|
return clonePlainData(DEFAULT_SETTINGS);
|
||||||
|
};
|
||||||
|
global.vscGetManagedSyncKeys = function () {
|
||||||
|
return MANAGED_SYNC_KEYS.slice();
|
||||||
|
};
|
||||||
|
global.vscGetSiteRulesDiffFormat = function () {
|
||||||
|
return SITE_RULES_DIFF_FORMAT;
|
||||||
|
};
|
||||||
|
global.vscMatchSiteRule = mergeMatchingSiteRules;
|
||||||
|
global.vscSiteRuleMatchesUrl = siteRuleMatchesUrl;
|
||||||
|
global.vscIsSiteRuleDisabled = isSiteRuleDisabled;
|
||||||
|
})(typeof globalThis !== "undefined" ? globalThis : this);
|
||||||
Reference in New Issue
Block a user