forked from nsand/tab-glutton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
170 lines (151 loc) · 4.43 KB
/
popup.html
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
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/css/style.css" type="text/css">
<script type="text/javascript" src="lib/jquery.js"></script>
<script type="text/javascript" src="lib/tg.js"></script>
<script>
// Delay filtering for typing speed
var TYPING_DELAY = 350;
// Typing timeout reference
var typing = null;
// Keep track of the current tab item
var current = null;
function load() {
var _windId = chrome.windows.WINDOW_ID_NONE;
/* Seems hacky, but window.selected seems to return false always for browser actions */
chrome.windows.getLastFocused(function(_wind) {
_windId = _wind.id;
});
chrome.windows.getAll({populate: true}, function(windows) {
var i = 0;
for (; i < windows.length; i++) {
addTabs(windows[i], _windId);
}
});
$(".tg_field").bind("keyup", function() {
if (typing == null) {
typing = setTimeout(refresh, TYPING_DELAY);
}
else {
clearTimeout(typing);
typing = setTimeout(refresh, TYPING_DELAY);
}
});
$(".tg_field")[0].focus();
}
function addTabs(wind, windId) {
var i = 0;
var tabs = wind.tabs;
if (tabs.length == 0)
return;
var list = $("<ul class='tg_tab_list'>");
for (; i < tabs.length ; i++) {
if (tabs[i].url == "chrome-extension://fcbnfpbonnllhepohamfgeokfbnfcjan/popup.html")
continue;
var li = $("<li>");
$.data(li[0], "tabId", tabs[i].id);
li.append(createActions(li));
li.append(createLink(tabs[i].favIconUrl, tabs[i].title, tabs[i].url));
li.append(createDescription(tabs[i].url));
if (windId == wind.id && tabs[i].selected) {
current = li;
current.addClass("current");
}
li.click(function(e) {
chrome.tabs.update($.data(this, "tabId"), { selected : true });
current.removeClass("current");
current = $(this).addClass("current");
});
//if (localStorage["showURL"] == "true" && localStorage["hoverURL"] == "true")
var details = localStorage["showURL"] == "true" && localStorage["hoverURL"] == "true";
li.hover(function() { showActions(this, details)}, function() { hideActions(this, details)});
list.append(li);
}
if (windId == wind.id) {
$(".scrollable").prepend(list);
if (localStorage["highlightWindow"] == "true")
list.addClass("tg_focused_window");
}
else {
$(".scrollable").append(list);
}
}
function showActions(tab, details) {
$(tab).toggleClass("hover");
if (details)
$(tab).find(".description").css("display", "block");
}
function hideActions(tab, details) {
$(tab).toggleClass("hover");
if (details)
$(tab).find(".description").css("display", "none");
}
/* Refresh the tab list after the delay */
function refresh() {
typing = null;
var value = $(".tg_field").val();
var exp = null;
if (value != null && value.replace(/^\s*/,"").length > 0)
exp = value;
var re = exp != null ? new RegExp(exp, "i") : null;
$(".tg_tab_list > li > .label").each(function(idx) {
if (re != null && !re.test($.data(this, "url")) && !re.test($(this).find("span").text())) {
$(this).parent().hide();
}
else {
$(this).parent().show();
}
});
$(".tg_tab_list").show();
$(".tg_tab_list").each(function(idx) {
if ($(this).find("li:visible").size() > 0) {
$(this).show();
}
else {
$(this).hide();
}
});
}
/* TODO Will need to escape the string for regular expressions */
function escapeString(str) {
}
function createLink(icon, title, url) {
var d = $("<div>").addClass("label");
$("<img>").appendTo(d).addClass("favicon").attr("src", icon || (url == "chrome://newtab/" ? "img/chromium_logo.png" : "img/defaultIcon.png"));
$("<span>").text(title || url).attr("title", title || url).appendTo(d);
$.data(d[0], "url", url);
return d;
}
function createDescription(desc) {
return $("<span>").addClass("description" + ((localStorage["showURL"] == "true" && localStorage["hoverURL"] != "true") ? " detail" : "")).text(desc);
}
/*
Create actions for tab items. [item] is the item in the tab list
to create the action for.
*/
function createActions(item) {
var actionContainer = $("<ul>").addClass("actions");
var action = $("<div>").appendTo("<li>").addClass("close").click(function(e) {
chrome.tabs.remove($.data(item[0], "tabId"), function() {
item.remove();
});
e.stopPropagation();
});
action.parent().appendTo(actionContainer);
return actionContainer;
}
</script>
<title>Tab Glutton</title>
</head>
<body onload="load()" class="tabglutton">
<div class="tg_content">
<div class="tg_search">
<input class="tg_field">
</div>
<div class="scrollable" >
<!--<ul class="tg_tab_list"></ul>-->
</div>
</div>
</body>
</html>