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
|
/* {{{
Copyright (c) 2010, anekos.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The names of the authors may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
###################################################################################
# http://sourceforge.jp/projects/opensource/wiki/licenses%2Fnew_BSD_license #
# に参考になる日本語訳がありますが、有効なのは上記英文となります。 #
###################################################################################
}}} */
// PLUGIN_INFO {{{
let PLUGIN_INFO =
<VimperatorPlugin>
<name>mkreport</name>
<description>Write current information to the specified file</description>
<description lang="ja">現在の情報を指定のファイルに書き出す。</description>
<version>1.0.0</version>
<author mail="anekos@snca.net" homepage="http://d.hatena.ne.jp/nokturnalmortum/">anekos</author>
<license>new BSD License (Please read the source code comments of this plugin)</license>
<license lang="ja">修正BSDライセンス (ソースコードのコメントを参照してください)</license>
<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/reporter.js</updateURL>
<minVersion>2.2</minVersion>
<maxVersion>2.3</maxVersion>
<detail><![CDATA[
== Commands ==
- mkvimpref <FILENAME>
<FILENAME> に現在の preferences を書き出します。
- mkcolor <FILENAME>
<FILENAME> に現在の colorschme を書き出します。
- mkreport <FILENAME>
<FILENAME> に以下の情報を書き出します。
- Firefox アドオン&プラグインの一覧
- Vimperator プラグインの一覧
- デフォルトから変更されている preference (about:config でみられる設定) のリスト
- バージョンなどの情報
]]></detail>
</VimperatorPlugin>;
// }}}
(function () {
const File = io.File || io.getFile;
function openFileWith (path, block) {
let localFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
let out = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
let conv = Cc['@mozilla.org/intl/converter-output-stream;1'].
createInstance(Ci.nsIConverterOutputStream);
let file = File(io.expandPath(path));
if (file.exists())
file.remove(false);
localFile.initWithPath(file.path);
out.init(localFile, 0x02 | 0x08, 0664, 0);
let result = block({
__proto__: file,
write: function (s) {
conv.init(out, 'UTF-8', s.length,
Components.interfaces.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
return conv.writeString(s)
},
writeln: function (s) this.write(s + '\n')
});
conv.close();
out.close();
return result;
}
function pad (s, max)
(s.length < max ? pad(s + ' ', max) : s);
function defineCommand ({names, desc, action, options}) {
commands.addUserCommand(
names,
desc,
function (args) {
let filename = args[0];
return openFileWith(
filename,
function (file) {
if (file.exists() && !args.bang)
return liberator.echoerr(filename + ' already exists (add ! to override)');
return action(file, args);
}
);
},
{
argCount: '1',
bang: true,
options: options,
completer: function (context) completion.file(context, true)
},
true
);
}
const LIMIT_OPTION = [['-length-limit', '-ll'], commands.OPTION_INT];
const Writer = {
basic: function (file) {
function puts (name, value)
file.writeln(pad(name + ': ', 20) + value);
puts('Name', config.name);
puts('Host', config.hostApplication);
puts('Platform', navigator.platform);
puts('Version', liberator.version);
puts('UserAgent', navigator.userAgent);
},
colors: function (file) {
function rmrem (s)
s.replace(/\s*\/\*.*\*\//g, '');
let max = 0;
for (let h in highlight)
max = Math.max(h.class.length, max);
for (let h in highlight)
file.writeln(h.value ? 'hi ' + pad(h.class, max) + ' ' + rmrem(h.value)
: '" hi ' + h.class);
},
preferences: function (file, {'-length-limit': limit}) {
function quote(str)
(typeof str === 'string' ? Commands.quoteArg["'"](str) : str);
function compareByName ([n1,], [n2,])
n1.localeCompare(n2);
let Pref = services.get("pref");
for each (let name in options.allPrefs().sort(compareByName)) {
if (!Pref.prefHasUserValue(name))
continue;
let value = options.getPref(name);
if (typeof value === 'string' && limit && value.length > limit)
continue;
file.writeln("set! " + name + "=" + quote(value));
}
},
addons: function (file) {
for each (let ext in liberator.extensions) {
file.writeln(ext.name);
file.writeln(' ' + (ext.enabled ? 'enabled' : 'disabled'));
}
},
plugins: function (file) {
[File(n).leafName for (n in plugins.contexts)].sort().forEach(function (n) file.writeln(n));
}
};
defineCommand({
names: ['mkco[lor]'],
desc: 'Write current highlights to the specified file',
action: Writer.colors
});
defineCommand({
names: ['mkvimpref'],
desc: 'Write current preferences to the specified file',
options: [LIMIT_OPTION],
action: Writer.preferences
});
defineCommand({
names: ['mkreport'],
desc: 'Write the report for your question.',
options: [LIMIT_OPTION],
action: function (file, args) {
function writeSection (title, writer) {
const line = '"======================================================================';
file.writeln(line);
file.writeln('" ' + title);
file.writeln(line + '\n');
writer(file, args);
file.writeln('\n');
}
writeSection('Basic', Writer.basic);
writeSection(config.name + ' Plugin', Writer.plugins);
writeSection(config.hostApplication + ' Addon & Plugin', Writer.addons);
writeSection(config.hostApplication + ' Preference', Writer.preferences);
writeSection('Color Scheme', Writer.colors);
}
});
})();
// vim:sw=2 ts=2 et si fdm=marker:
|