Changeset 25306 for lang/javascript/vimperator-plugins
- Timestamp:
- 11/29/08 05:08:15 (6 weeks ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/gmperator.js
r25283 r25306 5 5 * @author teramako teramako@gmail.com 6 6 * @namespace http://d.hatena.ne.jp/teramako/ 7 * @version 0.6 b7 * @version 0.6c 8 8 * ==/VimperatorPlugin== 9 9 * … … 91 91 const Ci = Components.interfaces; 92 92 const gmID = '@greasemonkey.mozdev.org/greasemonkey-service;1'; 93 if (!Cc[gmID]) {93 if (!Cc[gmID]){ 94 94 liberator.log('Greasemonkey is not installed',0); 95 95 return; … … 112 112 containers[panelID] = gmCon; 113 113 this.__defineGetter__(panelID,function() gmCon); 114 //liberator.log('gmpeartor: Registered: ' + panelID + ' - ' + uri, 8);114 //liberator.log('gmpeartor: Registered: ' + panelID + ' - ' + uri,8); 115 115 } 116 116 gmCon.sandbox = sandbox; 117 117 gmCon.addScript(script); 118 118 gmCon.uri = uri; 119 triggerGMEvent('GMInjectedScript', uri,script._filename);119 triggerGMEvent('GMInjectedScript',uri,script._filename); 120 120 if (panelID == this.currentPanel){ 121 triggerGMEvent('GMActiveScript', uri,script._filename);121 triggerGMEvent('GMActiveScript',uri,script._filename); 122 122 } 123 123 }, … … 131 131 }, 132 132 getSandboxFromWindow: function(win){ 133 for each (varc in containers){134 if (c.sandbox.window == win) return sandbox;133 for each (let c in containers){ 134 if (c.sandbox.window == win) return sandbox; 135 135 } 136 136 return null; … … 138 138 getContainersFromURI: function(uri){ 139 139 var list = []; 140 for each (varc in containers){140 for each (let c in containers){ 141 141 if (c.uri == uri) list.push(c); 142 142 } 143 143 return list.length > 0 ? list : null; 144 } ,144 } 145 145 }; 146 146 // }}} … … 160 160 }; 161 161 } 162 appendCode(gmSvc, 'evalInSandbox',function(code,uri,sandbox,script){162 appendCode(gmSvc,'evalInSandbox',function(code,uri,sandbox,script){ 163 163 liberator.plugins.gmperator.register(uri,sandbox,script); 164 164 }); 165 165 function getPanelID(win){ 166 166 var tabs = getBrowser().mTabs; 167 for ( var i=0; i<tabs.length; i++){168 vartab = tabs.item(i);167 for (let i=0,l=tabs.length; i<l; i++){ 168 let tab = tabs.item(i); 169 169 if (tab.linkedBrowser.contentWindow == win){ 170 170 return tab.linkedPanel; … … 183 183 var container; 184 184 if (container = containers[panelID]){ 185 liberator.log(panelID + '\n' + container.uri +'\n'+ container.scripts.length, 8);185 liberator.log(panelID + '\n' + container.uri +'\n'+ container.scripts.length,8); 186 186 container.scripts.forEach(function(script){ 187 triggerGMEvent('GMActiveScript', container.uri,script._filename);187 triggerGMEvent('GMActiveScript',container.uri,script._filename); 188 188 }); 189 189 } … … 195 195 * @param {String} filename script filename 196 196 */ 197 function triggerGMEvent(name, uri,filename){198 autocommands.trigger(name, uri+'\n'+filename);199 liberator.log('gmpeartor: '+ name + ' ' + uri+'\n'+filename, 8);197 function triggerGMEvent(name,uri,filename){ 198 autocommands.trigger(name,uri+'\n'+filename); 199 liberator.log('gmpeartor: '+ name + ' ' + uri+'\n'+filename,8); 200 200 } 201 201 getBrowser().mTabContainer.addEventListener('TabClose',updateGmContainerList,false); 202 202 getBrowser().mTabBox.addEventListener('TabSelect',dispatchGMTabSelect,false); 203 203 204 config.autocommands.push([ "GMInjectedScript","Triggered when UserScript is injected"]);205 config.autocommands.push([ "GMActiveScript","Triggered when location is changed and injected UserScripts are exist"]);206 config.dialogs.push([ "userscriptmanager", "Greasemonkey Manager",function(){GM_openUserScriptManager();}]);204 config.autocommands.push(['GMInjectedScript','Triggered when UserScript is injected']); 205 config.autocommands.push(['GMActiveScript','Triggered when location is changed and injected UserScripts are exist']); 206 config.dialogs.push(['userscriptmanager','Greasemonkey Manager',function(){GM_openUserScriptManager();}]); 207 207 // }}} 208 208 return manager; … … 212 212 // User Command 213 213 // --------------------------- 214 commands.addUserCommand(['gmli[st]','lsgm'], 'list Greasemonkey scripts', //{{{214 commands.addUserCommand(['gmli[st]','lsgm'],'list Greasemonkey scripts', //{{{ 215 215 function(args){ 216 216 var xml = <></>; … … 218 218 var reg; 219 219 if (args.bang || args.string == 'full'){ 220 reg = new RegExp( '.*');221 } else if (args.string){220 reg = new RegExp(); 221 } else if (args.string){ 222 222 reg = new RegExp(args.string,'i'); 223 223 } 224 224 if (reg){ 225 for each (vars in scripts){226 if (reg.test(s.name) || reg.test(s._filename)) {225 for each (let s in scripts){ 226 if (reg.test(s.name) || reg.test(s._filename)){ 227 227 xml += scriptToString(s); 228 228 } 229 229 } 230 230 } else { 231 vartable = <table/>;232 vartr;233 for each (varscript in scripts){231 let table = <table/>; 232 let tr; 233 for each (let script in scripts){ 234 234 tr = <tr/>; 235 235 if (script.enabled){ … … 248 248 <caption class="hl-Title" style="text-align:left">{script.name}</caption> 249 249 </table>; 250 [['FileName','_filename'], ['NameSpace','namespace'],['Description','description'],251 ['Includes','includes'], ['Excludes','excludes'],['Enabled','enabled']].forEach(function(prop){252 vartr = <tr>250 [['FileName','_filename'],['NameSpace','namespace'],['Description','description'], 251 ['Includes','includes'],['Excludes','excludes'],['Enabled','enabled']].forEach(function(prop){ 252 let tr = <tr> 253 253 <th style="font-weight:bold;text-align:left;vertical-align:top">{prop[0]}</th> 254 254 </tr>; 255 varcontents = script[prop[1]];256 if (typeof contents == "string" || typeof contents == "boolean"){255 let contents = script[prop[1]]; 256 if (typeof contents == 'string' || typeof contents == 'boolean'){ 257 257 tr.* += <td>{contents}</td>; 258 258 } else { 259 vartd = <td/>;260 for ( var i=0; i<contents.length; i++){259 let td = <td/>; 260 for (let i=0,l=contents.length; i<l; i++){ 261 261 td.* += contents[i]; 262 262 if (contents[i+1]) td.* += <br/>; … … 272 272 } 273 273 ); //}}} 274 commands.addUserCommand(['gmlo[ad]'], 'load Greasemonkey scripts', //{{{274 commands.addUserCommand(['gmlo[ad]'],'load Greasemonkey scripts', //{{{ 275 275 function(args){ 276 if (!args.string) {276 if (!args.string){ 277 277 liberator.echoerr('Usage: :gmlo[ad][!] {name|filename}'); 278 278 return; … … 280 280 var scripts = GM_getConfig().scripts; 281 281 var script; 282 for ( var i=0; i<scripts.length; i++){282 for (let i=0,l=scripts.length; i<l; i++){ 283 283 if (scripts[i]._filename == args.string || scripts[i].name == args.string){ 284 284 script = scripts[i]; … … 286 286 } 287 287 } 288 if (!script) {288 if (!script){ 289 289 liberator.echoerr('no such a user script'); 290 290 return; … … 295 295 liberator.echo('loading: ' +script._filename); 296 296 } 297 var href,unsafewin; 297 298 try { 298 varhref = buffer.URL;299 varunsafewin = window.content.document.defaultView.wrappedJSObject;299 href = buffer.URL; 300 unsafewin = window.content.document.defaultView.wrappedJSObject; 300 301 GM_BrowserUI.gmSvc.wrappedJSObject.injectScripts([script],href,unsafewin,window); 301 } catch (e){302 } catch (e){ 302 303 liberator.log(e); 303 304 liberator.echoerr(e); … … 307 308 window.setTimeout(function(){ 308 309 var loadEvent = document.createEvent('Event'); 309 loadEvent.initEvent('load',true,true, window.content.document,1);310 loadEvent.initEvent('load',true,true,window.content.document,1); 310 311 window.content.document.dispatchEvent(loadEvent); 311 312 },100); … … 315 316 } 316 317 ); //}}} 317 commands.addUserCommand(['gmset'], 'change settings for Greasemonkey scripts', //{{{318 commands.addUserCommand(['gmset'],'change settings for Greasemonkey scripts', //{{{ 318 319 function(args){ 319 if (args.length == 0) {320 if (args.length == 0){ 320 321 if (args.bang) GM_setEnabled(!GM_getEnabled()); // toggle enable/disable Greasemonkey 321 322 return; … … 324 325 var config = GM_getConfig(); 325 326 var script; 326 for ( var i=0; i<config.scripts.length; i++){327 for (let i=0,l=config.scripts.length; i<l; i++){ 327 328 if (config.scripts[i]._filename == filename){ 328 329 script = config.scripts[i]; … … 339 340 config._save(); 340 341 },{ 341 completer: function(context) scriptsCompleter(context.filter, false),342 completer: function(context) scriptsCompleter(context.filter,false), 342 343 options: [ 343 344 [['-name','-n'], commands.OPTION_STRING], … … 348 349 } 349 350 ); //}}} 350 commands.addUserCommand([ "gmcommand", "gmcmd"], "run Greasemonkey Command", //{{{351 function(args, special){351 commands.addUserCommand(['gmcommand','gmcmd'],'run Greasemonkey Command', //{{{ 352 function(args,special){ 352 353 var commander = GM_BrowserUI.getCommander(content); 353 for ( var i = 0; i < commander.menuItems.length; i++){354 varmenuItem = commander.menuItems[i];355 if (menuItem.getAttribute( "label") == args.string){354 for (let i=0,l=commander.menuItems.length; i<l; i++){ 355 let menuItem = commander.menuItems[i]; 356 if (menuItem.getAttribute('label') == args.string){ 356 357 menuItem._commandFunc(); 357 358 return; 358 359 } 359 360 } 360 liberator.echoerr(args.string + " is not defined userscript command.");361 liberator.echoerr(args.string + ' is not defined userscript command.'); 361 362 }, 362 363 { 363 completer: function(context) {364 completer: function(context){ 364 365 var items = GM_BrowserUI.getCommander(content).menuItems; 365 366 var completions = []; 366 var exp = new RegExp( ".*" + context.filter + ".*","i");367 var exp = new RegExp(context.filter,'i'); 367 368 context.title = ["UserScript's Commands"]; 368 369 context.completions = [[items[i].getAttribute('label'),'-'] for (i in items)].filter(function(item){ 369 370 return this.test(item[0]); 370 }, new RegExp(".*"+context.filter+".*","i"));371 },exp); 371 372 } 372 373 } … … 387 388 } 388 389 GmContainer.prototype = { 389 addScript : function(script) {390 addScript : function(script){ 390 391 if (!this.hasScript(script)){ 391 return this.scripts.push(script) 392 return this.scripts.push(script); 392 393 } 393 394 return false; … … 395 396 hasScript : function(script){ 396 397 var filename; 397 switch ( typeof(script)){398 switch (typeof script){ 398 399 case 'object': filename = script._filename; break; 399 400 case 'string': filename = script; break; … … 409 410 if (!filter) isAll=true; 410 411 if (flag){ 411 for each (vars in scripts){412 for each (let s in scripts){ 412 413 if (isAll || s.name.toLowerCase().indexOf(filter) == 0 || 413 414 s._filename.indexOf(filter) == 0) 414 415 { 415 candidates.push([s.name, s.description]);416 candidates.push([s._filename, s.description]);416 candidates.push([s.name,s.description]); 417 candidates.push([s._filename,s.description]); 417 418 } 418 419 } 419 420 } else { 420 for each (vars in scripts){421 for each (let s in scripts){ 421 422 if (isAll || s._filename.indexOf(filter) == 0) 422 423 { 423 candidates.push([s._filename, s.description]);424 candidates.push([s._filename,s.description]); 424 425 } 425 426 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)