/
scriptIcon.js
45 lines (40 loc) · 1.35 KB
/
scriptIcon.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
var EXPORTED_SYMBOLS = ['ScriptIcon'];
Components.utils.import('resource://greasemonkey/scriptDependency.js');
Components.utils.import('resource://greasemonkey/util.js');
ScriptIcon.prototype = new ScriptDependency();
ScriptIcon.prototype.constructor = ScriptIcon;
function ScriptIcon(aScript) {
ScriptDependency.call(this, aScript);
this.type = 'ScriptIcon';
}
ScriptIcon.prototype.__defineGetter__('fileURL',
function ScriptIcon_getFileURL() {
if (this._dataURI) {
return this._dataURI;
} else if (this._filename) {
return GM_util.getUriFromFile(this.file).spec;
} else {
return 'chrome://greasemonkey/skin/userscript.png';
}
});
ScriptIcon.prototype.__defineSetter__('fileURL',
function ScriptIcon_setFileURL(iconURL) {
if (/^data:/i.test(iconURL)) {
// icon is a data scheme
this._dataURI = iconURL;
} else if (iconURL) {
// icon is a file
this._filename = iconURL;
}
});
ScriptIcon.prototype.setMetaVal = function(value) {
// accept data uri schemes for image mime types
if (/^data:image\//i.test(value)) {
this._dataURI = value;
} else if (/^data:/i.test(value)) {
throw new Error('@icon data: uri must be an image type');
} else {
var resUri = GM_util.uriFromUrl(this._script._downloadURL);
this._downloadURL = GM_util.uriFromUrl(value, resUri).spec;
}
};