diff options
Diffstat (limited to 'inspector.js')
-rw-r--r-- | inspector.js | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/inspector.js b/inspector.js index e324bb2..f17a83f 100644 --- a/inspector.js +++ b/inspector.js @@ -3,16 +3,25 @@ * @name inspector * @description DOM Inspector commands * @depend "DOM Inspector" inspector@mozilla.org - * @version 1.0 + * @author teramako teramako@gmail.com + * @minVersion 2.0pre + * @version 1.1 * ==/VimperatorPlugin== + * + * Usage: + * + * :inspect #{id} -> inspect the element of the {id} in browser content + * :inspect! #{id} -> inspect the element of the {id} in firefox + * :inspect[!] -f[rame] #{id} -> inspect the document in the frame element of the {id} + * :inspect {str} -> inspect the return value of evaluated the {str} */ (function(){ const inspectorID = 'inspector@mozilla.org'; -if (!Application.extensions.get(inspectorID).enabled) return; +if (!Application.extensions.has(inspectorID) || !Application.extensions.get(inspectorID).enabled) return; -/* これやるとFirefox終了時に実行されるんだけど...なぜ? +/* これやるとFirefox終了時に実行されるんだけど...なぜ? -> Ubiquityが悪さしているみたい Object.prototype.inspect = function(){ runInspector(this); } @@ -27,6 +36,11 @@ function runInspector(node){ inspectObject(node); } } +function getIDList(filter, isChrome){ + var doc = isChrome ? document : content.document; + var iter = buffer.evaluateXPath('//*[@id and contains(@id,"' + filter + '")]',doc); + return [["#" + e.id, "TagName: "+ e.tagName] for (e in iter)]; +} function getFrameList(){ var list = []; @@ -37,30 +51,41 @@ function getFrameList(){ } return list; } +var options = [ + [["-frame","-f"], commands.OPTION_NOARG] +]; commands.addUserCommand(['inspect','dominspect'],'run DOM Inspector', - function(arg, bang){ - if (!arg.string){ - bang ? inspectDOMDocument(document) : inspectDOMDocument(content.document); - return; - } - var list = getFrameList(); - var index = list.map(function($_) $_[0]).indexOf(arg.string); + function(args, bang){ + var arg = args.arguments[0]; + var doc = bang ? document : content.document; var node; - if (index != -1) node = document.getElementById(list[index][0]).contentDocument; - if (!node){ + if (!arg){ + node = doc; + } else if (arg.charAt(0) == "#"){ + var id = arg.substr(1); + node = doc.getElementById(id); + if (!node) { + liberator.echoerr("No such id: " + id ); + return; + } + } else { try { - node = window.eval("with(liberator){" + arg.string + "}"); - } catch(e) { + node = __eval(args.string); + } catch (e) { liberator.echoerr(e); - return; } } + if (args["-frame"] && node.contentDocument) node = node.contentDocument; runInspector(node); },{ bang: true, - completer: function(filter){ - var list = completion.filter(getFrameList(), filter, true); - if (list.length > 0) return [0, list]; + argCount: "*", + options: options, + completer: function(filter, bang){ + var arg = commands.parseArgs(filter, options, "*").arguments[0]; + if (arg.charAt(0) == "#"){ + return [filter.indexOf(arg), completion.filter(getIDList(arg.substr(1),bang),arg,true)]; + } return completion.javascript(filter); }, } |