forked from alice0775/userChrome.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgetHisoryForThisSite.uc.js
165 lines (144 loc) · 5.97 KB
/
forgetHisoryForThisSite.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// ==UserScript==
// @name forgetHisoryForThisSite.uc.js
// @namespace http://space.geocities.yahoo.co.jp/gl/alice0775
// @description ブックマークやタブからも指定ホストの履歴(クッキー,パスワードも)を消去出来るようにする, "Forget about this site" with Bookmarks and/or Tab.
// @include main
// @include chrome://browser/content/places/places.xul
// @include chrome://browser/content/bookmarks/bookmarksPanel.xul
// @include chrome://browser/content/history/history-panel.xul
// @compatibility Firefox 3.5, 3.6a1pre
// @author Alice0775
// @Note Require userChrome.js (download from http://mozilla.zeniko.ch/userchrome.js.xpi)
// @Note Require Sub-Script/Overlay Loader v3.0.24mod (download from http://space.geocities.jp/alice0775/STORE/userChrome.js)
// @version 2010/03/26 13:00 Minefield/3.7a4pre Bug 554991 - allow tab context menu to be modified by normal XUL overlays
// @version 2010/03/15 00:00 Minefield/3.7a4pre Bug 347930 - Tab strip should be a toolbar instead
// @version 2009/08/06 22:00 PlacesUtils._uriの例外
// @version 2009/07/08 14:40
// ==/UserScript==
var forgetHisoryForThisSite = {
tabContext : null,
deleteHost : null,
menuitem : null,
handleEvent : function(event) {
switch (event.type) {
case 'unload':
this.uninit();
break;
case 'popupshowing':
this.onPopupShowing();
break;
}
},
init: function() {
window.addEventListener('unload', this, false);
// Eneble Bookmarks & Live Bookmarks
this.deleteHost = document.getElementById("placesContext_deleteHost");
this.deleteHost.removeAttribute("forcehideselection");
// Enable for Live Bookmarks
var func = PlacesController.prototype.isCommandEnabled.toString();
func = func.replace(
'switch (aCommand) {',
<><![CDATA[
$&
case "placesCmd_deleteDataHost":
var selectedNode = this._view.selectedNode;
return selectedNode && PlacesUtils.nodeIsURI(selectedNode) &&
!PlacesUIUtils.privateBrowsing.privateBrowsingEnabled
]]></>
);
eval("PlacesController.prototype.isCommandEnabled = " + func);
// It decides whether to display "Delete Host."
// When "host" is not in history entry, "Delete Host" should be hidden.
func = PlacesController.prototype.buildContextMenu.toString();
func = func.replace(
'if (!item.hidden) {',
<><![CDATA[
if (!item.hidden && item.getAttribute("id") == "placesContext_deleteHost") {
var selectedNode = this._view.selectedNode;
if (PlacesUIUtils.privateBrowsing.privateBrowsingEnabled)
item.hidden = true;
if (selectedNode && PlacesUtils.nodeIsURI(selectedNode)) {
try {
var host = PlacesUtils._uri(selectedNode.uri).host;
item.hidden = !forgetHisoryForThisSite.isExistHostInHistory(host);
} catch(e) {
item.hidden = true;
}
}
}
$&
]]></>
);
eval("PlacesController.prototype.buildContextMenu = " + func);
// Preparation for tab context menu
if (location.href != "chrome://browser/content/browser.xul")
return;
// For tab Context Menu
this.tabContext = document.getAnonymousElementByAttribute(
gBrowser, "anonid", "tabContextMenu") ||
gBrowser.tabContainer.contextMenu;
this.tabContext.addEventListener("popupshowing", this, false);
},
uninit: function() {
if (this.tabContext)
this.tabContext.removeEventListener("popupshowing", this, false);
window.removeEventListener('unload', this, false);
},
// for tab context menu
onPopupShowing: function(event){
if (!this.menuitem) {
this.menuitem = document.createElement("menuitem");
this.menuitem.setAttribute("id", "forgetHisoryForThisSiteMenu");
this.menuitem.setAttribute("label", this.deleteHost.getAttribute('label'));
this.menuitem.setAttribute("accesskey", this.deleteHost.getAttribute('accesskey'));
this.menuitem.setAttribute("oncommand", "forgetHisoryForThisSite.doforgetHisoryForTab(gBrowser.mContextTab);");
this.menuitem.setAttribute("hidden", "true");
var ref = document.getElementById("context_closeTab");
this.tabContext.insertBefore(this.menuitem, ref.nextSibling);
}
var ishidden;
try {
var uri = gBrowser.getBrowserForTab(gBrowser.mContextTab).currentURI.spec;
var host = PlacesUtils._uri(uri).host;
ishidden = /*!this.isExistHostInHistory(host) ||*/
PlacesUIUtils.privateBrowsing.privateBrowsingEnabled;
} catch (e) {
ishidden = true;
}
this.menuitem.setAttribute("hidden", ishidden);
},
doforgetHisoryForTab: function(aTab){
var browser = gBrowser.getBrowserForTab(aTab);
var uri = browser.currentURI.spec
try {
var host = PlacesUtils._uri(uri).host;
PlacesUIUtils.privateBrowsing.removeDataFromDomain(host);
} catch (e) {
}
},
// Is "host" in history entry or not?
isExistHostInHistory: function(host) {
try {
var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"]
.getService(Components.interfaces.nsINavHistoryService);
// No query options set will get all history, sorted in database order,
// which is nsINavHistoryQueryOptions.SORT_BY_NONE.
var options = historyService.getNewQueryOptions();
options.queryType = options.QUERY_TYPE_HISTORY;
options.maxResults = 1;
// No query parameters will return everything
var query1 = historyService.getNewQuery();
query1.domain = host;
// execute the query
var result = historyService.executeQuery(query1, options);
var cont = result.root;
cont.containerOpen = true;
var isExist = cont.childCount > 0;
cont.containerOpen = false;
return isExist;
} catch(e) {
return false;
}
}
}
forgetHisoryForThisSite.init();