From af2c0797905ee7a0418aa62e42bf62871134f5d6 Mon Sep 17 00:00:00 2001 From: teramako Date: Wed, 25 Jun 2008 19:07:53 +0000 Subject: greasemonkey 0.8 に対応 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@14619 d0d07461-0603-4401-acd4-de1884942a52 --- gmperator.js | 122 +++++++++++++++++++++++++---------------------------------- 1 file changed, 52 insertions(+), 70 deletions(-) (limited to 'gmperator.js') diff --git a/gmperator.js b/gmperator.js index fd7b1e5..4f1c051 100644 --- a/gmperator.js +++ b/gmperator.js @@ -101,14 +101,15 @@ liberator.plugins.gmperator = (function(){ //{{{ gmCon = new GmContainer(uri,sandbox); containers[panelID] = gmCon; this.__defineGetter__(panelID,function() gmCon); - //log('gmpeartor: Registered: ' + panelID + ' - ' + uri); + log('gmpeartor: Registered: ' + panelID + ' - ' + uri, 8); } gmCon.sandbox = sandbox; gmCon.addScript(script); gmCon.uri = uri; - autocommands.trigger('GMInjectedScript',uri+'\n'+script.filename); + autocommands.trigger('GMInjectedScript',uri+'\n'+script._filename); + log('gmpeartor: GMInjectedScript ' + uri+'\n'+script._filename, 8); }, - get gmScripts() getScripts(), + get gmScripts() GM_getConfig().scripts, get allItem() containers, get currentPanel() getBrowser().mCurrentTab.linkedPanel, get currentContainer() containers[this.currentPanel] || null, @@ -165,7 +166,6 @@ liberator.plugins.gmperator = (function(){ //{{{ return tab.linkedPanel; } } - //liberator.log(win + 'is not found'); } function updateGmContainerList(e){ var t = e.target; @@ -185,7 +185,7 @@ liberator.plugins.gmperator = (function(){ //{{{ commands.addUserCommand(['gmli[st]','lsgm'], 'list Greasemonkey scripts', //{{{ function(arg,special){ var str = ''; - var scripts = getScripts(); + var scripts = GM_getConfig().scripts; var reg; if (special || arg == 'full'){ reg = new RegExp('.*'); @@ -193,50 +193,50 @@ commands.addUserCommand(['gmli[st]','lsgm'], 'list Greasemonkey scripts', //{{{ reg = new RegExp(arg,'i'); } if (reg){ - scripts.forEach(function(s){ - if ( reg.test(s.name) || reg.test(s.filename) ) { - str += scriptToString(s) + '\n\n'; + for each(var s in scripts){ + if ( reg.test(s.name) || reg.test(s._filename) ) { + str += scriptToString(s) + '\n'; } - }); + } } else { var table = ; var tr; - scripts.forEach(function(script){ + for each(var script in scripts){ tr = ; if (script.enabled){ - tr.* += ; + tr.* += ; } else { tr.* += ; } - tr.* += ; + tr.* += ; table.* += tr; - }); - str += table.toXMLString(); + } + str += table.toSource().replace(/\n/g,''); } echo(str,true); function scriptToString(script){ var table =
{script.name}{script.name}{script.name}({script.filename})({script._filename})
{script.name}
; - ['FileName', 'NameSpace', 'Description', - 'Includes', 'Excludes', 'Enabled'].forEach(function(prop){ + [['FileName','_filename'], ['NameSpace','namespace'], ['Description','description'], + ['Includes','includes'], ['Excludes','excludes'], ['Enabled','enabled']].forEach(function(prop){ var tr = - {prop} + {prop[0]} ; - var contents = script[prop.toLowerCase()]; - if (typeof contents == "string"){ + var contents = script[prop[1]]; + if (typeof contents == "string" || typeof contents == "boolean"){ tr.* += {contents}; } else { var td = ; - contents.forEach(function(c,i,a){ - td.* += c; - if (a[i+1]) td.* +=
; - }); + for (var i=0; i; + } tr.* += td; } table.* += tr; }); - return table.toXMLString(); + return table.toSource().replace(/\n/g,''); } } ); //}}} @@ -246,10 +246,10 @@ commands.addUserCommand(['gmlo[ad]'], 'load Greasemonkey scripts', //{{{ echoerr('Usage: :gmlo[ad][!] {name|filename}'); return; } - var scripts = getScripts(); + var scripts = GM_getConfig().scripts; var script; for (var i=0; i 0){ - script.name = commands.getOption(res.opts, '-name', script.name); - script.includes = commands.getOption(res.opts, '-include', script.includes); - script.excludes = commands.getOption(res.opts, '-exclude', script.excludes); - } - config.save(); + if (res['-name']) script.name = res['-name']; + if (res['-include']) script.include = res['-include']; + if (res['-exclude']) script.exclude = res['-exclude']; + config._save(); },{ - args: [ - [['-name','-n'], commands.OPTION_STRING], - [['-include','-i'], commands.OPTION_LIST], - [['-exclude','-e'], commands.OPTION_LIST] - ], - shortHelp: 'change settings for Greasemonkey scripts', - help: [ - 'toggle enable/disable with "!", if {filename} is exist, if not toggle Greasemonkey', - '
-n
-name
change the name
', - '
-i
-include
change the includes list ("," delimiter)
', - '
-e
-exclude
change the excludes list ("," delimiter)
', - 'Caution: the change is permanent, not the only session.
And cannot get back.' - ].join(''), completer: function(filter) scriptsCompleter(filter, false) } @@ -347,39 +334,34 @@ GmContainer.prototype = { hasScript : function(script){ var filename; switch( typeof(script) ){ - case 'object': filename = script.filename; break; + case 'object': filename = script._filename; break; case 'string': filename = script; break; default: return null; } return this.scripts.some(function(s) s.filename == filename); } }; // }}} -function getScripts(){ //{{{ - var config = new Config(); - config.load(); - return config.scripts; -} //}}} function scriptsCompleter(filter,flag){ //{{{ var candidates = []; - var scripts = getScripts(); + var scripts = GM_getConfig().scripts; var isAll = false; if (!filter) isAll=true; if (flag){ - scripts.forEach(function(s){ + for each(var s in scripts){ if (isAll || s.name.toLowerCase().indexOf(filter) == 0 || - s.filename.indexOf(filter) == 0) + s._filename.indexOf(filter) == 0) { candidates.push([s.name, s.description]); - candidates.push([s.filename, s.description]); + candidates.push([s._filename, s.description]); } - }); + } } else { - scripts.forEach(function(s){ - if (isAll || s.filename.indexOf(filter) == 0) + for each(var s in scripts){ + if (isAll || s._filename.indexOf(filter) == 0) { - candidates.push([s.filename, s.description]); + candidates.push([s._filename, s.description]); } - }); + } } return [0,candidates]; } //}}} -- cgit v1.2.3