var PLUGIN_INFO = {NAME} Vimperator plugin for Greasemonkey teramako 0.6c 2.0pre 2.0pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/gmperator.js (: - filename : {String} - name : {String} - namespace : {String} - description: {String} - enabled : {Boolean} - includes : {String[]} - encludes : {String[]} ) ]]> ; (function(){ const Cc = Components.classes; const Ci = Components.interfaces; const gmID = '@greasemonkey.mozdev.org/greasemonkey-service;1'; if (!Cc[gmID]){ liberator.log('Greasemonkey is not installed',0); return; } liberator.plugins.gmperator = (function(){ //{{{ // ----------------------- // PUBLIC section // ----------------------- // {{{ var manager = { register: function (uri,sandbox,script){ var panelID = getPanelID(sandbox.window); if (!panelID) return; var gmCon; if (containers[panelID] && containers[panelID].uri == uri){ gmCon = containers[panelID]; } else { gmCon = new GmContainer(uri,sandbox); containers[panelID] = gmCon; this.__defineGetter__(panelID,function() gmCon); //liberator.log('gmpeartor: Registered: ' + panelID + ' - ' + uri,8); } gmCon.sandbox = sandbox; gmCon.addScript(script); gmCon.uri = uri; triggerGMEvent('GMInjectedScript',uri,script._filename); if (panelID == this.currentPanel){ triggerGMEvent('GMActiveScript',uri,script._filename); } }, get gmScripts() GM_getConfig().scripts, get allItem() containers, get currentPanel() getBrowser().mCurrentTab.linkedPanel, get currentContainer() containers[this.currentPanel] || null, get currentSandbox(){ var id = this.currentPanel; return containers[id] ? containers[id].sandbox : null; }, getSandboxFromWindow: function(win){ for each (let c in containers){ if (c.sandbox.window == win) return sandbox; } return null; }, getContainersFromURI: function(uri){ var list = []; for each (let c in containers){ if (c.uri == uri) list.push(c); } return list.length > 0 ? list : null; } }; // }}} // ----------------------- // PRIVATE section // ----------------------- // {{{ var containers = {}; var gmSvc = Cc[gmID].getService().wrappedJSObject; function appendCode(target,name,func){ var original = target[name]; target[name] = function(){ var tmp = original.apply(target,arguments); func.apply(this,arguments); return tmp; }; } appendCode(gmSvc,'evalInSandbox',function(code,uri,sandbox,script){ liberator.plugins.gmperator.register(uri,sandbox,script); }); function getPanelID(win){ var tabs = getBrowser().mTabs; for (let i=0,l=tabs.length; i; var scripts = GM_getConfig().scripts; var reg; if (args.bang || args.string == 'full'){ reg = new RegExp(); } else if (args.string){ reg = new RegExp(args.string,'i'); } if (reg){ for each (let s in scripts){ if (reg.test(s.name) || reg.test(s._filename)){ xml += scriptToString(s); } } } else { let table = ; let tr; for each (let script in scripts){ tr = ; if (script.enabled){ tr.* += ; } else { tr.* += ; } tr.* += ; table.* += tr; } xml += table; } liberator.echo(xml,true); function scriptToString(script){ var table =
{script.name}{script.name}({script._filename})
{script.name}
; [['FileName','_filename'],['NameSpace','namespace'],['Description','description'], ['Includes','includes'],['Excludes','excludes'],['Enabled','enabled']].forEach(function(prop){ let tr = {prop[0]} ; let contents = script[prop[1]]; if (typeof contents == 'string' || typeof contents == 'boolean'){ tr.* += {contents}; } else { let td = ; for (let i=0,l=contents.length; i; } tr.* += td; } table.* += tr; }); return table; } },{ bang:true } ); //}}} commands.addUserCommand(['gmlo[ad]'],'load Greasemonkey scripts', //{{{ function(args){ if (!args.string){ liberator.echoerr('Usage: :gmlo[ad][!] {name|filename}'); return; } var scripts = GM_getConfig().scripts; var script; for (let i=0,l=scripts.length; i/* * ==VimperatorPlugin== * @name niconicoplaylist_cooperation.js * @description this script give you keyboard opration for NicoNicoPlaylist. * @description-ja NicoNicoPlaylist をキーボードで操作できるようにする。 * @author janus_wel <janus_wel@fb3.so-net.ne.jp> * @version 0.32 * @minversion 2.0pre 2008/10/16 * ==/VimperatorPlugin== * * CONSTRAINT * need NicoNicoPlaylist version 1.12 or above * * LICENSE * New BSD License * * USAGE * :nnppushallvideos * 現在のページ内のすべての動画を再生リストに送る。 * ランキングやマイリストのほか、動画ページではオススメ動画が追加される。 * :nnppushthisvideo * 現在見ている動画を再生リストに送る。 * :nnpplaynext [next] * 再生リストの次の動画を再生する。 * :nnpremove [index] * index 番目の動画を再生リストから取り除く。 index は 0 から数える。 * 指定しない場合は一番上が取り除かれる。 * :nnpclear * 再生リストをすべてクリアする。 * :nnpgetlist [numof] * 再生リストの上から numof 個を表示する。指定しない場合は g:nnp_coop_numoflist が使われる。 * :nnprandom * ランダムモードの on / off * :nnploop * ループモードの on / off * :nnpfullscreen * 全画面モードの on / off * * VARIABLES * g:nnp_coop_numoflist * :NNPGetList で表示するリストの個数を指定する。デフォルトは 10 。 * * HISTORY * 2008/07/11 ver. 0.10 - initial written. * 2008/07/15 ver. 0.20 - refactoring. * 2008/09/26 ver. 0.30 - change XPath expression. * - correspond mode toggling (fullscreen, random, loop). * - change caption: display now-playing title and mode's statuses. * - mode's statuses are displayed with the following word. * R: random mode is on * L: loop mode is on * F: fullscreen mode is on * 2008/09/28 ver. 0.31 - bugfix :nnpgetlist in ranking page. * * */ /* 以下のコードを _vimperatorrc に貼り付けると幸せになれるかも。 コマンド ( [',nn'] や [',nr'] の部分 ) は適宜変えてね。 javascript <<EOM // [N],nn // N 番目の動画を再生する。 // 指定なしの場合次の動画が再生される。 liberator.modules.mappings.addUserMap( [liberator.modules.modes.NORMAL], [',nn'], 'play next item in NicoNicoPlaylist', function(count) { if(count === -1) count = 1; liberator.execute(':nnpplaynext ' + count); }, { flags: liberator.modules.Mappings.flags.COUNT } ); // [N],nr // 上から N 個の動画を削除する。 // 指定なしの場合一番上の動画が削除される。 liberator.modules.mappings.addUserMap( [liberator.modules.modes.NORMAL], [',nr'], 'remove item in NicoNicoPlaylist', function(count) { if(count === -1) count = 1; for(let i=0 ; i<count ; ++i) liberator.execute(':nnpremove'); liberator.execute(':nnpgetlist'); }, { flags: liberator.modules.Mappings.flags.COUNT } ); EOM */ (function(){ // thumbnail URL const thumbnailURL = 'http://tn-skr$HOSTNUMBER.smilevideo.jp/smile?i=$VIDEO_ID'; // style const styles = [ '<style type="text/css">', 'table.nnp_coop .index { text-align:right; width:2em; }', 'table.nnp_coop .thumbnail { text-align:center; }', 'table.nnp_coop caption { color:green; }', 'table.nnp_coop thead { text-align:center; }', '</style>', ].join(''); // table const tableTemplate = [ '<table class="nnp_coop">', '$CAPTION', '$THEAD', '<tbody>$ITEMS</tbody>', '</table>', ].join(''); // table caption const captionTemplate = '<caption>now playing: $PLAYTITLE (display $NUMOFDISPLAY / $NUMOFTOTAL$STATUSES)</caption>'; // table head const thead = [ '<thead>', '<tr>', '<td> </td>', '<td>thumbnail</td>', '<td>title</td>', '<td>url</td>', '</tr>', '</thead>', ].join(''); // item const itemHTML = [ '<tr>', '<td class="index">$INDEX:</td>', '<td class="thumbnail"><img src="$THUMBNAILURL" width="33" height="25" /></td>', '<td>$TITLE</td>', '<td>$URL</td>', '</tr>', ].join(''); // scrape from div element that inserted by NicoNicoPlaylist liberator.modules.commands.addUserCommand(['nnpgetlist'], 'get NicoNicoPlaylist', function (args) { var arg = (args.arguments.length > 1) ? args.arguments[0].toString() : args.string; // check existence of NicoNicoPlaylist var playlist = $f('//div[contains(@id, "playlistcontroller_")]'); if(!playlist) { liberator.echoerr('NicoNicoPlaylist is not found.'); return; } var titleNode = $f('//h1') || $f('./html/head/title'); var playTitle = titleNode.textContent; var statuses = ''; if($f('.//input[contains(@id, "-checkbox-random")]', playlist).checked) statuses += 'R'; if($f('.//input[contains(@id, "-checkbox-loop")]', playlist).checked) statuses += 'L'; if($f('.//input[contains(@id, "-checkbox-full")]', playlist).checked) statuses += 'F'; if(statuses) statuses = ' ' + statuses; // check existence of items in NicoNicoPlaylist var nodes = $s('./div[contains(concat(" ", @class, " "), " playlist-list-outer ")]/ul/li/a', playlist); var nodesLength = nodes.length if(nodesLength === 0) { liberator.echoerr('no items in NicoNicoPlaylist.'); return; } // get number of displayed items var numofList = arg.match(/^\d+$/) ? arg : (liberator.globalVariables.nnp_coop_numoflist || 10); // struct display string // generate data var items = new Array; for(let i=0 ; i<nodesLength && i<numofList ; ++i ) { // get video id let id = nodes[i].href.match(/\d+$/); // build thumnail's URL // refer: http://d.hatena.ne.jp/ZIGOROu/20081014/1223991205 let thumbnail = thumbnailURL.replace(/\$HOSTNUMBER/g, id % 2 + 1) .replace(/\$VIDEO_ID/g, id); // evaluate variables and push to list items.push( itemHTML.replace(/\$INDEX/g, i + 1) .replace(/\$THUMBNAILURL/g, thumbnail) .replace(/\$TITLE/g, nodes[i].textContent) .replace(/\$URL/g, nodes[i].href) ); } // evaluate variables var caption = captionTemplate .replace(/\$NUMOFDISPLAY/g, (nodesLength < numofList) ? nodesLength : numofList) .replace(/\$NUMOFTOTAL/g, nodesLength) .replace(/\$PLAYTITLE/g, playTitle) .replace(/\$STATUSES/g, statuses); // final processing var str = styles + tableTemplate.replace(/\$CAPTION/g, caption) .replace(/\$THEAD/g, thead) .replace(/\$ITEMS/g, items.join('')); liberator.echo(str, liberator.modules.commandline.FORCE_MULTILINE); },{} ); // stuff functions // return first node function $f(query, node) { node = node || window.content.document; var result = (node.ownerDocument || node).evaluate( query, node, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); return result.singleNodeValue ? result.singleNodeValue : null; } // return snapshot nodes list function $s(query, node) { node = node || window.content.document; var result = (node.ownerDocument || node).evaluate( query, node, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); var nodes = []; for(let i=0 ; i<result.snapshotLength ; ++i) nodes.push(result.snapshotItem(i)); return nodes; } // define other commands // only send CommandEvent to NicoNicoPlaylist script [ [['nnppushallvideos'], "push all videos to NicoNicoPlaylist", 'GMNNPPushAllVideos'], [['nnppushthisvideo'], "push current video to NicoNicoPlaylist", 'GMNNPPushThisVideo'], [['nnpplaynext'], "play next in NicoNicoPlaylist", 'GMNNPPlayNext'], [['nnpremove'], "remove item in NicoNicoPlaylist", 'GMNNPRemove'], [['nnpclear'], "clear all items in NicoNicoPlaylist", 'GMNNPClear'], [['nnprandom'], "toggle random mode of NicoNicoPlaylist", 'GMNNPRandom'], [['nnploop'], "toggle loop mode of NicoNicoPlaylist", 'GMNNPLoop'], [['nnpfullscreen'], "toggle fullscreen mode of NicoNicoPlaylist", 'GMNNPFullScreen'], ].forEach( function ([command, description, eventname]){ liberator.modules.commands.addUserCommand(command, description, function (arg) { var r = document.createEvent("CommandEvent"); r.initCommandEvent(eventname, true, true, arg.string); window.content.dispatchEvent(r); },{} ); } ); })(); // vim:sw=4 ts=4 et: