-
Notifications
You must be signed in to change notification settings - Fork 56
/
hateb-keysnail-collabo.ks.js
executable file
·290 lines (256 loc) · 11.8 KB
/
hateb-keysnail-collabo.ks.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
// PLUGIN INFO: {{{
var PLUGIN_INFO =
<KeySnailPlugin>
<name>Hatebnail</name>
<description>Use Hatena bookmark extension from KeySnail!</description>
<description lang="ja">はてなブックマーク拡張を KeySnail から使おう!</description>
<version>1.2.0</version>
<updateURL>http://github.com/mooz/keysnail/raw/master/plugins/hateb-keysnail-collabo.ks.js</updateURL>
<iconURL>http://github.com/mooz/keysnail/raw/master/plugins/icon/hateb-keysnail-collabo.icon.png</iconURL>
<author mail="stillpedant@gmail.com" homepage="http://d.hatena.ne.jp/mooz/">mooz</author>
<license>The MIT License</license>
<license lang="ja">MIT ライセンス</license>
<minVersion>0.9.6</minVersion>
<include>main</include>
<provides>
<ext>list-hateb-comments</ext>
<ext>list-hateb-items</ext>
</provides>
<options>
<option>
<name>hatebnail.list_bookmarks_limit</name>
<type>integer</type>
<description>Limit count of bookmark items to be displayed (Default: 5000)</description>
<description lang="ja">表示するブックマークの上限数 (デフォルト値: 5000)</description>
</option>
</options>
<detail lang="ja"><![CDATA[
=== 使い方 ===
このプラグインをインストールすることにより
- list-hateb-comments
- list-hateb-items
といったエクステが追加されます。
M-x など (ext.select を呼び出すキー) を入力することにより、これらのコマンドを実行することができます。
また .keysnail.js 内に次のような設定を記述することにより、特定のキーへコマンドを割り当てておくことも可能です。
>||
key.setGlobalKey(["C-M-c"], function (ev, arg) {
ext.exec("list-hateb-comments", arg);
}, "はてなブックマークのコメントを一覧表示", true);
key.setGlobalKey(["C-x", ";"], function (ev, arg) {
ext.exec("list-hateb-items", arg);
}, "はてなブックマークのアイテムを一覧表示", true);
||<
上記のような設定により C-M-c で「現在閲覧しているページのはてなブックマークのコメント一覧」を、 C-x ; により「自分のはてなブックマーク一覧」を、それぞれ表示することが可能となります。
]]></detail>
</KeySnailPlugin>;
// }}}
// ChangeLog : {{{
//
// ==== 1.2.0 (2009 12/20) ====
//
// * Supported , in the URL.
//
// ==== 1.1.9 (2009 12/05) ====
//
// * Supported % in the URL.
//
// ==== 1.1.8 (2009 11/23) ====
//
// * Added action "Open URL in the comment".
//
// ==== 1.1.7 (2009 11/15) ====
//
// * Added some useful actions.
//
// ==== 1.1.6 (2009 11/04) ====
//
// * Added option "hatebnail.list_bookmarks_limit".
//
// ==== 1.1.5 (2009 11/02) ====
//
// * Made "No bookmarks found" message displayed correctly.
//
// }}}
var hblist;
ext.add("list-hateb-comments", listHBComments, M({ja: 'このページのはてなブックマークコメントを一覧表示',
en: 'List hatena bookmark comments of this page'}));
ext.add("list-hateb-items" , listHBItems, M({ja: "はてなブックマークのアイテムを一覧表示しジャンプ",
en: 'List all hatena bookmark entries in prompt.selector'}));
function showCommentOfPage(aPageURL, aArg) {
if (KeySnail.windowType != "navigator:browser" || !hBookmark)
return;
const HB_USER_ICON = 0;
const HB_USER_NAME = 1;
const HB_TAGS = 2;
const HB_COMMENT = 3;
const HB_DATE = 4;
const B_URL = 'http://b.hatena.ne.jp/';
function iconGetter(aRow) {
return aRow[HB_USER_ICON] = hBookmark.UserUtils.getProfileIcon(aRow[HB_USER_NAME]);
}
hBookmark.HTTPCache.comment.async_get(
aPageURL,
function (data) {
if (!data || !data.title) {
display.echoStatusBar(M({ja: 'ブックマークが見つかりませんでした',
en: "No bookmarks found"}), 2000);
return;
}
var collection = [];
var bookmarks = data.bookmarks;
for (var i = 0; i < bookmarks.length; ++i) {
var bookmark = bookmarks[i];
if (!bookmark.comment && (aArg == null))
continue;
collection.push([iconGetter, bookmark.user, bookmark.tags.toString(), bookmark.comment, bookmark.timestamp]);
}
if (!collection.length) {
display.echoStatusBar(M({ja: ((aArg == null) ? 'コメント付きの' : '') + 'ブックマークが見つかりませんでした',
en: "No bookmarks found"}), 2000);
return;
}
function getPermaLink(aRow) {
var userLink = B_URL + aRow[HB_USER_NAME] + '/';
var ymd = aRow[HB_DATE].split(' ')[0];
return userLink + ymd.replace(/\//g, '') + '#bookmark-' + bookmarks.eid;
}
prompt.selector(
{
message: "pattern:",
collection: collection,
flags: [ICON | IGNORE, 0, 0, 0, 0],
style: ["color:blue;", "color:#3c5bff;", null, "color:#989898;"],
header: ["User", "Tags", "Comment", "Date"],
width: [15, 25, 45, 15],
actions: [
[function (aIndex) {
if (aIndex >= 0) {
var url = getPermaLink(collection[aIndex]);
openUILinkIn(url, "tab");
}
}, M({ja: '選択中ユーザのブックマークコメントページを新しいタブで開く',
en: "Open User Comment Page in new tab"})],
[function (aIndex) {
if (aIndex >= 0) {
command.setClipboardText(collection[aIndex][HB_COMMENT]);
}
}, M({ja: 'コメントをクリップボードにコピー',
en: "Copy selected comment"})],
[function (aIndex) {
if (aIndex >= 0) {
display.prettyPrint(collection[aIndex][HB_COMMENT], {timeout: 6000, fade: 300});
}
}, M({ja: 'コメントを全文表示',
en: "Display entire comment"})],
[function (aIndex) {
var matched;
var comment = collection[aIndex][HB_COMMENT];
while ((matched = comment.match("(h?t?tps?|ftp)(://[a-zA-Z0-9/?;#_*,.:/=&%\\-]+)")))
{
var prefix = (matched[1] == "ftp") ? "ftp" : "http";
if (matched[1][matched[1].length - 1] == 's')
prefix += "s";
gBrowser.loadOneTab(prefix + matched[2], null, null, null, false);
comment.text = comment.text.slice(comment.text.indexOf(matched[2]) + matched[2].length);
}
}, M({ja: 'コメント中の URL を開く',
en: 'Open URL in the comment'})]
]
}
);
});
};
function listHBComments(aEvent, aArg) {
showCommentOfPage(content.location.href, aArg);
};
function listHBItems(aEvent, aArg) {
if (KeySnail.windowType != "navigator:browser")
return;
var limit = plugins.options["hatebnail.list_bookmarks_limit"] || 5000;
const HB_ICON = 0;
const HB_TITLE = 1;
const HB_COMMENT = 2;
const HB_URL = 3;
const HB_DATE = 4;
const HB_SEARCH = 5;
function iconGetter(aRow) {
return aRow[HB_ICON] = util.getFaviconPath(aRow[HB_URL]);
}
function getDate(aString) {
return L(aString.slice(0, 4) + " 年 " + aString.slice(4, 6) + " 月 " + aString.slice(6, 8)
+ " 日 " + aString.slice(8, 10) + ":" + aString.slice(10, 12));
}
function getURL(aIndex) {
return hblist[aIndex][HB_URL];
}
// by adding prefix arugment to force rebuild the cache
if (!hblist || aArg != null) {
if (!hBookmark.User.user) {
hBookmark.User.login();
util.sleep(2000);
}
var db = hBookmark.User.user.database.connection;
var stmt = db.createStatement(["SELECT b.title, b.comment, b.url, b.date, b.search",
"FROM bookmarks b",
"ORDER BY b.date DESC"].join(" "));
var count = 0;
var bookmarks = [];
while (stmt.executeStep() && count++ < limit) {
// icon, title, comment, url, date, search,
bookmarks.push([iconGetter, stmt.getString(0), stmt.getString(1),
stmt.getString(2), getDate(stmt.getString(3)), stmt.getString(4)]);
}
hblist = bookmarks;
}
prompt.selector(
{
message: "pattern:",
collection: hblist,
flags: [ICON | IGNORE, IGNORE, IGNORE, HIDDEN | IGNORE, IGNORE, HIDDEN],
style: [null, "color:#0a1e89;", "color:#001d6b;"],
header: ["Title", "Comment", "Date"],
width: [40, 45, 15],
actions: [
[function (aIndex) {
if (aIndex >= 0) {
openUILinkIn(getURL(aIndex), "tab");
}
}, M({en: "Open Link in new tab (foreground)", ja: "新しいタブで開く (前面)"})],
[function (aIndex) {
if (aIndex >= 0) {
openUILinkIn(getURL(aIndex), "tabshifted");
}
}, M({en: "Open Link in new tab (background)", ja: "新しいタブで開く (背面)"})],
[function (aIndex) {
if (aIndex >= 0) {
openUILinkIn(getURL(aIndex), "window");
}
}, M({en: "Open Link in new window", ja: "新しいウィンドウで開く (背面)"})],
[function (aIndex) {
if (aIndex >= 0) {
openUILinkIn(getURL(aIndex), "current");
}
}, M({en: "Open Link in current tab", ja: "現在のタブで開く"})],
[function (aIndex) {
if (aIndex >= 0)
hBookmark.AddPanelManager.showPanel(getURL(aIndex));
}, M({en: "Edit bookmars entry", ja: "選択中のブックマークエントリを編集"})],
[function (aIndex) {
if (aIndex >= 0) {
var url = getURL(aIndex);
showCommentOfPage(url);
}
}, M({en: "Show comments of the selected item's page", ja: "選択中のブックマークエントリについたコメントを見る"})],
[function (aIndex) {
if (aIndex >= 0) {
var url = getURL(aIndex);
var match = url.match("(ftp|https?)://(.*)");
if (match) {
openUILinkIn("http://b.hatena.ne.jp/entry/" + match[2], "tab");
}
}
}, M({en: "Show hatena bookmark page of selected item", ja: "選択中アイテムのブックマークエントリページへ"})]
]
}
);
};