forked from hogelog/keysnail-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquickmark.ks.js
79 lines (77 loc) · 2.33 KB
/
quickmark.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
var PLUGIN_INFO =
<KeySnailPlugin>
<name>QuickMark</name>
<description>QuickMark for KeySnail</description>
<version>0.0.1</version>
<updateURL>http://github.com/hogelog/keysnail-plugins/raw/master/quickmark.ks.js</updateURL>
<author mail="[email protected]" homepage="http://hogel.org/">hogelog</author>
<license>CC0</license>
<minVersion>1.5.0</minVersion>
<include>main</include>
<provides>
<ext>quickmark-mark-page</ext>
<ext>quickmark-jump-page</ext>
<ext>quickmark-open-page</ext>
<ext>quickmark-delete-page</ext>
</provides>
<options>
</options>
<detail><![CDATA[]]></detail>
</KeySnailPlugin>;
const PersistName = "quickmark";
let marks = persist.restore(PersistName) || {};
function jumpURI(uri, bg) {
gBrowser.loadOneTab(uri, null, null, null, true);
}
function openURI(uri) {
gBrowser.loadURIWithFlags(uri, null, null, null, null);
}
ext.add("quickmark-mark-page", function () {
prompt.reader({
message: "Mark Page (QuickMark)",
callback: function (arg) {
let [mark, uri] = arg.split(/\s+/);
if (!uri) {
uri = content.location.href;
}
marks[arg] = uri;
persist.preserve(marks, PersistName);
},
});
}, "Mark Page (QuickMark)");
ext.add("quickmark-jump-page", function () {
prompt.reader({
message: "Jump Page (QuickMark)",
onChange: function (arg) {
let mark = arg.textbox.value;
let uri = marks[mark];
if (uri) {
jumpURI(uri);
arg.finish();
}
},
});
}, "Jump Page (QuickMark)");
ext.add("quickmark-open-page", function () {
prompt.reader({
message: "Open Page (QuickMark)",
onChange: function (arg) {
let mark = arg.textbox.value;
let uri = marks[mark];
if (uri) {
arg.finish();
openURI(uri);
}
},
});
}, "Open Page (QuickMark)");
ext.add("quickmark-delete-page", function () {
let uri = content.location.href;
for (mark in marks) {
if (marks[mark] == uri) {
delete marks[mark];
}
}
persist.preserve(marks, PersistName);
}, "Delete Page (QuickMark)");
// vim: fenc=utf-8 sw=4 ts=4 et: