2019-07-05 23:45:29 +02:00
// How to use:
// version: {ExtensionConf object, but only properties that get overwritten}
2021-02-08 23:04:54 +01:00
import StretchType from '../../common/enums/StretchType.enum' ;
2025-12-10 22:49:59 +01:00
// import ExtensionMode from '../../common/enums/ExtensionMode.enum';
2021-02-08 23:04:54 +01:00
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' ;
2023-01-07 03:05:17 +01:00
import { _cp } from '../../common/js/utils' ;
2023-01-15 22:11:47 +01:00
import CropModePersistence from '../../common/enums/CropModePersistence.enum' ;
2023-03-30 00:45:34 +02:00
import AspectRatioType from '../../common/enums/AspectRatioType.enum' ;
2025-04-20 16:11:17 +02:00
import { update } from 'lodash' ;
2025-08-03 02:37:05 +02:00
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' ;
2025-12-26 21:39:34 +01:00
import { PlayerDetectionMode } from '../../common/enums/PlayerDetectionMode.enum' ;
2025-12-26 22:32:36 +01:00
import { SiteSupportLevel } from '../../common/enums/SiteSupportLevel.enum' ;
2025-12-10 22:49:59 +01:00
2019-07-05 23:45:29 +02:00
2025-04-26 01:11:31 +02:00
const ExtensionConfPatch = Object . freeze ( [
2019-09-03 00:28:35 +02:00
{
2025-01-27 02:59:30 +01:00
forVersion : '6.2.4' ,
2025-12-11 02:43:39 +01:00
updateFn : ( userOptions : any , defaultOptions , logger ? ) = > {
2025-01-27 02:59:30 +01:00
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 ,
2025-01-27 02:59:30 +01:00
}
}
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
2025-01-27 02:59:30 +01:00
}
userOptions . sites [ '@empty' ] . enableUI = {
2025-12-10 22:49:59 +01:00
fullscreen : LegacyExtensionMode.Default ,
theater : LegacyExtensionMode.Default ,
normal : LegacyExtensionMode.Default ,
2025-01-27 02:59:30 +01:00
}
}
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 ? ) = > {
2025-08-03 02:37:05 +02:00
console . log ( '[ultrawidify] Migrating settings — applying patches for version 6.2.6' ) ;
2025-04-26 01:11:31 +02:00
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
}
}
2025-04-26 01:11:31 +02:00
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
} ,
2025-04-26 01:11:31 +02:00
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
}
2025-08-03 02:37:05 +02:00
} , {
forVersion : '6.3.92' ,
2025-12-10 22:49:59 +01:00
updateFn : ( userOptions : any ) = > {
2025-08-03 02:37:05 +02:00
// applyToEmbeddedContent is now an enum, and also no longer optional
for ( const site in userOptions . sites ) {
if ( userOptions . sites [ site ] . applyToEmbeddedContent === undefined ) {
2025-12-26 21:36:01 +01:00
userOptions . sites [ site ] . applyToEmbeddedContent = EmbeddedContentSettingsOverridePolicy . UseAsDefault ;
2025-08-03 02:37:05 +02:00
} else {
userOptions . sites [ site ] . applyToEmbeddedContent = userOptions . sites [ site ] . applyToEmbeddedContent ? EmbeddedContentSettingsOverridePolicy.Always : EmbeddedContentSettingsOverridePolicy.Never ;
}
}
}
2025-10-08 19:35:12 +02:00
} ,
{
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-08 19:35:12 +02:00
}
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-26 22:50:56 +01:00
if ( typeof option === 'number' ) {
logger . warn ( 'updateFn' , 'This option is not an object, which suggests it has already been converted. Skipping conversion. Raw value of option:' , option ) ;
return option ;
}
logger . log (
'updateFn' ,
` \ nconverting option ——— normal: ${ LegacyExtensionMode [ option . normal ] } theater: ${ LegacyExtensionMode [ option . normal ] } fs: ${ LegacyExtensionMode [ option . fullscreen ] } ` , '\nraw obj:' , 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 ) {
2025-12-26 22:50:56 +01:00
logger . log ( 'updateFn' , '\n\n ... migrating default enable-state for site' , key ) ;
2025-12-10 22:49:59 +01:00
userOptions . sites [ key ] . enable = convertLegacyExtensionMode ( userOptions . sites [ key ] . enable as any ) ;
2025-12-26 22:50:56 +01:00
userOptions . sites [ key ] . enableAard = convertLegacyExtensionMode ( userOptions . sites [ key ] . enableAard as any ) ;
userOptions . sites [ key ] . enableKeyboard = convertLegacyExtensionMode ( userOptions . sites [ key ] . enableKeyboard as any ) ;
userOptions . sites [ key ] . enableUI = convertLegacyExtensionMode (
userOptions . sites [ key ] . enableUI ? ? ( key === '@global' ? ExtensionMode.FullScreen : ExtensionMode.Default ) as any
) ;
2025-12-15 19:42:07 +01:00
2025-12-26 22:32:36 +01:00
logger . log ( 'updateFn' , 'migrated site' , key , userOptions . sites [ key ] ) ;
2025-12-10 22:49:59 +01:00
}
}
2025-12-16 22:57:19 +01:00
} ,
{
forVersion : '6.3.995' ,
updateFn : ( userOptions : SettingsInterface , defaultOptions : SettingsInterface , logger ? ) = > {
if ( ! userOptions . ui ) {
userOptions . ui = defaultOptions . ui
} ;
}
2025-12-26 21:39:34 +01:00
} , {
forVersion : '6.3.996' ,
updateFn : ( userOptions : SettingsInterface , defaultOptions : SettingsInterface , logger ? ) = > {
for ( const site in userOptions . sites ) {
2025-12-26 22:32:36 +01:00
const siteData = userOptions . sites [ site ] ;
logger . log ( 'updateFn' , 'migrating settings for' , site , ' — persistCSA?' , siteData . persistCSA , 'typeof persistCSA?' , typeof siteData . persistCSA , 'does domconfig exist?' , siteData . DOMConfig ) ;
if ( typeof siteData . persistCSA !== 'number' ) {
userOptions . sites [ site ] . persistCSA = CropModePersistence . Default ;
} else {
userOptions . sites [ site ] . persistCSA = userOptions . sites [ site ] . persistCSA ? ? CropModePersistence . Default ;
}
for ( const domConf in siteData . DOMConfig ) {
logger . log ( 'updateFn' , "Updating domconf" , domConf ) ;
2025-12-26 21:39:34 +01:00
const oldConf = userOptions . sites [ site ] . DOMConfig [ domConf ] as any ;
2025-12-26 22:32:36 +01:00
logger . log ( 'updateFn' , "——— oldConf:" , oldConf ) ;
2025-12-26 21:39:34 +01:00
const newConf : any = {
type : oldConf . type ? ? userOptions . sites [ site ] . type ,
elements : { }
} ;
2025-12-26 22:32:36 +01:00
if ( oldConf . elements ? . player ) {
2025-12-26 21:39:34 +01:00
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 ,
}
}
2025-12-26 22:32:36 +01:00
if ( oldConf . elements ? . video ) {
2025-12-26 21:39:34 +01:00
newConf . elements [ 'video' ] = {
2025-12-26 22:32:36 +01:00
type : oldConf . type ? ? siteData . type ,
2025-12-26 21:39:34 +01:00
elements : {
video : {
playerDetectionMode : oldConf?.elements?.video?.manual ? PlayerDetectionMode.QuerySelectors : PlayerDetectionMode.Auto ,
allowAutoFallback : true ,
querySelectors : oldConf?.elements?.video?.querySelectors ,
customCSS : oldConf?.elements?.video?.customCss ,
}
}
}
}
2025-12-26 22:32:36 +01:00
console . log ( 'new conf:' , newConf )
2025-12-26 21:39:34 +01:00
userOptions . sites [ site ] . DOMConfig [ domConf ] = newConf ;
}
}
2025-12-26 22:32:36 +01:00
// set new defaults for global and empty:
userOptions . sites [ '@global' ] . DOMConfig = {
'auto' : {
type : SiteSupportLevel . Unknown ,
elements : {
player : {
playerDetectionMode : PlayerDetectionMode.Auto ,
allowAutoFallback : true ,
}
}
}
}
userOptions . sites [ '@global' ] . activeDOMConfig = 'auto' ;
userOptions . sites [ '@empty' ] . DOMConfig = {
'empty' : {
type : SiteSupportLevel . UserDefined ,
elements : {
player : {
playerDetectionMode : PlayerDetectionMode.Auto ,
allowAutoFallback : true ,
// ancestorIndex: 1,
// querySelectors: '',
// customCSS: ''
} ,
video : {
playerDetectionMode : PlayerDetectionMode.Auto ,
allowAutoFallback : true ,
// ancestorIndex: 1,
// querySelectors: '',
// customCSS: ''
}
} ,
}
} ;
userOptions . sites [ '@empty' ] . activeDOMConfig = 'empty' ;
logger . log ( 'updateFn' , 'Migration complete. New site settings:' , userOptions . sites ) ;
2025-12-26 21:39:34 +01:00
}
2019-09-03 00:28:35 +02:00
}
2025-10-08 19:35:12 +02:00
2025-04-26 01:11:31 +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 ;