forked from nsand/tab-glutton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.html
126 lines (116 loc) · 3.5 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
<!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() {
chrome.tabs.getAllInWindow(null, function(tabs) {
var list = $("#list");
var i = 0;
for (; i < tabs.length ; i++) {
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 (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);
}
document.getElementById("field").onkeyup = function() {
if (typing == null) {
typing = setTimeout(refresh, TYPING_DELAY);
}
else {
clearTimeout(typing);
typing = setTimeout(refresh, TYPING_DELAY);
}
};
});
document.getElementById("field").focus();
}
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 = $("#field").val();
var exp = null;
if (value != null && value.replace(/^\s*/,"").length > 0)
exp = value;
var re = exp != null ? new RegExp(exp, "i") : null;
$("#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();
}
});
}
/* 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>
<body onload="load()">
<div id="content">
<div id="search">
<input id="field">
</div>
<div class="scrollable" >
<ul id="list"></ul>
</div>
</div>
</body>
</html>