forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteHistoryByLink.uc.js
128 lines (112 loc) · 3.53 KB
/
deleteHistoryByLink.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// ==UserScript==
// @name deleteHistoryByLink.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description リンクのソースを表示, 中クリックで新規タブ, 右クリックでサイドバー
// @include main
// @compatibility Firefox 4.0
// @author alice0775
// @version 2011/04/15
// ==/UserScript==
var deleteHistoryByLink = {
popup: null,
menuitem: null,
init: function() {
if ( window.location.href == "chrome://browser/content/web-panels.xul") {
var browser = document.createElement("web-panels-browser");
if (!/^(http|ftp|file)/.test(content.location.href))
return;
}
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("id","context-deleteHistoryByLink");
menuitem.setAttribute("label","Delete History By Link");
menuitem.setAttribute("accesskey","L");
menuitem.setAttribute("oncommand","deleteHistoryByLink.deleteHistory();");
var popup = document.getElementById("contentAreaContextMenu");
var refitem = document.getElementById("context-sep-copylink");
popup.insertBefore(menuitem, refitem);
popup.addEventListener("popupshowing", this, false);
this.popup = popup;
this.menuitem = menuitem;
window.addEventListener("unload", this, false);
},
uninit: function() {
if (this.popup) {
this.popup.removeEventListener("popupshowing", this, false);
}
window.removeEventListener("unload", this, false);
},
popupshowing: function(aEvent) {
this.onclick(aEvent);
var schemes = "https?|ftp|file|data|resource|chrome|about|jar|view-source";
var regScheme = new RegExp(schemes, "i");
var isLinkViewable = regScheme.test(this.linkProtocol);
this.showItem(this.menuitem, this.onLink && isLinkViewable);
},
target: null,
get linkProtocol() {
if (this.linkURI)
return this.linkURI.scheme; // can be |undefined|
return null;
},
get onLink() {
return !!this.target;
},
get linkURL() {
return (this.target) ? this.target.href : null;
},
get linkURI() {
try {
return makeURI(this.linkURL);
} catch (ex) {
return null;
}
},
showItem:function(menu, show){
if (menu)
(show) ? menu.removeAttribute('hidden')
: menu.setAttribute('hidden', true)
},
onclick: function(aEvent) {
var target = document.popupNode;
this.target = null;
while (target.nodeType == Node.ELEMENT_NODE) {
try {
if ((target instanceof HTMLAnchorElement && target.href) ||
(target instanceof HTMLAreaElement && target.href) ||
target instanceof HTMLLinkElement ||
target.getAttributeNS("http://www.w3.org/1999/xlink", "type") == "simple")
this.target = target;
} catch (e) { }
target = target.parentNode;
}
},
deleteHistory: function() {
var url = this.linkURL;
try {
var uri = makeURI(url);
var bhist = PlacesUtils.history.QueryInterface(Ci.nsIBrowserHistory);
bhist.removePage(uri);
//repaint
var p = this.target.parentNode;
var next = this.target.nextSibling;
var elm = p.removeChild(this.target);
this.target = p.insertBefore(elm, next);
} catch (ex) {
return;
}
},
handleEvent: function(aEvent) {
switch (aEvent.type) {
case 'popupshowing':
this.popupshowing(aEvent);
break;
case 'command':
this.deleteHistory(aEvent);
break;
case 'unload':
this.uninit();
break;
}
}
}
deleteHistoryByLink.init();