-
Notifications
You must be signed in to change notification settings - Fork 1
/
bundle-sources.js
119 lines (117 loc) · 3.23 KB
/
bundle-sources.js
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
/*
* Anychrome.crx
* writtern By Takaya Tsujikawa <http://github.com/mechairoi>.
*
* Released under the MIT License
*/
Anychrome.defineSource ({
name: "tab",
title: "Tab",
candidates: function (callback) {
chrome.tabs.query({}, callback);
},
candidatesTransformer: function (callback, tabs) {
callback(
tabs.map(
function(tab) {
return {
id : tab.id.toString(),
element : $("<li>").addClass("nowrap").append(
$('<img>').addClass('favicon').attr({"src": tab.favIconUrl, width: "16px", height: "16px"}),
$('<span>').text(tab.title),
$('<span>').addClass('url').text(
tab.url.match("^http://") ? tab.url.substr(7) : tab.url
)
)[0],
entity: tab
};
}
)
);
},
actions: [
{
name: "Switch",
fn : function (tabs) {
chrome.tabs.update(tabs[0].id, { selected : true });
}
},
{
name: "Close",
fn : function (tabs) {
tabs.forEach(function(tab) { chrome.tabs.remove(tab.id, function () {} ); });
}
}
],
regex: true,
migemo: 3
}, function () {});
$.each(
{day:[0, 1], week: [1, 7], month: [7, 31]},
function(key, value) {
Anychrome.defineSource (
{
name: "history_" + key,
title: "History " + key,
delayed: 0.1,
requiresPattern: 3, // XXX not implemented
// migemo: 3,
// regex: true,
candidates: function(callback, query) {
chrome.history.search(
{
text: query.join(" "),
startTime: (new Date()).getTime()
- 1000 * 60 * 60 * 24 * value[1],
endTime: (new Date()).getTime()
- 1000 * 60 * 60 * 24 * value[0],
maxResults: 30
},
callback
);
},
candidatesTransformer: function(callback, historyItems) {
callback(
historyItems.map(
function(historyItem) {
return {
id: historyItem.id,
name: historyItem.url + historyItem.title,
element: $("<li>").addClass("nowrap").append(
$('<span>').text(historyItem.title),
$('<span>').addClass('url').text(
historyItem.url.match("^http://") ? historyItem.url.substr(7) : historyItem.url
)
)[0],
entity: historyItem
};
}
)
);
},
actions: [
// {
// name: "Open in current tab",
// fn : function (history_items) {
// }
// },
{
name: "Open in new tab",
fn : function (historyItems) {
historyItems.forEach(
function (historyItem) {
chrome.tabs.create({url: historyItem.url}, function () {});
}
);
}
}
// {
// name: "Open in new window",
// fn : function (history_items) {
// }
// }
]
}, function () {}
);
}
);