-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewtab.js
More file actions
91 lines (84 loc) · 2.46 KB
/
newtab.js
File metadata and controls
91 lines (84 loc) · 2.46 KB
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
var bookmarks = chrome.bookmarks;
function readBooks() {
var box = null;
var createPanel = function (node) {
var tmp = $("#siteSetTemp").html();
str = tmp.replace(/#id#/g, node.id);
str = str.replace(/#title#/g, node.title);
return str;
};
var createSite = function (node) {
bookmarks.getChildren(node.id, function (children) {
var tmp = $("#siteTemp").html();
var str = "";
var panel = createPanel(node);
panel = $(panel);
var site = null;
for (var i = 0; i < children.length; i++) {
site = children[i];
if (site.url == null || site.url == "") {
continue;
}
str = tmp.replace(/#url#/g, site.url);
str = str.replace(/#title#/g, site.title);
str = str.replace(/#icon#/g, getIcon(site));
panel.append(str);
}
panel.find("img").bind("error", function () {
$(this).attr('src', 'default.png');
console.log("error");
});
$("#panel").append(panel);
});
};
bookmarks.search("favorites", function (items) {
if (items == null || items.length == 0) return;
box = items[0];
if (box == null) { return; }
box.title = "常用站点";
createSite(box);
bookmarks.getChildren(box.id, function (children) {
var site = null;
for (var i = 0; i < children.length; i++) {
site = children[i];
if (site.url == null || site.url == "") {
createSite(site);
}
}
});
});
}
function getIcon(site) {
var us = site.url.split("/");
iconUrl = us[0] + "//" + us[2] + "/favicon.ico";
return iconUrl;
}
function getIconByNet(url) {
var ret;
$.ajax({
url: getIconUrl(url),
type: "get",
async: false,
success: function (d, p) {
}
});
return ret;
}
function getIconByStore(id) {
var store = localStorage;
var icons = store.getItem("iconSet");
icons = $.parseJSON(icons);
return icons[id];
}
function getIconUrl(url) {
var us = url.split("/");
console.log(us);
iconUrl = us[0] + "//" + us[2] + "/favicon.ico";
return iconUrl;
}
$(function () {
readBooks();
$("#search").bind("click", function () {
$("#searcher").submit();
});
});