Repository navigation
Expand file tree
/
Copy pathoptions.js
More file actions
70 lines (52 loc) · 1.55 KB
/
Copy pathoptions.js
File metadata and controls
70 lines (52 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
(function($){
const SETTINGS_KEY = 'settings';
var Options = function() {}
Options.prototype.init = function() {
this.$rules = $(".js-rules");
this.$save = $(".js-save")
.bind("click", this.save.bind(this));
this.firstTimeLoad();
return this;
}
Options.prototype.firstTimeLoad = async function() {
const settings = await this._getSettings();
this.$rules.val(settings.rules.join("\n"));
}
Options.prototype.save = async function() {
const rules = this.$rules.val().split("\n");
const settings = await this._getSettings();
settings.rules = rules;
await this.update(settings);
chrome.extension.getBackgroundPage().faviconer.reload();
this.$save.attr("disabled", "disabled");
// Enable after text change.
this.$rules.one("keydown", function() {
this.$save.removeAttr("disabled");
}.bind(this));
}
Options.prototype.update = function(settings, callback) {
return new Promise((resolve) => {
chrome.storage.local.set({ [SETTINGS_KEY]: settings }, resolve);
});
}
Options.prototype._getSettings = function() {
return new Promise((resolve) => {
chrome.storage.local.get([ SETTINGS_KEY ], (result) => {
let settings = result[SETTINGS_KEY];
if (!settings || !settings.rules) {
settings = {
rules: []
};
}
resolve(settings);
});
});
};
Options.prototype.getEmpty = function() {
return {
rules: []
};
}
// Main.
new Options().init();
})(jQuery);