ultrawidify/src/ext/conf/ExtConfPatches.ts

373 lines
12 KiB
TypeScript
Raw Normal View History

2019-07-05 23:45:29 +02:00
// How to use:
// version: {ExtensionConf object, but only properties that get overwritten}
import StretchType from '../../common/enums/StretchType.enum';
2025-12-10 22:49:59 +01:00
// import ExtensionMode from '../../common/enums/ExtensionMode.enum';
import VideoAlignmentType from '../../common/enums/VideoAlignmentType.enum';
2021-04-05 03:30:29 +02:00
import BrowserDetect from './BrowserDetect';
2025-12-10 22:49:59 +01:00
import SettingsInterface, { SiteSettingsInterface } from '../../common/interfaces/SettingsInterface';
import { _cp } from '../../common/js/utils';
import CropModePersistence from '../../common/enums/CropModePersistence.enum';
import AspectRatioType from '../../common/enums/AspectRatioType.enum';
2025-04-20 16:11:17 +02:00
import { update } from 'lodash';
import EmbeddedContentSettingsOverridePolicy from '../../common/enums/EmbeddedContentSettingsOverridePolicy.enum';
2025-12-10 22:49:59 +01:00
import LegacyExtensionMode from '../../common/enums/LegacyExtensionMode.enum';
import ExtensionMode from '../../common/enums/ExtensionMode.enum';
import { PlayerDetectionMode } from '../../common/enums/PlayerDetectionMode.enum';
2025-12-10 22:49:59 +01:00
2019-07-05 23:45:29 +02:00
const ExtensionConfPatch = Object.freeze([
2019-09-03 00:28:35 +02:00
{
forVersion: '6.2.4',
2025-12-11 02:43:39 +01:00
updateFn: (userOptions: any, defaultOptions, logger?) => {
for (const site in userOptions.sites) {
2025-12-10 22:49:59 +01:00
(userOptions as any).sites[site].enableUI = {
fullscreen: LegacyExtensionMode.Default,
theater: LegacyExtensionMode.Default,
normal: LegacyExtensionMode.Default,
}
}
userOptions.sites['@global'].enableUI = {
2025-12-10 22:49:59 +01:00
fullscreen: userOptions.ui.inPlayer.enabled ? LegacyExtensionMode.Enabled : LegacyExtensionMode.Disabled,
theater: LegacyExtensionMode.Enabled,
normal: (userOptions.ui.inPlayer.enabled && !userOptions.ui.inPlayer.enabledFullscreenOnly) ? LegacyExtensionMode.Enabled : LegacyExtensionMode.Disabled
}
userOptions.sites['@empty'].enableUI = {
2025-12-10 22:49:59 +01:00
fullscreen: LegacyExtensionMode.Default,
theater: LegacyExtensionMode.Default,
normal: LegacyExtensionMode.Default,
}
}
2025-04-20 16:11:17 +02:00
}, {
forVersion: '6.2.6',
2025-12-11 02:43:39 +01:00
updateFn: (userOptions: any, defaultOptions, logger?) => {
console.log('[ultrawidify] Migrating settings — applying patches for version 6.2.6');
if (!userOptions.commands) {
userOptions.commands = {
zoom: [],
crop: [],
stretch: [],
pan: [],
internal: []
};
}
2025-04-20 16:11:17 +02:00
userOptions.commands.zoom = [{
action: 'change-zoom',
label: 'Zoom +5%',
arguments: {
zoom: 0.05
},
shortcut: {
key: 'z',
code: 'KeyY',
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: false,
onKeyUp: true,
onKeyDown: false,
},
internalOnly: true,
actionId: 'change-zoom-10in'
}, {
action: 'change-zoom',
label: 'Zoom -5%',
arguments: {
zoom: -0.05
},
shortcut: {
key: 'u',
code: 'KeyU',
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: false,
onKeyUp: true,
onKeyDown: false,
},
internalOnly: true,
actionId: 'change-zoom-10out'
}, {
action: 'set-zoom',
label: 'Reset zoom',
arguments: {
zoom: 1,
},
internalOnly: true,
actionId: 'set-zoom-reset'
}];
delete (userOptions as any).actions;
2025-04-20 19:29:47 +02:00
2025-04-22 02:42:33 +02:00
userOptions.dev = {
loadFromSnapshot: false
};
2025-04-20 19:29:47 +02:00
userOptions.ui.dev = {
aardDebugOverlay: {
showOnStartup: false,
showDetectionDetails: true
}
}
const newZoomActions = [{
action: 'set-zoom',
label: 'Reset zoom',
shortcut: {
key: 'r',
code: 'KeyR',
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: true,
onKeyUp: true,
onKeyDown: false,
},
2025-05-19 01:15:05 +02:00
arguments: {
zoom: 1
},
internalOnly: true,
actionId: 'set-zoom-reset'
}, {
action: 'set-ar-zoom',
label: 'Automatic',
comment: 'Automatically detect aspect ratio and zoom accordingly',
arguments: {
type: AspectRatioType.Automatic
},
shortcut: {
key: 'a',
code: 'KeyA',
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: true,
onKeyUp: true,
onKeyDown: false,
}
}, {
action: 'set-ar-zoom',
label: 'Cycle',
comment: 'Cycle through zoom options',
arguments: {
type: AspectRatioType.Cycle
},
shortcut: {
key: 'c',
code: 'KeyC',
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: true,
onKeyUp: true,
onKeyDown: false,
}
}, {
action: 'set-ar-zoom',
label: '21:9',
comment: 'Zoom for 21:9 aspect ratio (1:2.39)',
arguments: {
type: AspectRatioType.Fixed,
ratio: 2.39
},
shortcut: {
key: 'd',
code: 'KeyD',
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: true,
onKeyUp: false,
onKeyDown: true,
}
}, {
action: 'set-ar-zoom',
label: '18:9',
comment: 'Zoom for 18:9 aspect ratio (1:2)',
arguments: {
type: AspectRatioType.Fixed,
ratio: 1.78
},
shortcut: {
key: 's',
code: 'KeyS',
ctrlKey: false,
metaKey: false,
altKey: false,
shiftKey: true,
onKeyUp: false,
onKeyDown: true,
}
}, {
action: 'set-ar-zoom',
label: '32:9',
comment: 'Zoom for 32:9 aspect ratio',
arguments: {
type: AspectRatioType.Fixed,
ratio: 3.56
},
}];
const compareShortcuts = (a: any, b: any) => {
if (!a || !b) {
return false;
}
return a.key === b.key && b.code === b.code && a.ctrlKey == b.ctrlKey && a.shiftKey == b.shiftKey && a.metaKey == a.metaKey && a.altKey == b.altKey;
}
const hasConflict = (shortcut: any) => {
for (const ct in userOptions.commands) {
for (const command of userOptions.commands[ct]) {
if (compareShortcuts(shortcut, command.shortcut)) {
return true;
}
}
}
return false;
}
for (const zoomAction of newZoomActions) {
if (
!userOptions.commands.zoom.find(
x => x.action === zoomAction.action
&& x.arguments?.type === zoomAction.arguments?.type
&& x.arguments?.ratio === zoomAction.arguments?.ratio
)
) {
userOptions.commands.zoom.push({
...zoomAction,
shortcut: hasConflict(zoomAction.shortcut) ? undefined : zoomAction.shortcut
});
}
}
2025-04-20 16:11:17 +02:00
}
}, {
forVersion: '6.3.92',
2025-12-10 22:49:59 +01:00
updateFn: (userOptions: any) => {
// applyToEmbeddedContent is now an enum, and also no longer optional
for (const site in userOptions.sites) {
if (userOptions.sites[site].applyToEmbeddedContent === undefined) {
userOptions.sites[site].applyToEmbeddedContent = EmbeddedContentSettingsOverridePolicy.UseAsDefault;
} else {
userOptions.sites[site].applyToEmbeddedContent = userOptions.sites[site].applyToEmbeddedContent ? EmbeddedContentSettingsOverridePolicy.Always : EmbeddedContentSettingsOverridePolicy.Never;
}
}
}
},
{
forVersion: '6.3.93',
updateFn: (userOptions: SettingsInterface, defaultOptions: SettingsInterface) => {
2025-10-14 18:52:22 +02:00
(userOptions as any).arDetect.polling = defaultOptions.aard.polling;
(userOptions as any).arDetect.subtitles = defaultOptions.aard.subtitles;
(userOptions as any).arDetect.autoDisable = defaultOptions.aard.autoDisable;
}
2025-10-12 22:03:55 +02:00
},
{
2025-10-14 18:52:22 +02:00
forVersion: '6.3.98',
2025-10-12 22:03:55 +02:00
updateFn: (userOptions: SettingsInterface, defaultOptions: SettingsInterface) => {
2025-10-14 18:52:22 +02:00
(userOptions as any).arDetect.letterboxOrientationScan = defaultOptions.aard.letterboxOrientationScan;
(userOptions as any).arDetect.edgeDetection = defaultOptions.aard.edgeDetection;
(userOptions as any).arDetect.subtitles = defaultOptions.aard.subtitles;
}
},
{
forVersion: '6.3.98',
2025-12-11 02:43:39 +01:00
updateFn: (userOptions: SettingsInterface, defaultOptions: SettingsInterface) => {
2025-10-14 18:52:22 +02:00
userOptions.aard = defaultOptions.aard;
userOptions.aardLegacy = defaultOptions.aardLegacy;
delete (userOptions as any).arDetect;
2025-10-12 22:03:55 +02:00
}
2025-12-10 22:49:59 +01:00
},
{
forVersion: '6.3.994',
2025-12-11 02:43:39 +01:00
updateFn: (userOptions: SettingsInterface, defaultOptions: SettingsInterface, logger?) => {
2025-12-10 22:49:59 +01:00
const convertLegacyExtensionMode = (option: {normal: LegacyExtensionMode, theater: LegacyExtensionMode, fullscreen: LegacyExtensionMode}) => {
2025-12-11 02:43:39 +01:00
logger.log('updateFn', 'converting option', option);
2025-12-10 22:49:59 +01:00
if (option.normal === LegacyExtensionMode.Enabled) {
return ExtensionMode.All;
}
if (option.theater === LegacyExtensionMode.Enabled) {
return ExtensionMode.Theater;
}
if (option.fullscreen === LegacyExtensionMode.Enabled) {
return ExtensionMode.FullScreen;
}
if (option.fullscreen === LegacyExtensionMode.Disabled) {
return ExtensionMode.Disabled;
}
return ExtensionMode.Default;
}
for (const key in userOptions.sites) {
userOptions.sites[key].enable = convertLegacyExtensionMode(userOptions.sites[key].enable as any);
userOptions.sites[key].enableAard = convertLegacyExtensionMode(userOptions.sites[key].enable as any);
userOptions.sites[key].enableKeyboard = convertLegacyExtensionMode(userOptions.sites[key].enable as any);
userOptions.sites[key].enableUI = convertLegacyExtensionMode(userOptions.sites[key].enable as any);
2025-12-15 19:42:07 +01:00
logger.log('migrated site', key, userOptions.sites[key]);
2025-12-10 22:49:59 +01:00
}
}
},
{
forVersion: '6.3.995',
updateFn: (userOptions: SettingsInterface, defaultOptions: SettingsInterface, logger?) => {
if (!userOptions.ui) {
userOptions.ui = defaultOptions.ui
};
}
}, {
forVersion: '6.3.996',
updateFn: (userOptions: SettingsInterface, defaultOptions: SettingsInterface, logger?) => {
for (const site in userOptions.sites) {
for (const domConf in userOptions.sites.DOMConfig) {
const oldConf = userOptions.sites[site].DOMConfig[domConf] as any;
const newConf: any = {
type: oldConf.type ?? userOptions.sites[site].type,
elements: {}
};
if (oldConf.elements.player) {
newConf.elements['player'] = {
playerDetectionMode: oldConf?.elements?.player?.manual ? (
oldConf?.elements?.player?.querySelectors.trim() ? PlayerDetectionMode.QuerySelectors : PlayerDetectionMode.AncestorIndex
) : PlayerDetectionMode.Auto,
allowAutoFallback: true,
ancestorIndex: oldConf?.elements?.player?.parentIndex,
querySelectors: oldConf?.elements?.player?.querySelectors,
customCSS: oldConf?.elements?.player?.customCss,
}
} else {
newConf.elements['player'] = {
playerDetectionMode: PlayerDetectionMode.Auto,
allowAutoFallback: true,
}
}
if (oldConf.elements.video) {
newConf.elements['video'] = {
type: oldConf.type ?? userOptions.sites[site].type,
elements: {
video: {
playerDetectionMode: oldConf?.elements?.video?.manual ? PlayerDetectionMode.QuerySelectors : PlayerDetectionMode.Auto,
allowAutoFallback: true,
querySelectors: oldConf?.elements?.video?.querySelectors,
customCSS: oldConf?.elements?.video?.customCss,
}
}
}
}
userOptions.sites[site].DOMConfig[domConf] = newConf;
}
}
}
2019-09-03 00:28:35 +02:00
}
]);
2019-07-05 23:45:29 +02:00
2019-11-02 01:05:36 +01:00
2021-10-28 22:53:23 +02:00
export default ExtensionConfPatch;