-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathunload-tab.js
89 lines (79 loc) · 2.54 KB
/
unload-tab.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
/*
* タブを削除せずに、セッションを残しつつコンテンツをアンロードさせるエコなコマンド
* unload[tab] num
*/
/*
Thu, 11 Jul 2013 01:55:46 +0800
unload[tab] negative_number
for unload all tab without seleted tab
set tab title opacity when unload or restore
*/
var INFO = xml`
<plugin name="unloadTab"
version="0.3"
summary="Unload tab contents like (BarTab)"
xmlns="http://vimperator.org/namespaces/liberator">
<author email="[email protected]">teramako</author>
<license>MPL 1.1/GPL 2.0/LGPL 2.1</license>
<project name="Vimperator" minVersion="3.1"/>
<item>
<tags>:unloadtab :unload</tags>
<spec>:unload<oa>tab</oa> <a>tabNumber</a></spec>
<description>
<p>Unload the tab contents.</p>
</description>
</item>
</plugin>`;
if (!("SS" in this)) {
XPCOMUtils.defineLazyServiceGetter(this, "SS", "@mozilla.org/browser/sessionstore;1", "nsISessionStore");
}
function unloadTab (aTab) {
var browser = aTab.linkedBrowser,
state = SS.getTabState(aTab),
shistory = browser.sessionHistory,
icon = aTab.getAttribute("image");
browser.addEventListener("load", function onload(){
this.removeEventListener("load", onload, true);
if (shistory.count > 1)
shistory.PurgeHistory(shistory.count -1);
aTab.ownerDocument.defaultView.setTimeout(function(){
aTab.setAttribute("image", icon);
}, 0);
SS.setTabState(aTab, state);
}, true);
browser.loadURI("about:blank");
}
commands.addUserCommand(["unload[tab]"], "Unload Tabs",
function action (args) {
var str = args[0];
var m = str.match(/^(-?\d+):?/);
if (!m)
return;
var tab = gBrowser.tabs[m[1]];
if (tab && !tab.selected && !tab.linkedBrowser.__SS_restoreState)
unloadTab(tab), tab.style.opacity = 0.5 ;
// unload other tabs
if (m[1] < 0)
for each(tab in Array.slice(gBrowser.tabs))
if(tab && !tab.selected){
if(!tab.linkedBrowser.__SS_restoreState) unloadTab(tab);
tab.style.opacity = 0.5 ;
}
}, {
literal: 0,
completer: function (context, args) {
context.anchored = false;
context.completions = [
for (tab of Array.slice(gBrowser.tabs))
if (!tab.selected && !tab.linkedBrowser.__SS_restoreState)
[tab._tPos + ": " + tab.label, tab.linkedBrowser.currentURI.spec]
];
}
}, true);
// the listener for recovering opacity
gBrowser.tabContainer.addEventListener('SSTabRestored',
function tabRestored(event){
var tab = event.originalTarget ;
tab.style.opacity = 1 ;
}
, true);