// Info let PLUGIN_INFO = LDRCnail LDRize Cooperation from KeySnail KeySnail 上で Minibuffer や LDRize をチョメチョメ https://gist.github.com/raw/917255/ldrc.ks.js https://sites.google.com/site/958site/Home/files/LDRCnail.ks.png 958 0.0.1 Creative Commons 1.8.0 main |javascript| plugins.options["prefer_ldrize.keymap"] = { ":" : function() ext.exec("ldrc-minibuffer"), "j" : null, "k" : null, "p" : null, "v" : null, "o" : null, "S" : function() { plugins.ldrc.getPinnedItemsOrCurrentItem(true).forEach(function(item){ openUILinkIn('view-source:' + item[0], 'tabshifted'); }); }, "l" : function() ext.exec("ldrc-pin-list") }; ||< アドオンの Read It Later を使ってる人はこんな感じにすると便利です >|javascript| plugins.options["prefer_ldrize.keymap"] = { ":" : function() ext.exec("ldrc-minibuffer"), "j" : null, "k" : null, "p" : null, "v" : null, "o" : null, "i" : function() { plugins.ldrc.getPinnedItemsOrCurrentItem(true).forEach(function(item){ RIL.saveLink( item[0].href, item[1], RIL.xul('clickToSaveTags').value); }); } "l" : function() ext.exec("ldrc-pin-list") }; ||< というか、どうしてもこれをやりたくて、この Plugin を作りました === Minibuffer を KeySnail の Shell で === こんな感じで動かすことも出来ます >|javascript| shell.add( ['minibuffer', 'mb'], 'minibuffer', function(args) plugins.ldrc.Minibuffer.execute(args.join('')), { argCount: '*', completer: function(args, extra) plugins.ldrc.minibufferCompleter(extra.left || '') }, true ); plugins.options["prefer_ldrize.keymap"] = { ":" : function() shell.input("mb "), "j" : null, "k" : null, "p" : null, "v" : null, "o" : null, "t" : null, "l" : function() ext.exec("ldrc-pin-list") }; ||< === plugins.ldrc === LDRize のピンを取得できたりします >|javascript| let items = plugins.ldrc.getPinnedItems(); alert(items); ||< とか >|javascript| let items = plugins.ldrc.getPinnedItemsOrCurrentItem(); alert(items); ||< パラメータに true を指定すると、ついでに clear-pin します >|javascript| let items = plugins.ldrc.getPinnedItemsOrCurrentItem(true); alert(items); ||< 他のスクリプトから LDRize オブジェクトや Minibuffer オブジェクトに触ることができます >|javascript| plugins.ldrc.Minibuffer.execute('clear-pin'); ||< とか >|javascript| let text = plugins.ldrc.LDRize.getPinnedItemsOrCurrentItem()[0].node.textContent; alert(text); ||< スクリプトを書けば、色々できると思います ピンのリンクををダウンローダに渡したりとか・・・ === 流用元 === ldrize_cooperation.js at master from vimpr/vimperator-plugins - GitHub https://github.com/vimpr/vimperator-plugins/blob/master/ldrize_cooperation.js ]]> ; // options let pOptions = plugins.setupOptions("ldrc", { "add_list_actions" : { preset: [], description: M({ ja: 'エクステ `ldrc-pin-list` で表示されるピンリスト一覧で追加するアクション', en: 'Action list of ext `ldrc-pin-list`' }) }, "pin_list_keymap" : { preset: { "C-z" : "prompt-toggle-edit-mode", "SPC" : "prompt-next-page", "b" : "prompt-previous-page", "j" : "prompt-next-completion", "k" : "prompt-previous-completion", "g" : "prompt-beginning-of-candidates", "G" : "prompt-end-of-candidates", "q" : "prompt-cancel", // specific actions "v" : "open-current-tab", "o" : "open-foreground-tab", "O" : "open-background-tab", "p" : "toggle-pin" }, description: M({ ja: 'エクステ `ldrc-pin-list` で表示されるピンリスト一覧のキーマップ', en: 'Local keymaps in ext `ldrc-pin-list`.' }) } }, PLUGIN_INFO); let ldrc = (function(){ // Hook greasemonkey let gmService = Cc["@greasemonkey.mozdev.org/greasemonkey-service;1"]; if (!gmService) { // greasemonkey not installed return null; } // Hook Greasemonkey hook.addToHook('PluginLoaded', function () { // Prefer-LDRize との衝突を避けるために、 PluginLoaded 後に実行する gmService = gmService.getService().wrappedJSObject; if (!my.ldrcSavedEvalInSandbox) my.ldrcSavedEvalInSandbox = gmService.evalInSandbox; if (!my.savedEvalInSandbox) { var org = my.ldrcSavedEvalInSandbox; } else { var org = gmService.evalInSandbox; } gmService.evalInSandbox = function (code, codebase, sandbox) { org.apply(this, arguments); try { sandbox = (sandbox.window) ? sandbox : codebase; if (sandbox.window.Minibuffer != undefined && sandbox.window.LDRize != undefined) { sandbox.window.addEventListener("focus", function () { self.LDRize = util.evalInContext("self",sandbox.window.LDRize.getSiteinfo); self.Minibuffer = util.evalInContext("command",sandbox.window.Minibuffer.addCommand); if (typeof self.LDRize.getSiteinfo != 'function') self.LDRize = sandbox.window.LDRize; if (typeof self.Minibuffer.addCommand != 'function') self.Minibuffer = sandbox.window.Minibuffer.command; }, false); if (window.content.wrappedJSObject == sandbox.unsafeWindow) { self.LDRize = util.evalInContext("self",sandbox.window.LDRize.getSiteinfo); self.Minibuffer = util.evalInContext("command",sandbox.window.Minibuffer.addCommand); if (typeof self.LDRize.getSiteinfo != 'function') self.LDRize = sandbox.window.LDRize; if (typeof self.Minibuffer.addCommand != 'function') self.Minibuffer = sandbox.window.Minibuffer.command; } } } catch (e) { if (util.fbug) util.fbug(e); } }; }); // Global var self = { LDRize: { getSiteinfo: function() undefined }, Minibuffer: null, // Pin getPinnedItems: function(clearPin){ if (!self.LDRize || typeof self.LDRize.getSiteinfo != 'function') return []; let linkXpath = self.LDRize.getSiteinfo()["link"]; let viewXpath = self.LDRize.getSiteinfo()["view"] || linkXpath; let ret = self.LDRize.getPinnedItems().map(function(i){ let linkResult = i.XPath(linkXpath),viewResult = i.XPath(viewXpath); return [linkResult,viewResult ? viewResult.textContent : null]; }); if (clearPin) self.Minibuffer.execute('clear-pin'); return ret; }, getPinnedItemsOrCurrentItem: function(clearPin){ if (!self.LDRize || typeof self.LDRize.getSiteinfo != 'function') return []; let linkXpath = self.LDRize.getSiteinfo()["link"]; let viewXpath = self.LDRize.getSiteinfo()["view"] || linkXpath; let ret = self.LDRize.getPinnedItemsOrCurrentItem().map(function(i){ let linkResult = i.XPath(linkXpath),viewResult = i.XPath(viewXpath); return [linkResult,viewResult ? viewResult.textContent : null]; }); if (clearPin) self.Minibuffer.execute('clear-pin'); return ret; }, // Minibuffer minibufferCompleter: function(word){ if (!self.Minibuffer) return {collection: [], origin: 0, query: word}; let completionList = []; let command = self.Minibuffer.command; let alias = self.Minibuffer.alias_getter(); let tokens = (word || '').split("|").map(function(str) str.replace(/\s+/g,"")); let exp = new RegExp("^" + tokens.pop(), 'i'); for(let i in command) if(exp.test(i))completionList.push(tokens.concat(i).join(" | ")); for(let i in alias) if(exp.test(i))completionList.push(i); return {collection: completionList, origin: 0, query: word}; } }; return self; })(); if (ldrc) plugins.withProvides(function (provide) { let listActions = [ [ function(aIndex, items){ openUILinkIn(items[aIndex][0]); }, "View", "open-current-tab" ], [ function(aIndex, items){ openUILinkIn(items[aIndex][0], 'tab'); }, "Open link in new tab (foreground)", "open-foreground-tab" ], [ function(aIndex, items){ openUILinkIn(items[aIndex][0], 'tabshifted'); }, "Open link in new tab (background)", "open-background-tab" ], [ function(aIndex, items){ if (items.length == 0) return; ldrc.LDRize.togglePin([ldrc.LDRize.getPinnedItems()[aIndex].node]); items.splice(aIndex, 1); if (items.length == 0) prompt.finish(); else prompt.refresh(); }, "Toggle pin", "toggle-pin,c" ] ].concat(pOptions["add_list_actions"]); provide("ldrc-pin-list", function(){ let links = ldrc.getPinnedItems(); if (links.length == 0) return; prompt.selector({ message : 'LDRize pin list:', collection : links, flags : [0, 0], style : [style.prompt.url, style.prompt.description], header : ['URL', 'Text'], keymap : pOptions["pin_list_keymap"], initialAction : 2, // onChange : function (arg) { // ldrc.LDRize.getPinnedItems()[arg.index].node.scrollIntoView(); // }, actions : listActions }); }, M({ ja: 'LDRize のピンリストを表示', en: "Show LDRize pinned links" }) ); provide("ldrc-minibuffer", function(ev, arg){ prompt.reader({ message: 'minibuffer:', escapeWhiteSpace : false, completer : function (left, whole) { let ret = ldrc.minibufferCompleter(left); return ret; }, callback: function (str) { ldrc.Minibuffer.execute(str.replace(/\\+/g,"")) } }); }, M({ ja: 'Minibuffer のコマンドを実行', en: "Execute minibuffer command" }) ); plugins.ldrc = ldrc; }, PLUGIN_INFO);