/
pt_tweak_main.js
63 lines (51 loc) · 1.46 KB
/
pt_tweak_main.js
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
/*global $:false */
/* exported inject_script */
console.log('PT Tweaks Loading');
/**
* Helper method to inject scripts into a page.
*/
function inject_script(scriptFile) {
var s = document.createElement('script');
s.src = chrome.extension.getURL(scriptFile);
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
}
// Code to inject immediately
// todo: get this loaded as part of configuration
inject_script('epic_overrides.js');
(function(exports) {
function App() {
this.options = null;
this._optionWatchers = [];
}
_.extend(App.prototype, {
start: function() {
var me = this;
chrome.extension.sendRequest(
{ name: "getOptions" },
function(data) {
// Store the options list
me.options = data;
// Notify all listeners
_.each(me._optionWatchers, function(handler) {
handler(data);
});
// Clear the handler list
me._optionWatchers = null;
}
);
},
onOptionsLoaded: function(handler) {
if (! this.options) {
this._optionWatchers.push(handler);
}
else {
handler(this.options);
}
}
});
var extension = exports.PTT = new App();
$().ready(_.bind(extension.start, extension));
})(window);