forked from ericpromislow/tabhunter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabhunter.kpf
285 lines (248 loc) · 9.34 KB
/
tabhunter.kpf
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
<?xml version="1.0" encoding="UTF-8"?>
<!-- Komodo Project File - DO NOT EDIT -->
<project id="75abdd97-f26f-42b9-a3b8-6db0ca10ab93" kpf_version="4" name="tabhunter.kpf">
<macro async="0" icon="chrome://famfamfamsilk/skin/icons/brick.png" id="0533dea7-96a4-4d8c-845b-f6dc833f18d0" idref="382f0674-ff34-489b-b71c-bc859d3af9a0" keyboard_shortcut="" language="JavaScript" name="extension_lib" rank="100" trigger="trigger_postopen" trigger_enabled="0">
try {
var extensionLib = function() {
this.os = Components.classes['@activestate.com/koOs;1'].
getService(Components.interfaces.koIOs);
this.error = false;
}
extensionLib.prototype.getPath = function(relative) {
try {
var prj_path = ko.interpolate.interpolateStrings('%p');
path = this.os.path.join(prj_path, relative);
return path;
} catch(e) {
alert(e+"\narg name: "+name);
}
}
extensionLib.prototype.readFile = function(filename) {
// read the template file
try {
var fileEx = Components.classes["@activestate.com/koFileEx;1"]
.createInstance(Components.interfaces.koIFileEx);
fileEx.URI = filename;
fileEx.open('rb');
var content = fileEx.readfile();
fileEx.close();
return content;
} catch(e) {
alert(e+"\narg filename: "+filename);
}
}
extensionLib.prototype.writeFile = function(filename, content) {
try {
var fileEx = Components.classes["@activestate.com/koFileEx;1"]
.createInstance(Components.interfaces.koIFileEx);
fileEx.URI = filename;
fileEx.open('wb+');
fileEx.puts(content);
fileEx.close();
} catch(e) {
alert(e+"\narg filename: "+filename);
}
}
extensionLib.prototype.getRdfVars = function(txt) {
try {
var Rx = /\<em\:([\w]+)[\ \S]*\>([\S\ ]+?)\<\//g;
var ext_vars = {};
while(results = Rx.exec(txt)) {
var idRx = /type|min|max|\{/;
if(!idRx.test(results[0])) { // filter out stuff we don't want
ext_vars[results[1]] = results[2];
}
}
return ext_vars;
} catch(e) {
alert(e+"\narg rdf_path: "+rdf_path);
}
}
extensionLib.prototype.getManifestVars = function(txt) {
try {
var rx1 = /content ([\S]+?) jar\:([\S]+?)\.jar/g;
var res1 = rx1.exec(txt);
var rx2 = /chrome:\/\/([\S]+?)\/content\/overlay\.xul/g;
var res2 = rx2.exec(txt);
return new Array(res1[1], res1[2], res2[1]);
} catch(e) {
alert(e+"\narg path: "+path);
}
}
extensionLib.prototype.getOverlayVars = function(txt) {
try {
var rx1 = /<overlay id="([\S]+?)"/g;
var res1 = rx1.exec(txt);
var rx2 = /<menuitem id="([\S]+?)"[\s]+?label="([\S\ ]+?)"/g;
var res2 = rx2.exec(txt);
return [res1[1], res2[1], res2[2]];
} catch(e) {
alert(e+"\narg path: "+path);
}
}
extensionLib.prototype.updateProject = function(vars) {
try {
var overlayPath = this.getPath('content/overlay.xul');
if(this.os.path.exists(overlayPath)) {
var ovl_str = this.readFile(overlayPath);
var ov_vars = this.getOverlayVars(ovl_str);
var ovl_new = [vars.ext_name+'Overlay', 'menu_'+vars.ext_name, vars.name];
this.writeFile(overlayPath, this.replaceAll(ov_vars, ovl_new, ovl_str));
} else { this.error = "Doesn't exist: "+overlayPath; return false; }
var manifestPath = this.getPath('chrome.manifest');
if(this.os.path.exists(manifestPath)) {
var man_str = this.readFile(manifestPath);
var man_vars = this.getManifestVars(man_str);
var man_new = [vars.ext_name, vars.ext_name, vars.ext_name];
this.writeFile(manifestPath, this.replaceAll(man_vars, man_new, man_str));
} else { this.error = "Doesn't exist: "+overlayPath; return false; }
var rdf_path = this.getPath('install.rdf');
if(this.os.path.exists(rdf_path)) {
var rdf_str = this.readFile(rdf_path);
var rdf_vars = this.getRdfVars(rdf_str);
this.writeFile(rdf_path, this.replaceAll(rdf_vars, vars, rdf_str));
} else { this.error = "Doesn't exist: "+overlayPath; return false; }
} catch(e) {
this.error = e;
return false;
}
return true;
}
extensionLib.prototype.replaceAll = function(orig_vars, new_vars, str) {
try {
var out = str;
for(v in orig_vars) {
out = out.replace(orig_vars[v], new_vars[v]);
}
return out;
} catch(e) {
alert(e);
}
}
extensionLib.prototype.getNiceName = function(name) {
return this.trim(name).replace(/[\W]/g,'').toLowerCase();
}
extensionLib.prototype.trim = function(str) {
return str.replace(/^\s*/, '').replace(/\s*$/, '');
}
extensionLib.prototype.clone = function(obj) {
var newobj = {}; for(i in obj) {
newobj[i] = obj[i];
} return newobj;
}
extensionLib.prototype._dump = function(obj) {
var str = ''; for(i in obj) {
str += i+': '+obj[i]+'\n';
} return(str);
}
extensionLib.prototype._keys = function(obj) {
var out = new Array(); for(i in obj) {
out.push(i);
} return out;
}
} catch(e) {
allert(e);
}
</macro>
<macro async="0" icon="chrome://famfamfamsilk/skin/icons/lightning_go.png" id="086c73c1-1bab-4c86-be5d-1317e49bf843" idref="382f0674-ff34-489b-b71c-bc859d3af9a0" keyboard_shortcut="" language="JavaScript" name="Build" rank="100" trigger="trigger_postopen" trigger_enabled="0">
/**
* Script to build an xpi, running koext build in the current project root.
*/
var project = ko.macros.current.project;
var os = Components.classes['@activestate.com/koOs;1'].
getService(Components.interfaces.koIOs);
var koSysUtils = Components.classes["@activestate.com/koSysUtils;1"].
getService(Components.interfaces.koISysUtils);
var appInfo = Components.classes["@mozilla.org/xre/app-info;1"].
getService(Components.interfaces.nsIXULRuntime);
var koDirs = Components.classes['@activestate.com/koDirs;1'].
getService(Components.interfaces.koIDirs);
var pythonExe = koDirs.pythonExe;
var projectDir = ko.interpolate.interpolateStrings('%p');
var scriptName = 'koext';
if (appInfo.OS == 'WINNT') {
scriptName += ".py";
}
var arr = [koDirs.sdkDir, 'bin', scriptName]
var app = os.path.joinlist(arr.length, arr);
var cmd = '"'+pythonExe+'" "'+app+'" build -d "'+projectDir+'"';
if (appInfo.OS == 'WINNT') {
cmd = '"' + cmd + '"';
}
var cwd = koDirs.mozBinDir;
cmd += " {'cwd': u'"+cwd+"'}";
ko.run.runEncodedCommand(window, cmd, function() {
ko.statusBar.AddMessage('Build complete', 'projects', 5000, true);
ko.projects.manager.saveProject(project);
});
</macro>
<file id="5b9da7ab-0227-4c34-8a4a-fb2d5e6ba69e" idref="382f0674-ff34-489b-b71c-bc859d3af9a0" name="setup.xul" url="_prj_internal_/setup.xul">
</file>
<macro async="0" icon="chrome://famfamfamsilk/skin/icons/wrench.png" id="96375912-e46b-4667-98de-ea618a1c84c5" idref="382f0674-ff34-489b-b71c-bc859d3af9a0" keyboard_shortcut="" language="JavaScript" name="Configure" rank="100" trigger="trigger_postopen" trigger_enabled="0">
try {
var libPart = ko.projects.findPart('macro', 'extension_lib', 'container');
eval(libPart.value);
var koExt = new extensionLib();
var project = ko.macros.current.project;
var setupWin = project.getChildByAttributeValue('name','setup.xul', 1);
var rdf = project.getChildByAttributeValue('name','install.rdf', 1);
var data = {};
var prefset = project.prefset;
if(prefset.hasPrefHere('configured')) {
var rdf_xml = koExt.readFile(rdf.getFile().URI);
data = {
'valid': false,
'configured': true,
'vars': koExt.getRdfVars(rdf_xml)
};
data.vars['ext_name'] = koExt.getNiceName(data.vars.name);
} else { // init data
data = {
'valid': false,
'configured': false,
'vars': {
'id': '',
'name': 'My Extension',
'creator': 'Me',
'version': '0.1',
'description': '',
'homepageURL': '',
'ext_name': ''
}
};
}
window.openDialog(
setupWin.getFile().URI,
"_blank",
"centerscreen,chrome,resizable,scrollbars,dialog=no,close,modal=yes",
data
);
if(data.valid) {
if(koExt.updateProject(data.vars)) {
prefset.setBooleanPref('configured', true);
var part = project.getChildByAttributeValue('name', 'oncreate',1);
if(part) { part.name = 'Configure'; }
var msg = 'Extension Project '+data.vars.name+' configured!';
ko.statusBar.AddMessage(msg, 'project', 3000, true);
ko.projects.manager.saveProject(project);
} else {
alert('Error encountered: '+koExt.error+"\nConfiguration aborted.");
}
}
} catch(e) {
alert(e);
}
</macro>
<folder id="382f0674-ff34-489b-b71c-bc859d3af9a0" idref="75abdd97-f26f-42b9-a3b8-6db0ca10ab93" name="Project">
</folder>
<preference-set idref="43c8f4af-2d69-c64c-80c4-fa4879e6d3fa">
</preference-set>
<preference-set idref="75abdd97-f26f-42b9-a3b8-6db0ca10ab93">
<boolean id="configured">1</boolean>
<string id="import_exclude_matches">*.*~;*.bak;*.tmp;CVS;.#*;*.pyo;*.pyc;.svn;*%*;tmp*.html;.DS_Store;_prj_internal_</string>
<string id="import_include_matches"></string>
<boolean id="import_live">1</boolean>
<boolean id="import_recursive">1</boolean>
<string id="import_type">useFolders</string>
</preference-set>
</project>