/
popup.html
126 lines (116 loc) · 3.75 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>
<script src="core.js"></script>
<script src="json2.js"></script>
<script>
function main() {
if (localStorage['HN.NumLinks'] == null)
{
buildPopupAfterResponse = true;
UpdateFeed();
}
else {
buildPopup(RetrieveLinksFromLocalStorage());
}
}
function buildPopup(links) {
var header = document.getElementById("header");
var feed = document.getElementById("feed");
var issueLink = document.getElementById("issues");
issueLink.addEventListener("click", openLinkFront);
//Setup Title Link
var title = document.getElementById("title");
title.addEventListener("click", openLink);
//Setup search button
var searchButton = document.getElementById("searchbutton");
searchButton.addEventListener("click", search);
for (var i=0; i<links.length; i++) {
hnLink = links[i];
var row = document.createElement("tr");
row.className = "link";
var num = document.createElement("td");
num.innerText = i+1;
var link_col = document.createElement("td")
var title = document.createElement("a");
title.className = "link_title";
title.innerText = hnLink.Title;
title.href = hnLink.Link;
title.addEventListener("click", openLink);
var comments = document.createElement("a");
comments.className = "comments";
comments.innerText = "(comments)";
comments.href = hnLink.CommentsLink;
comments.addEventListener("click", openLink);
link_col.appendChild(title);
link_col.appendChild(comments);
row.appendChild(num);
row.appendChild(link_col)
feed.appendChild(row);
}
hideElement("spinner");
showElement("container");
}
function searchOnEnter(e) {
if (e.keyCode == 13) {
search();
}
}
function search() {
var searchBox = document.getElementById("searchbox");
var keywords = searchBox.value;
if (keywords.length > 0) {
var search_url = "http://www.google.com/#hl=en&q=" + keywords + "+site%3Anews.ycombinator.com&fp=1&cad=b";
openUrl(search_url, true);
}
}
function refreshLinks() {
var linkTable = document.getElementById("feed");
while(linkTable.hasChildNodes()) linkTable.removeChild(linkTable.firstChild); //Remove all current links
toggle("container");
toggle("spinner");
buildPopupAfterResponse = true;
UpdateFeed();
updateLastRefreshTime();
}
//Submit the current tab
function submitCurrentTab() {
chrome.windows.getCurrent(function(win){
chrome.tabs.getSelected(win.id, function(tab){
var submit_url = "http://news.ycombinator.com/submitlink?u=" + encodeURIComponent(tab.url) + "&t=" + encodeURIComponent(tab.title);
openUrl(submit_url, true);
});
});
}
</script>
<link href="style.css" rel="stylesheet" type="text/css"/>
<style>
body {overflow: hidden;}
#container, #spinner {width:350px;}
</style>
</head>
<body onload="main();">
<div id="spinner" style="display:none">
<img src="ajax-loader.gif">
</div>
<div id="container" class="popup-container">
<div id="header">
<img src="icon18.gif">
<a id="title" href="http://news.ycombinator.com">Hacker News</a>
<span>|</span>
<a id="submitLink" href="javascript:submitCurrentTab()">Submit Current Page</a>
</div>
<div id="search">
<input type="text" id="searchbox" name="searchbox" placeholder="search hacker news..." onkeypress="searchOnEnter(event)" />
<input type="submit" id="searchbutton" value="search" />
</div>
<table id="feed" cellspacing="3" cellpadding="0">
</table>
<div id="footer">
<div class="right">
<a href="http://github.com/adamalbrecht/hacker-news-for-chrome/issues" id="issues">Issues?</a> | <a href="javascript:refreshLinks()" id="refresh">Refresh</a> | <a href="javascript:openOptions()" id="options">Options</a>
</div>
</div>
</div>
</body>
</html>