Super ghetto patching
This commit is contained in:
parent
d5acab1c40
commit
04a6c11cf5
44
src/ext/conf/ExtConfPatches.js
Normal file
44
src/ext/conf/ExtConfPatches.js
Normal file
@ -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;
|
@ -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.
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user