forked from samclark/pinboard
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.html
116 lines (107 loc) · 4.52 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
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Pinboard Toolbar Button</title>
<style type="text/css">
div.menu-item {
font: normal 12px helvetica, arial, verdana;
padding: 4px;
text-indent: 22px;
cursor: hand;
color: #555;
width: 143;
background-color: #fff;
background-image: url('gray_star.png');
background-repeat: no-repeat;
background-position: 5px 5px;
border-bottom: 1px solid #eee;
}
div.menu-item:first-child {
-webkit-border-top-left-radius: 3px;
-webkit-border-top-right-radius: 3px;
}
div.menu-item:last-child {
-webkit-border-bottom-left-radius: 3px;
-webkit-border-bottom-right-radius: 3px;
border-bottom-style: none;
}
div.menu-item:hover {
color: #11A;
background-color: #f2f2f2;
background-image: url('blue_star.png');
}
</style>
<script type="text/javascript">
function addMenuItem(show, name, onClickFunction) {
if ("yes" == show) {
var parentElement = document.getElementById("menu");
var menuItemElement = document.createElement("div");
menuItemElement.setAttribute("class", "menu-item");
menuItemElement.setAttribute("onclick", onClickFunction);
menuItemElement.appendChild(document.createTextNode(name));
parentElement.appendChild(menuItemElement);
}
}
function addMenuItems() {
var options = chrome.extension.getBackgroundPage().getOptionAll();
if (options.userName && "" != options.userName) {
addMenuItem(options.showAllBookmarks, "All Bookmarks", "openUrl(\"http://pinboard.in/u:" + options.userName + "/\");");
addMenuItem(options.showPrivateBookmarks, "Private Bookmarks", "openUrl(\"http://pinboard.in/u:" + options.userName + "/private/\");");
addMenuItem(options.showPublicBookmarks, "Public Bookmarks", "openUrl(\"http://pinboard.in/u:" + options.userName + "/public/\");");
addMenuItem(options.showUnreadBookmarks, "Unread Bookmarks", "openUrl(\"http://pinboard.in/u:" + options.userName + "/unread/\");");
addMenuItem(options.showUntaggedBookmarks, "Untagged Bookmarks", "openUrl(\"http://pinboard.in/u:" + options.userName + "/untagged/\");");
addMenuItem(options.showStarredBookmarks, "Starred Bookmarks", "openUrl(\"http://pinboard.in/u:" + options.userName + "/starred/\");");
addMenuItem(options.showSaveBookmark, "Save Bookmark", "saveBookmark();");
addMenuItem(options.showReadLater, "Read Later", "readLater();");
}
else {
addMenuItem("yes", "Setup User Name", "openUrl(\"" + chrome.extension.getURL("options.html") + "\");");
}
}
function openUrl(url) {
chrome.tabs.getAllInWindow(null, function (tabs) {
for (var i in tabs) {
var tab = tabs[i];
if (tab.url == url || tab.url == url.replace("http://", "https://")) {
chrome.tabs.update(tab.id, {selected:true});
return;
}
}
chrome.tabs.create({url: url});
window.close();
});
}
function saveBookmark() {
chrome.tabs.getSelected(null , function(tab) {
chrome.tabs.sendRequest(tab.id, {method: "getSelection"}, function (response) {
var description = response.data;
if (description.length > 0) {
window.open("http://pinboard.in/add?jump=close&url=" + encodeURIComponent(tab.url) +
"&title=" + encodeURIComponent(tab.title) +
"&description=" + encodeURIComponent(description.substr(0, 256)),
"pinboad.in",
"location=no,links=no,scrollbars=no,toolbar=no,width=700,height=350");
} else {
window.open("http://pinboard.in/add?jump=close&url=" + encodeURIComponent(tab.url) +
"&title=" + encodeURIComponent(tab.title),
"pinboad.in",
"location=no,links=no,scrollbars=no,toolbar=no,width=700,height=350");
}
});
});
}
function readLater() {
chrome.tabs.getSelected(null , function(tab) {
window.open("http://pinboard.in/add?later=yes&noui=yes&jump=close&url=" + encodeURIComponent(tab.url) +
"&title=" + encodeURIComponent(tab.title),
"pinboad.in",
"location=no,links=no,scrollbars=no,toolbar=no,width=0,height=0");
});
}
</script>
</head>
<body onload="addMenuItems()">
<div id="menu">
</div>
</body>
</html>