Created empty data pattern
This commit is contained in:
parent
a4c2ae5ba1
commit
e728a3c380
2 changed files with 20 additions and 27 deletions
44
lib/popup.js
44
lib/popup.js
|
@ -62,6 +62,16 @@
|
||||||
'//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js'
|
'//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
host: undefined,
|
||||||
|
emptyDataPattern: {
|
||||||
|
config: {
|
||||||
|
enable: false,
|
||||||
|
include: '',
|
||||||
|
extra: ''
|
||||||
|
},
|
||||||
|
source: ''
|
||||||
|
},
|
||||||
|
data: null,
|
||||||
editor: {
|
editor: {
|
||||||
instance: null,
|
instance: null,
|
||||||
defaultValue: "// Here You can type your custom JavaScript...",
|
defaultValue: "// Here You can type your custom JavaScript...",
|
||||||
|
@ -235,6 +245,11 @@
|
||||||
delete response.customjs.src;
|
delete response.customjs.src;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set-up data pattern if empty
|
||||||
|
if( !popup.data ) {
|
||||||
|
popup.data = $.extend(true, {}, popup.emptyDataPattern);
|
||||||
|
}
|
||||||
|
|
||||||
// Merge host's data to defaults
|
// Merge host's data to defaults
|
||||||
popup.data = $.extend(popup.data, response.customjs);
|
popup.data = $.extend(popup.data, response.customjs);
|
||||||
|
|
||||||
|
@ -256,15 +271,6 @@
|
||||||
popup.applyData(popup.storage.get('draft'));
|
popup.applyData(popup.storage.get('draft'));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
host: undefined,
|
|
||||||
data: {
|
|
||||||
config: {
|
|
||||||
enable: false,
|
|
||||||
include: '',
|
|
||||||
extra: ''
|
|
||||||
},
|
|
||||||
source: ''
|
|
||||||
},
|
|
||||||
applyData: function(data, notDraft) {
|
applyData: function(data, notDraft) {
|
||||||
|
|
||||||
if( data && !notDraft ) {
|
if( data && !notDraft ) {
|
||||||
|
@ -374,14 +380,9 @@
|
||||||
|
|
||||||
// Remove customjs from frontend
|
// Remove customjs from frontend
|
||||||
chrome.tabs.sendRequest(popup.tabId, {method: "removeData", reload: false});
|
chrome.tabs.sendRequest(popup.tabId, {method: "removeData", reload: false});
|
||||||
popup.data = {
|
|
||||||
config: {
|
// Set-up empty data
|
||||||
enable: false,
|
popup.data = $.extend(true, {}, popup.emptyDataPattern);
|
||||||
include: '',
|
|
||||||
extra: ''
|
|
||||||
},
|
|
||||||
source: ''
|
|
||||||
};
|
|
||||||
popup.applyData();
|
popup.applyData();
|
||||||
|
|
||||||
popup.removeDraft();
|
popup.removeDraft();
|
||||||
|
@ -499,14 +500,7 @@
|
||||||
}
|
}
|
||||||
// Hotfix for host without customjs
|
// Hotfix for host without customjs
|
||||||
catch(err) {
|
catch(err) {
|
||||||
popup.applyData({
|
popup.applyData($.extend(true, {}, popup.emptyDataPattern), true);
|
||||||
config: {
|
|
||||||
enable: false,
|
|
||||||
include: '',
|
|
||||||
extra: ''
|
|
||||||
},
|
|
||||||
source: ''
|
|
||||||
}, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -7,14 +7,13 @@
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
|
|
||||||
"permissions": [
|
"permissions": [
|
||||||
|
"storage",
|
||||||
"http://*/",
|
"http://*/",
|
||||||
"https://*/",
|
"https://*/",
|
||||||
"tabs"
|
"tabs"
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
||||||
"tabs": {},
|
|
||||||
|
|
||||||
"icons": { "128": "img/icon_128.png" },
|
"icons": { "128": "img/icon_128.png" },
|
||||||
|
|
||||||
"content_security_policy": "script-src 'self' https://*.googleapis.com; object-src 'self'",
|
"content_security_policy": "script-src 'self' https://*.googleapis.com; object-src 'self'",
|
||||||
|
|
Reference in a new issue