/** * For Vimperator 2.0pre * @author mattn mattn.jp@gmail.com */ (function() { const Cc = Components.classes; const Ci = Components.interfaces; const StarXPath = './/img[contains(concat(" ", @class, " "), " hatena-star-add-button ")]'; var flasher = null; var nmap = (liberator.globalVariables.hatena_star_mappings || ',?s').split(/\s+/); var hmap = liberator.globalVariables.hatena_star_hint_mapping || 'h'; function getFlasher() { if (!flasher) { flasher = Cc['@mozilla.org/inspector/flasher;1'].createInstance(Ci.inIFlasher); flasher.color = '#FF0000'; flasher.thickness = 2; } return flasher; } function blink(aNode) { if (!aNode) { liberator.echoerr('hatenastar not found'); return; } if (aNode.nodeType == 3) aNode = aNode.parentNode; var toggle = true; var flasher = getFlasher(); for (let i=1; i<7; ++i) { setTimeout(function() { if (toggle) flasher.drawElementOutline(aNode); else flasher.repaintElement(aNode); toggle = !toggle; }, i * 100); } } function addHatenaStar (elem) { let e = document.createEvent('MouseEvents'); e.initMouseEvent('click', true, true, window, 1, 10, 50, 10, 50, 0, 0, 0, 0, 1, elem); elem.dispatchEvent(e); } liberator.modules.commands.addUserCommand(['hatenastar', 'hatenas'], 'add Hatena Star', function (arg, special) { try { arg = arg.string; let result = buffer.evaluateXPath(StarXPath); if (arg.match(/^(\d+)\?$/)) { blink(result.snapshotItem(Number(RegExp.$1)-1)); return; } for (let i = 0, l = result.snapshotLength; i < l; i++) { if (arg == '' || arg == 'all' || arg == (i+1)) { addHatenaStar(result.snapshotItem(i)); } } } catch (e) { liberator.echoerr('hatenaStar: ' + e); } }, { bang: true, count: true } ); liberator.modules.mappings.addUserMap([liberator.modules.modes.NORMAL], nmap, 'add Hatena Star', function (count) { try { for (let n = 0; n++ < count; liberator.modules.commands.get('hatenastar').execute("all", false, count)); } catch (e) { liberator.echoerr('hatenaStar: ' + e); } }, { noremap: true, flags: liberator.modules.Mappings.flags.COUNT } ); liberator.modules.hints.addMode(hmap, 'Add hatena star', addHatenaStar, function () StarXPath); })(); b5efbc6'>commitdiffstats
path: root/stylish.js
blob: d9a97820aff9607f7e52040c981617a25825476e (plain)
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