diff --git a/src/ext/conf/ExtConfPatches.js b/src/ext/conf/ExtConfPatches.js new file mode 100644 index 0000000..a9d4701 --- /dev/null +++ b/src/ext/conf/ExtConfPatches.js @@ -0,0 +1,44 @@ +// How to use: +// version: {ExtensionConf object, but only properties that get overwritten} + +const ExtensionConfPatch = { + '4.2.0': { + sites: { + "old.reddit.com" : { + type: 'testing', + DOM: { + player: { + manual: true, + useRelativeAncestor: false, + querySelectors: '.media-preview-content' + } + }, + css: '', + }, + "www.reddit.com" : { + type: 'testing', + DOM: { + player: { + manual: true, + useRelativeAncestor: false, + querySelectors: '.media-preview-content' + } + }, + css: '', + }, + "www.youtube.com" : { + DOM: { + player: { + manual: true, + querySelectors: "#movie_player, #player", + additionalCss: "", + useRelativeAncestor: false, + playerNodeCss: "", + } + } + }, + } + } +} + +export default ExtensionConfPatch; \ No newline at end of file diff --git a/src/ext/lib/ObjectCopy.js b/src/ext/lib/ObjectCopy.js index 398d26e..705613b 100644 --- a/src/ext/lib/ObjectCopy.js +++ b/src/ext/lib/ObjectCopy.js @@ -46,6 +46,32 @@ class ObjectCopy { return out; } + static overwrite(existing, target){ + for(var k in target) { + // if current key exist, replace it with existing value. Take no action otherwise. + if (existing[k]) { + + // Types and constructors of objects must match. If they don't, we always use the new value. + if (typeof target[k] === typeof existing[k] && target[k].constructor === existing[k].constructor) { + + // objects are special, we need to check them recursively. + if(existing[k] && typeof existing[k] === 'object' && existing[k].constructor === Object ) { + if(Debug.debug && Debug.settings) { + console.log("[ObjectCopy::addNew] current key contains an object. Recursing!") + } + + existing[k] = this.overwrite(existing[k], target[k]); + } else { + existing[k] = target[k]; + } + } else { + existing[k] = target[k]; + } + } + } + return existing; + } + static pruneUnused(existing, target, ignoreKeys) { // TODO: implement at some other date // existing: object that we have. diff --git a/src/ext/lib/Settings.js b/src/ext/lib/Settings.js index 21238eb..d935ed7 100644 --- a/src/ext/lib/Settings.js +++ b/src/ext/lib/Settings.js @@ -5,6 +5,7 @@ import ExtensionMode from '../../common/enums/extension-mode.enum'; import ObjectCopy from '../lib/ObjectCopy'; import Stretch from '../../common/enums/stretch.enum'; import VideoAlignment from '../../common/enums/video-alignment.enum'; +import ExtensionConfPatch from '../conf/ExtConfPatches'; @@ -108,6 +109,7 @@ class Settings { if(Debug.debug) { console.log("[Settings::init] extension was saved with current version of ultrawidify (", this.version, "). Returning object as-is."); } + return this.active; } @@ -124,6 +126,9 @@ class Settings { this.active = JSON.parse(JSON.stringify(this.default)); } + // in case settings in previous version contained a fucky wucky, we overwrite existing settings with a patch + ObjectCopy.overwrite(this.active, ExtensionConfPatch['4.2.0']); + this.set(this.active); return this.active; }