/
scripticon.js
58 lines (51 loc) · 1.61 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
46
47
48
49
50
51
52
53
54
55
56
57
58
function ScriptIcon(script) {
ScriptResource.call(this, script);
this.type = "icon";
this._dataURI = null;
this.dataUriError = false;
}
// Inherit from ScriptResource
ScriptIcon.prototype = new ScriptResource();
ScriptIcon.prototype.constructor = ScriptIcon;
ScriptIcon.prototype.__defineSetter__("metaVal", 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)) {
this.dataUriError = true;
throw new Error('@icon data: uri must be an image type');
} else {
var resUri = GM_uriFromUrl(this._script._downloadURL);
this._downloadURL = GM_uriFromUrl(value, resUri).spec;
}
});
ScriptIcon.prototype.hasDownloadURL = function() {
return !!this._downloadURL;
};
ScriptIcon.prototype.isImage = function(contentType) {
return /^image\//i.test(contentType);
};
ScriptIcon.prototype.__defineGetter__("filename",
function ScriptIcon_getFilename() {
return (this._filename || this._dataURI);
});
ScriptIcon.prototype.__defineGetter__("fileURL",
function ScriptIcon_getFileURL() {
if (this._dataURI) {
return this._dataURI;
} else if (this._filename) {
return GM_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;
}
});