forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontextScanWithVirusTotal.uc.js
90 lines (83 loc) · 3.09 KB
/
contextScanWithVirusTotal.uc.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// ==UserScript==
// @name contextScanWithVirusTotal.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description scan with Virus Total
// @include main
// @compatibility Firefox 56+
// @author Alice0775
// @version 2018/09/20 scan with clipboard
// @version 2018/09/18 e10s and remove overlay
// @version 2013/09/03 open child tab if tree style tab installed
// @version 2012/01/07
// @Note
// ==/UserScript==
var scanWithVirusTotal = {
handleEvent: function(event) {
switch (event.type) {
case "popupshowing":
this.onpopupshowing(event);
break;
case "unload":
this.uninit();
break;
}
},
init: function() {
let menuitem = document.createElement("menuitem");
menuitem.setAttribute("id", "context-scanWithVirusTotal");
menuitem.setAttribute("label", "Scan with VirusTotal");
menuitem.setAttribute("tooltip", "aHTMLTooltip");
menuitem.setAttribute("accesskey", "V");
menuitem.setAttribute("oncommand", "scanWithVirusTotal.scan();");
let ref = document.getElementById("context-bookmarklink");
ref.parentNode.insertBefore(menuitem, ref);
document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", this, false);
window.addEventListener("unload", this, false);
},
uninit: function() {
document.getElementById("contentAreaContextMenu").removeEventListener("popupshowing", this, false);
window.removeEventListener("unload", this, false);
},
onpopupshowing: function(event) {
this.linkURL = this.getTextLink(readFromClipboard());
if (gContextMenu.onLink) {
this.linkURL = gContextMenu.linkURL;
} else if (gContextMenu.onCanvas || gContextMenu.onImage ||
gContextMenu.onVideo || gContextMenu.onAudio) {
this.linkURL = gContextMenu.mediaURL;
} else if (gContextMenu.isTextSelected) {
this.linkURL = this.getTextLink(gContextMenu.selectionInfo.fullText);
}
let menuitem = document.getElementById("context-scanWithVirusTotal");
menuitem.hidden = !this.linkURL;
menuitem.setAttribute("tooltiptext", "Scan: " + this.linkURL);
},
getTextLink: function(linkText) {
let uri;
if (/^(?:https?|ftp):/i.test(linkText)) {
try {
uri = makeURI(linkText);
} catch (ex) {}
}
// Check if this could be a valid url, just missing the protocol.
else if (/^(?:\w+\.)+\D\S*$/.test(linkText) ||
/^(?:[a-z\d-]+\.)+[a-z]+$/i.test(linkText)) {
let uriFixup = Cc["@mozilla.org/docshell/urifixup;1"]
.getService(Ci.nsIURIFixup);
try {
uri = uriFixup.createFixupURI(linkText, uriFixup.FIXUP_FLAG_NONE);
} catch (ex) {}
}
if (uri && uri.host) {
return uri.spec;
}
return null;
},
scan: function() {
let url = "https://www.virustotal.com/url/submission/?force=1&url=" + escape(this.linkURL);
if ("TreeStyleTabService" in window)
TreeStyleTabService.readyToOpenChildTab(gBrowser.selectedTab, false);
openUILinkIn(url, 'tab');
}
}
scanWithVirusTotal.init();