-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path.keysnail.js
399 lines (328 loc) · 13.6 KB
/
.keysnail.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
// ========================== KeySnail Init File =========================== //
// この領域は, GUI により設定ファイルを生成した際にも引き継がれます
// 特殊キー, キーバインド定義, フック, ブラックリスト以外のコードは, この中に書くようにして下さい
// ========================================================================= //
//{{%PRESERVE%
// ここにコードを入力して下さい
for each (let id in ["keysnail-prompt-textbox", "urlbar"]) {
let box = document.getElementById(id);
let input = document.getAnonymousElementByAttribute(box, 'anonid', 'input');
if (input)
input.style.imeMode = "inactive";
}
plugins.options["hok.hint_keys"] = "hjklyuiopnm";
plugins.options["hok.actions"] = [
['x',
M({ja: "要素のXPathをコピー", en: "copy XPath"}),
function (elem)
{
function getElementXPath (elem) {
if (elem.nodeType == 9) { // DOCUMENT_NODE = 9
return "";
}
if (elem.hasAttribute("id")) {
return 'id("'+elem.getAttribute("id")+'")';
}
let name = elem.tagName.toLowerCase();
let parent = elem.parentNode;
let path = arguments.callee(parent)+"/"+name;
let children = Array.filter(parent.childNodes,
function(e) e.nodeName == elem.nodeName && e.nodeType == elem.nodeType);
if (children.length != 1 && children[0]!=elem) {
path += "["+(children.indexOf(elem)+1)+"]";
}
return path;
}
command.setClipboardText(getElementXPath(elem));
}],
];
ext.add("dialog-keysnail-plugin", function () openDialog("chrome://keysnail/content/pluginmanager.xul", "_blank", null));
ext.add("dialog-keysnail-preference", function () openDialog("chrome://keysnail/content/preference.xul", "_blank", null));
style.register("#keysnail-twitter-client-container{ display:none !important; }");
plugins.options["twitter_client.popup_new_statuses"] = false;
plugins.options["twitter_client.automatically_begin"] = false;
plugins.options["twitter_client.timeline_count_beginning"] = 0;
plugins.options["twitter_client.timeline_count_every_updates"] = 0;
plugins.options["follow-link.targets"] = 'a[href], input:not([type="hidden"]), button';
plugins.options["follow-link.nextpattern"] = "^次へ|進む|^次.*|続|→|\\bnext|Next|≫";
plugins.options["follow-link.prevpattern"] = "\\bback|戻る|^前.*|←|\\bprev|Before|≪";
function findPattern(doc, pattern) {
let target = plugins.options["follow-link.targets"];
let regex = RegExp(pattern);
let result = doc.querySelectorAll(target);
for (let i=result.length-1;i>=0;--i) {
let elem = result[i];
if (regex.test(elem.textContent) || regex.test(elem.value)) {
return elem;
}
}
return false;
}
function findRel(doc, rel) {
for each(let query in ['a[rel~="%s"]', 'link[rel~="%s"]']) {
let link = doc.querySelector(util.format(query, rel));
if (link)
return link;
}
return false;
}
function followLink(doc, rel, pattern) {
let link = findRel(doc, rel) || findPattern(doc, pattern);
if (link);
plugins.hok.followLink(link, plugins.hok.CURRENT_TAB)
}
ext.add("follow-next-link", function () followLink(content.document, "next", plugins.options["follow-link.nextpattern"]), "follow next link");
ext.add("follow-prev-link", function () followLink(content.document, "prev", plugins.options["follow-link.prevpattern"]), "follow previous link");
function digitURI(num) {
function tostr(num, len) {
let str = String(num);
while(str.length<len) {
str = "0" + str;
}
return str;
}
let pattern = /^(.*\D|)(\d+)(\D*)$/;
let url = content.location.href;
let digit = url.match(pattern);
if (digit) {
let numstr = tostr(num + parseInt(digit[2], 10), digit[2].length);
content.location.href = digit[1] + numstr + digit[3];
return true;
}
return false;
}
ext.add("digit-url-incement", function () digitURI(1), "increment last digit in URL");
ext.add("digit-url-decement", function () digitURI(-1), "decrement last digit in URL");
//}}%PRESERVE%
// ========================================================================= //
// ========================= Special key settings ========================== //
key.quitKey = "ESC";
key.helpKey = "undefined";
key.escapeKey = "<f7>";
key.macroStartKey = "undefined";
key.macroEndKey = "undefined";
key.universalArgumentKey = "undefined";
key.negativeArgument1Key = "undefined";
key.negativeArgument2Key = "undefined";
key.negativeArgument3Key = "undefined";
key.suspendKey = "`";
// ================================= Hooks ================================= //
hook.setHook('KeyBoardQuit', function (ev) {
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_ESCAPE, true);
var elem = document.commandDispatcher.focusedElement;
if (elem) {
elem.blur();
}
command.closeFindBar();
if (!document.getElementById("keysnail-prompt").hidden) {
prompt.finish(true);
}
gBrowser.focus();
content.focus();
});
// ============================== Black list =============================== //
hook.addToHook("LocationChange", function (aNsURI) {
var URL = aNsURI ? aNsURI.spec : null;
key.suspendWhenMatched(URL, key.blackList);
});
key.blackList = [
'http://fastladder.com/'
];
// ============================= Key bindings ============================== //
key.setViewKey(['g', 'o'], function (ev, arg) {
ext.exec("quickmark-open-page", arg, ev);
}, 'Open Page (QuickMark)', true);
key.setViewKey([['g', 'T'], ['h'], ['C-p']], function () {
getBrowser().mTabContainer.advanceSelectedTab(-1, true);
}, 'ひとつ左のタブへ');
key.setViewKey([['g', 't'], ['l'], ['C-n']], function () {
getBrowser().mTabContainer.advanceSelectedTab(1, true);
}, 'ひとつ右のタブへ');
key.setViewKey(['g', 'g'], function () {
goDoCommand("cmd_scrollTop");
}, 'ページ先頭へ移動', true);
key.setViewKey(['g', 'u'], function () {
var uri = getBrowser().currentURI;
if (uri.path == "/") {
return;
}
var pathList = uri.path.split("/");
if (!pathList.pop()) {
pathList.pop();
}
loadURI(uri.prePath + pathList.join("/") + ("/"));
}, '一つ上のディレクトリへ移動');
key.setViewKey(['g', 'U'], function () {
var uri = window._content.location.href;
if (uri == null) {
return;
}
var root = uri.match(/^[a-z]+:\/\/[^/]+\//);
if (root) {
loadURI(root, null, null);
}
}, 'ルートディレクトリへ移動');
key.setViewKey(['g', 'i'], function () {
command.focusElement(command.elementsRetrieverTextarea, 0);
}, '最初のインプットエリアへフォーカス', true);
key.setViewKey(['g', 'j'], function (ev, arg) {
ext.exec("quickmark-jump-page", arg, ev);
}, 'Jump Page (QuickMark)', true);
key.setViewKey([['.'], ['d']], function (ev) {
BrowserCloseTabOrWindow();
}, 'タブ / ウィンドウを閉じる');
key.setViewKey('e', function () {
command.interpreter();
}, 'コマンドインタプリタ');
key.setViewKey('y', function () {
command.setClipboardText(content.location.href);
}, 'copy URL', true);
key.setViewKey('j', function (ev) {
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_DOWN, true);
}, '5行スクロールダウン');
key.setViewKey('k', function (ev) {
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
key.generateKey(ev.originalTarget, KeyEvent.DOM_VK_UP, true);
}, '5行スクロールアップ');
key.setViewKey('K', function () {
goDoCommand("cmd_scrollPageUp");
}, '一画面分スクロールアップ');
key.setViewKey('J', function () {
goDoCommand("cmd_scrollPageDown");
}, '一画面スクロールダウン');
key.setViewKey('G', function () {
goDoCommand("cmd_scrollBottom");
}, 'ページ末尾へ移動', true);
key.setViewKey('+', function (ev, arg) {
shell.input(null, arg);
}, 'コマンドの実行', true);
key.setViewKey('r', function () {
BrowserReload();
}, '更新', true);
key.setViewKey('R', function () {
BrowserReloadSkipCache();
}, '更新(キャッシュを無視)');
key.setViewKey('H', function () {
BrowserBack();
}, '戻る');
key.setViewKey('L', function () {
BrowserForward();
}, '進む');
key.setViewKey('f', function (ev, arg) {
ext.exec("hok-start-foreground-mode", arg);
}, 'Start foreground hint mode', true);
key.setViewKey('F', function (ev, arg) {
ext.exec("hok-start-background-mode", arg);
}, 'Start background hint mode', true);
key.setViewKey(';', function (ev, arg) {
ext.exec("hok-start-extended-mode", arg);
}, 'Start extended hint mode', true);
key.setViewKey('u', function (ev) {
undoCloseTab();
}, '閉じたタブを元に戻す');
key.setViewKey('o', function () {
command.focusToById("urlbar");
}, 'ロケーションバーへフォーカス', true);
key.setViewKey('t', function (ev) {
BrowserOpenTab();
var b = getBrowser();
b.mTabContainer.selectedIndex = b.mTabs.length - 1;
command.focusToById("urlbar");
}, 'タブを開く');
key.setViewKey(['z', 'i'], function (ev, arg) {
ext.exec("text-zoom-enlarge", arg, ev);
}, 'テキストサイズを大きく', true);
key.setViewKey(['z', 'o'], function (ev, arg) {
ext.exec("text-zoom-reduce", arg, ev);
}, 'テキストサイズを小さく', true);
key.setViewKey('U', function (ev, arg) {
ext.exec("hok-start-background-mode", arg, ev);
}, 'HoK - リンクをバックグラウンドで開く', true);
key.setViewKey('Y', function (ev, arg) {
ext.exec("hok-start-foreground-mode", arg, ev);
}, 'HoK - リンクをフォアグラウンドで開く', true);
key.setViewKey('$', function (ev, arg) {
var b = getBrowser();
b.mTabContainer.selectedIndex = b.mTabs.length - 1;
}, 'select last tab');
key.setViewKey('^', function (ev, arg) {
getBrowser().mTabContainer.selectedIndex = 0;
}, 'select first tab');
key.setViewKey(':', function (ev, arg) {
ext.select(arg, ev);
}, 'エクステ一覧表示', true);
key.setViewKey([',', 't', 't'], function (ev, arg) {
ext.exec("twitter-client-tweet", arg, ev);
}, 'つぶやく', true);
key.setViewKey([',', 't', 'l'], function (ev, arg) {
ext.exec("twitter-client-display-timeline", arg, ev);
}, 'TL を表示', true);
key.setViewKey([',', 't', 'r'], function (ev, arg) {
ext.exec("twitter-client-show-mentions", arg, ev);
}, '@ 一覧表示 (自分への言及一覧)', true);
key.setViewKey([',', 'r', 'r'], function () {
userscript.reload();
}, '設定ファイルを再読み込み');
key.setViewKey([',', 'd', 'p'], function (ev, arg) {
ext.exec("dialog-keysnail-preference", arg, ev);
});
key.setViewKey([',', 'R', 'R'], function () {
var appStartup = Cc['@mozilla.org/toolkit/app-startup;1'].getService(Ci.nsIAppStartup);
appStartup.quit(appStartup.eRestart | appStartup.eAttemptQuit);
}, 'Firefox を再起動');
key.setViewKey([',', 'l', 'i'], function (ev, arg) {
ext.exec("login-manager-login", arg, ev);
}, 'Log In (LoginManager)', true);
key.setViewKey([',', 'l', 'u'], function (ev, arg) {
ext.exec("login-manager-login", "tumblr", ev);
}, 'Log In Tumblr', true);
key.setViewKey([',', 'l', 'o'], function (ev, arg) {
ext.exec("login-manager-logout", arg, ev);
}, 'Log Out (LoginManager)', true);
key.setViewKey('<left>', function () {
var browser = getBrowser();
if (browser.mCurrentTab.previousSibling) {
browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos - 1);
} else {
browser.moveTabTo(browser.mCurrentTab, browser.mTabContainer.childNodes.length - 1);
}
}, '選択中のタブを左へ');
key.setViewKey('<right>', function () {
var browser = getBrowser();
if (browser.mCurrentTab.nextSibling) {
browser.moveTabTo(browser.mCurrentTab, browser.mCurrentTab._tPos + 1);
} else {
browser.moveTabTo(browser.mCurrentTab, 0);
}
}, '選択中のタブを右へ');
key.setViewKey([']', ']'], function (ev, arg) {
ext.exec("follow-next-link", arg, ev);
}, 'follow next link', true);
key.setViewKey([']', 'k'], function (ev, arg) {
ext.exec("digit-url-incement", arg, ev);
}, 'increment last digit in URL', true);
key.setViewKey(['[', '['], function (ev, arg) {
ext.exec("follow-prev-link", arg, ev);
}, 'follow previous link', true);
key.setViewKey(['[', 'k'], function (ev, arg) {
ext.exec("digit-url-decement", arg, ev);
}, 'decrement last digit in URL', true);
key.setViewKey('P', function (ev, arg) {
plugins.hok.openURI(command.getClipboardText(), plugins.hok.NEW_BACKGROUND_TAB);
}, 'open clipboard url in newtab');
key.setViewKey('p', function (ev, arg) {
plugins.hok.openURI(command.getClipboardText(), plugins.hok.CURRENT_TAB);
}, 'open clipboard url in currenttab');
key.setViewKey('M', function (ev, arg) {
ext.exec("quickmark-mark-page", arg, ev);
}, 'Mark Page (QuickMark)', true);
key.setViewKey([',', 'l', 't'], function (ev, arg) {
ext.exec('login-manager-login', "twitter", ev);
}, 'Log In Twitter', true);