aboutsummaryrefslogtreecommitdiffstats
path: root/inspector.js
blob: 7404dbf2edc12497873a830c81ccb6172580462d (plain)
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
let PLUGIN_INFO =
<VimperatorPlugin>
<name>{NAME}</name>
<description>DOM Inspector command</description>
<require type="extension" id="inspector@mozilla.org">DOM Inspector</require>
<author mail="teramako@gmail.com" homepage="http://vimperator.g.hatena.ne.jp/teramako/">teramako</author>
<version>0.3</version>
<minVersion>2.3pre</minVersion>
<maxVersion>2.3pre</maxVersion>
<detail><![CDATA[
== 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}
]]></detail>
</VimperatorPlugin>;

(function(){

const inspectorID = "inspector@mozilla.org";
if (!Application.extensions.has(inspectorID) || !Application.extensions.get(inspectorID).enabled) return;

/* これやるとFirefox終了時に実行されるんだけど...なぜ? -> Ubiquityが悪さしているみたい
Object.prototype.inspect = function(){
	runInspector(this);
};
*/

function runInspector(node){
	if (node instanceof Document){
		inspectDOMDocument(node);
	} else if (node instanceof Node){
		inspectDOMNode(node);
	} else if (node !== null && typeof node != "undefined"){
		inspectObject(node);
	}
}

function getIDList(filter, isChrome){
	var doc = isChrome ? document : content.document;
	var iter = util.evaluateXPath('//*[@id and contains(@id,"' + filter + '")]',doc);
	return [["#" + e.id, "TagName: "+ e.tagName] for (e in iter)];
}

var options = [
	[["-frame","-f"], commands.OPTION_NOARG]
];
commands.addUserCommand(["inspect","dominspect"],"run DOM Inspector",
	function(args){
		var arg = args[0];
		var doc = args.bang ? document : content.document;
		var node;
		if (!arg){
			node = doc;
		} else if (arg.charAt(0) == "#"){
			let id = arg.substr(1);
			node = doc.getElementById(id);
			if (!node){
				liberator.echoerr("No such id: " + id );
				return;
			}
		} else {
			try {
				node = liberator.eval(args.string);
			} catch (e){
				liberator.echoerr(e);
			}
		}
		if (args["-frame"] && node.contentDocument) node = node.contentDocument;
		runInspector(node);
	},{
		bang: true,
		argCount: "*",
		options: options,
		completer: function(context, args){
			if (args[0] && args[0].charAt(0) == "#"){
				var arg = args[0];
				var list = getIDList(arg.substr(1), args.bang);
				context.completions = list.filter(function(elem) elem[0].indexOf(arg) == 0);
			} else {
				completion.javascript(context);
			}
		}
	}
);

})();

ss="o">> Show hints for embedded objects. </p> </description> </item> <item> <tags>g:hints_for_embedded_mode </tags> <spec>let g:hints_for_embedded_mode=<a>hints-mode-character</a></spec> <description> <p> Hints mode characters. Default is not available. </p> </description> </item> <item> <tags>g:hints_for_embedded_where </tags> <spec>let g:hints_for_embedded_where=<a>where</a></spec> <description> <p> Where to open. <a>where</a> values. <ul> <li>new_tab</li> <li>current_tab</li> <li>new_background_tab</li> <li>new_window</li> </ul> </p> </description> </item> </plugin> <plugin name="HintsForEmbeded" version="1.3.1" href="http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/hints-for-embedded.js" summary="埋め込み(embed)オブジェクト用ヒントモード" lang="ja" xmlns="http://vimperator.org/namespaces/liberator"> <author email="anekos@snca.net">anekos</author> <license>New BSD License</license> <project name="Vimperator" minVersion="2.3"/> <item> <tags>:embhint</tags> <spec>:embhint</spec> <description> <p> 埋め込みオブジェクト用ヒントを表示 </p> </description> </item> <item> <tags>g:hints_for_embedded_mode </tags> <spec>let g:hints_for_embedded_mode=<a>hints-mode-character</a></spec> <description> <p> ヒントモード文字 デフォルト無効 </p> </description> </item> <item> <tags>g:hints_for_embedded_where </tags> <spec>let g:hints_for_embedded_where=<a>where</a></spec> <description> <p> どこに開くか <a>where</a> 値 <ul> <li>new_tab</li> <li>current_tab</li> <li>new_background_tab</li> <li>new_window</li> </ul> </p> </description> </item> </plugin> </>; // }}} (function () { const DESC = 'Hint for embedded object'; let modeName = liberator.globalVariables.hints_for_embedded_mode || 'hints-for-embedded'; let where = liberator.globalVariables.hints_for_embedded_where; let openParent = liberator.globalVariables.hints_for_embedded_open_parent_link || 0; if (typeof where === 'undefined') where = liberator.NEW_TAB; if (typeof where === 'string') where = liberator[where.replace(/[-\s]/g, '_').toUpperCase()]; let sites = { nico: { site: /(nico|smile)video/, name: /.*/, value: /(?:v|wv_id)=([a-z]{2}\d{1,10})/, url: function (id) ('http://www.nicovideo.jp/watch/' + id) }, youtube: { site: /youtube/, name: /.*/, value: /youtube\.com\/v\/([-a-zA-Z0-9_]+)/, url: function (id) ('http://www.youtube.com/watch?v=' + id) }, youtube_image: { site: /ytimg\.com/, name: /^flashvars$/, value: /video_id=([-a-zA-Z0-9_]+)/, url: function (id) ('http://www.youtube.com/watch?v=' + id) }, vimeo: { site: /vimeo/, name: /.*/, value: /clip_id=(\d+)/, url: function (id) ('http://vimeo.com/' + id) }, collegehumor: { site: /collegehumor/, name: /.*/, value: /clip_id=(\d+)/, url: function (id) ('http://www.collegehumor.com/video:' + id) } }; function getAttrs (elem) Array.map(elem.attributes, function(n) [n.nodeName, n.nodeValue]); function getInfo (elem) getAttrs(elem).concat((Array.slice(elem.querySelectorAll('object,embed,param')) || []).map(getInfo)); function open (elem) { let info = getInfo(elem.wrappedJSObject); if (elem.tagName === 'IMG' && elem.src) { if (openParent) { let p = elem.parentNode; if (p.tagName === 'A' && /(gif|png|jpe?g)$/i(p.href)) return liberator.open(p.href, liberator.NEW_TAB); } return liberator.open(elem.src, liberator.NEW_TAB); } let site = (function () { for (let [,site] in Iterator(sites)) if (info.some(function (nv) nv.some(function (v) site.site.test(v)))) return site; })(); if (site) { for each (let [n, v] in info) { if (site.name && !site.name(n)) continue; let m = n.match(site.value) || v.match(site.value); if (m) return site.url(Array.slice(m, 1)); } } let urls = info.filter(function ([n, v]) /^https?:\/\//(v)); if (!urls.length) return liberator.echoerr('Could not found URL'); commandline.input( 'Select the link you wish to open: ', function (url) { liberator.open(url, where); }, { default: urls[0][1], completer: function (context) { context.completions = [[v, n] for each ([n, v] in urls)]; } } ); } hints.addMode( modeName, DESC, function (elem) { liberator.open(open(elem), where); }, function () '//embed | //object | //img' ); commands.addUserCommand( ['embhint'], DESC, function (args) { hints.show(modeName); }, {}, true ); })(); // vim:sw=2 ts=2 et si fdm=marker: