From aad373b519fdaf2b04004db3e95c1571c5d9ddf8 Mon Sep 17 00:00:00 2001 From: shunirr Date: Thu, 20 Mar 2008 16:32:41 +0000 Subject: lang/javascript/vimperator-plugins/trunk lang/javascript/vimperator-plugins/tags/0.5.3 - mkdir trunk, tags - mv some files git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@8221 d0d07461-0603-4401-acd4-de1884942a52 --- char-hints-mod.js | 709 +++++++++++++++++++++++++++++++++++++++++++++++++ direct_hb.js | 215 +++++++++++++++ encodingSwitcher.js | 197 ++++++++++++++ ex_autocmd.js | 17 ++ googlesugest.js | 29 ++ hatenabookmark_show.js | 44 +++ ldrize_cooperation.js | 187 +++++++++++++ twitter.js | 38 +++ 8 files changed, 1436 insertions(+) create mode 100644 char-hints-mod.js create mode 100644 direct_hb.js create mode 100644 encodingSwitcher.js create mode 100644 ex_autocmd.js create mode 100644 googlesugest.js create mode 100644 hatenabookmark_show.js create mode 100644 ldrize_cooperation.js create mode 100644 twitter.js diff --git a/char-hints-mod.js b/char-hints-mod.js new file mode 100644 index 0000000..05a3382 --- /dev/null +++ b/char-hints-mod.js @@ -0,0 +1,709 @@ +// Vimperator plugin: 'Char Hints Mod' +// Last Change: 15-Mar-2008. Jan 2008 +// License: GPL +// Version: 0.2 +// Maintainer: Trapezoid + +// This file is a tweak based on char-hints.js by: +// (c) 2008: marco candrian +// This file is a tweak based on hints.js by: +// (c) 2006-2008: Martin Stubenschrott + +// Tested with vimperator 0.6pre from 2008-03-07 +// (won't work with older versions) + +// INSTALL: put this file into ~/.vimperator/plugin/ (create folders if necessary) +// and restart firefox or :source that file + +// plugin-setup +vimperator.plugins.charhints = {}; +var chh = vimperator.plugins.charhints; + +//<<<<<<<<<<<<<<<< EDIT USER SETTINGS HERE + +//chh.hintchars = "asdfjkl"; // chars to use for generating hints +chh.hintchars = "hjklasdfgyuiopqwertnmzxcvb"; // chars to use for generating hints + +chh.showcapitals = true; // show capital letters, even with lowercase hintchars +chh.timeout = 500; // in 1/000sec; when set to 0, press to follow + +chh.fgcolor = "black"; // hints foreground color +chh.bgcolor = "yellow"; // hints background color +chh.selcolor = "#99FF00"; // selected/active hints background color + +chh.mapNormal = "f"; // trigger normal mode with... +chh.mapNormalNewTab = "F"; // trigger and open in new tab +chh.mapExtended = ";"; // open in extended mode (see notes below) + +chh.hinttags = "//*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " + +"//input[not(@type='hidden')] | //a | //area | //iframe | //textarea | //button | //select | " + +"//xhtml:*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @class='lk' or @class='s'] | " + +"//xhtml:input[not(@type='hidden')] | //xhtml:a | //xhtml:area | //xhtml:iframe | //xhtml:textarea | " + +"//xhtml:button | //xhtml:select"; + +//======================================== +// extended hints mode arguments +// +// ; to focus a link and hover it with the mouse +// a to save its destination (prompting for save location) +// s to save its destination +// o to open its location in the current tab +// t to open its location in a new tab +// O to open its location in an :open query +// T to open its location in a :tabopen query +// v to view its destination source +// w to open its destination in a new window +// W to open its location in a :winopen query +// y to yank its location +// Y to yank its text description + +// variables etc//{{{ + + +// ignorecase when showcapitals = true +// (input keys on onEvent gets lowercased too + +if (chh.showcapitals) + chh.hintchars = chh.hintchars.toLowerCase(); + + +chh.submode = ""; // used for extended mode, can be "o", "t", "y", etc. +chh.hintString = ""; // the typed string part of the hint is in this string +chh.hintNumber = 0; // only the numerical part of the hint +chh.usedTabKey = false; // when we used to select an element + +chh.hints = []; +chh.validHints = []; // store the indices of the "hints" array with valid elements + +chh.activeTimeout = null; // needed for hinttimeout > 0 +chh.canUpdate = false; + +// used in number2hintchars +chh.transval = {"0":0, "1":1, "2":2, "3":3, "4":4, "5":5, "6":6, "7":7, "8":8, "9":9, "a":10, "b":11, + "c":12, "d":13,"e":14, "f":15, "g":16, "h":17, "i":18, "j":19, "k":20, "l":21, "m":22, "n":23, + "o":24, "p":25,"q":26, "r":27, "s":28, "t":29, "u":30, "v":31, "w":32, "x":33, "y":34, "z":35}; + +// used in hintchars2number +chh.conversion = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +// keep track of the documents which we generated the hints for +// docs = { doc: document, start: start_index in hints[], end: end_index in hints[] } +chh.docs = []; +//}}} +// reset all important variables +chh.reset = function ()//{{{ +{ + vimperator.statusline.updateInputBuffer(""); + chh.hintString = ""; + chh.hintNumber = 0; + chh.usedTabKey = false; + chh.hints = []; + chh.validHints = []; + chh.canUpdate = false; + chh.docs = []; + + if (chh.activeTimeout) + clearTimeout(chh.activeTimeout); + chh.activeTimeout = null; +} +//}}} +chh.updateStatusline = function ()//{{{ +{ + vimperator.statusline.updateInputBuffer(("") + + (chh.hintString ? "\"" + chh.hintString + "\"" : "") + + (chh.hintNumber > 0 ? " <" + chh.hintNumber + ">" : "")); +} +//}}} +// this function 'click' an element, which also works +// for javascript links +chh.hintchars2number = function (hintstr)//{{{ +{ + // convert into 'normal number then make it decimal-based + + var converted = ""; + + // translate users hintchars into a number (chh.conversion) 0 -> 0, 1 -> 1, ... + for (var i = 0, l = hintstr.length; i < l; i++) + converted += "" + chh.conversion[chh.hintchars.indexOf(hintstr[i])]; + + // add one, since hints begin with 0; + + return parseInt(converted, chh.hintchars.length); // hintchars.length is the base/radix +} +//}}} +chh.number2hintchars = function (nr)//{{{ +{ + var oldnr = nr; + var converted = ""; + var tmp = ""; + + tmp = nr.toString(chh.hintchars.length); // hintchars.length is the base/radix) + + // translate numbers into users hintchars + // tmp might be 2e -> (chh.transval) 2 and 14 -> (chh.hintchars) according hintchars + + for (var i = 0, l = tmp.length; i < l; i++) + converted += "" + chh.hintchars[chh.transval[tmp[i]]]; + + return converted; +} +//}}} +chh.openHint = function (where)//{{{ +{ + if (chh.validHints.length < 1) + return false; + + var x = 1, y = 1; + var elem = chh.validHints[chh.hintNumber - 1] || chh.validHints[0]; + var elemTagName = elem.localName.toLowerCase(); + elem.focus(); + + vimperator.buffer.followLink(elem, where); + return true; +} +//}}} +chh.focusHint = function ()//{{{ +{ + if (chh.validHints.length < 1) + return false; + + var elem = chh.validHints[chh.hintNumber - 1] || chh.validHints[0]; + var doc = window.content.document; + var elemTagName = elem.localName.toLowerCase(); + if (elemTagName == "frame" || elemTagName == "iframe") + { + elem.contentWindow.focus(); + return false; + } + else + { + elem.focus(); + } + + var evt = doc.createEvent("MouseEvents"); + var x = 0; + var y = 0; + // for imagemap + if (elemTagName == "area") + { + [x, y] = elem.getAttribute("coords").split(","); + x = Number(x); + y = Number(y); + } + + evt.initMouseEvent("mouseover", true, true, doc.defaultView, 1, x, y, 0, 0, 0, 0, 0, 0, 0, null); + elem.dispatchEvent(evt); +} +//}}} +chh.yankHint = function (text)//{{{ +{ + if (chh.validHints.length < 1) + return false; + + var elem = chh.validHints[chh.hintNumber - 1] || chh.validHints[0]; + if (text) + var loc = elem.textContent; + else + var loc = elem.href; + + vimperator.copyToClipboard(loc); + vimperator.echo("Yanked " + loc, vimperator.commandline.FORCE_SINGLELINE); +} +//}}} +chh.saveHint = function (skipPrompt)//{{{ +{ + if (chh.validHints.length < 1) + return false; + + var elem = chh.validHints[chh.hintNumber - 1] || chh.validHints[0]; + + try + { + vimperator.buffer.saveLink(elem,skipPrompt); + } + catch (e) + { + vimperator.echoerr(e); + } +} +//}}} +chh.generate = function (win)//{{{ +{ + var startDate = Date.now(); + + if (!win) + win = window.content; + + var doc = win.document; + var height = win.innerHeight; + var width = win.innerWidth; + var scrollX = doc.defaultView.scrollX; + var scrollY = doc.defaultView.scrollY; + + var baseNodeAbsolute = doc.createElementNS("http://www.w3.org/1999/xhtml", "span"); + baseNodeAbsolute.style.backgroundColor = "red"; + baseNodeAbsolute.style.color = "white"; + baseNodeAbsolute.style.position = "absolute"; + baseNodeAbsolute.style.fontSize = "10px"; + baseNodeAbsolute.style.fontWeight = "bold"; + baseNodeAbsolute.style.lineHeight = "10px"; + baseNodeAbsolute.style.padding = "0px 1px 0px 0px"; + baseNodeAbsolute.style.zIndex = "10000001"; + baseNodeAbsolute.style.display = "none"; + baseNodeAbsolute.className = "vimperator-hint"; + + var elem, tagname, text, span, rect; + var res = vimperator.buffer.evaluateXPath(chh.hinttags, doc, null, true); + vimperator.log("shints: evaluated XPath after: " + (Date.now() - startDate) + "ms"); + + var fragment = doc.createDocumentFragment(); + var start = chh.hints.length; + while ((elem = res.iterateNext()) != null) + { + // TODO: for frames, this calculation is wrong + rect = elem.getBoundingClientRect(); + if (!rect || rect.top > height || rect.bottom < 0 || rect.left > width || rect.right < 0) + continue; + + rect = elem.getClientRects()[0]; + if (!rect) + continue; + + // TODO: mozilla docs recommend localName instead of tagName + tagname = elem.tagName.toLowerCase(); + text = ""; + span = baseNodeAbsolute.cloneNode(true); + span.style.left = (rect.left + scrollX) + "px"; + span.style.top = (rect.top + scrollY) + "px"; + fragment.appendChild(span); + + chh.hints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color]); + } + + doc.body.appendChild(fragment); + chh.docs.push({ doc: doc, start: start, end: chh.hints.length - 1 }); + + // also generate hints for frames + for (var i = 0; i < win.frames.length; i++) + chh.generate(win.frames[i]); + + vimperator.log("shints: generate() completed after: " + (Date.now() - startDate) + "ms"); + return true; +} +//}}} +// TODO: make it aware of imgspans +chh.showActiveHint = function (newID, oldID)//{{{ +{ + var oldElem = chh.validHints[oldID - 1]; + if (oldElem) + oldElem.style.backgroundColor = chh.bgcolor; + + var newElem = chh.validHints[newID - 1]; + if (newElem) + newElem.style.backgroundColor = chh.selcolor; +} +//}}} +chh.showHints = function ()//{{{ +{ + var startDate = Date.now(); + var win = window.content; + var height = win.innerHeight; + var width = win.innerWidth; + + + var elem, tagname, text, rect, span, imgspan; + var hintnum = 1; + //var findTokens = chh.hintString.split(/ +/); + var activeHint = chh.hintNumber || 1; + chh.validHints = []; + + for (var j = 0; j < chh.docs.length; j++) + { + var doc = chh.docs[j].doc; + var start = chh.docs[j].start; + var end = chh.docs[j].end; + var scrollX = doc.defaultView.scrollX; + var scrollY = doc.defaultView.scrollY; + +outer: + for (let i = start; i <= end; i++) + { + [elem, , span, imgspan] = chh.hints[i]; + text = ""; + + if (elem.firstChild && elem.firstChild.tagName == "IMG") + { + if (!imgspan) + { + rect = elem.firstChild.getBoundingClientRect(); + if (!rect) + continue; + + imgspan = doc.createElementNS("http://www.w3.org/1999/xhtml", "span"); + imgspan.style.position = "absolute"; + imgspan.style.opacity = 0.5; + imgspan.style.zIndex = "10000000"; + imgspan.style.left = (rect.left + scrollX) + "px"; + imgspan.style.top = (rect.top + scrollY) + "px"; + imgspan.style.width = (rect.right - rect.left) + "px"; + imgspan.style.height = (rect.bottom - rect.top) + "px"; + imgspan.className = "vimperator-hint"; + chh.hints[i][3] = imgspan; + doc.body.appendChild(imgspan); + } + imgspan.style.backgroundColor = (activeHint == hintnum) ? chh.selcolor : chh.bgcolor; + imgspan.style.display = "inline"; + } + + if (!imgspan) + elem.style.backgroundColor = (activeHint == hintnum) ? chh.selcolor : chh.bgcolor; + elem.style.color = chh.fgcolor; + if (chh.showcapitals) + span.textContent = chh.number2hintchars(hintnum++).toUpperCase(); + else + span.textContent = chh.number2hintchars(hintnum++); + + span.style.display = "inline"; + chh.validHints.push(elem); + } + } + + vimperator.log("shints: showHints() completed after: " + (Date.now() - startDate) + "ms"); + return true; +} +//}}} +chh.removeHints = function (timeout)//{{{ +{ + var firstElem = chh.validHints[0] || null; + var firstElemselcolor = ""; + var firstElemColor = ""; + + for (var j = 0; j < chh.docs.length; j++) + { + var doc = chh.docs[j].doc; + var start = chh.docs[j].start; + var end = chh.docs[j].end; + + for (let i = start; i <= end; i++) + { + // remove the span for the numeric display part + doc.body.removeChild(chh.hints[i][2]); + if (chh.hints[i][3]) // a transparent span for images + doc.body.removeChild(chh.hints[i][3]); + + if (timeout && firstElem == chh.hints[i][0]) + { + firstElemselcolor = chh.hints[i][4]; + firstElemColor = chh.hints[i][5]; + } + else + { + // restore colors + var elem = chh.hints[i][0]; + elem.style.backgroundColor = chh.hints[i][4]; + elem.style.color = chh.hints[i][5]; + } + } + + // animate the disappearance of the first hint + if (timeout && firstElem) + { + setTimeout(function () { + firstElem.style.backgroundColor = firstElemselcolor; + firstElem.style.color = firstElemColor; + }, timeout); + } + } + + vimperator.log("shints: removeHints() done"); + chh.reset(); +} +//}}} +chh.processHints = function (followFirst)//{{{ +{ + if (chh.validHints.length == 0) + { + vimperator.beep(); + return false; + } + + if (!followFirst) + { + var firstHref = chh.validHints[0].getAttribute("href") || null; + if (firstHref) + { + if (chh.validHints.some(function (e) { return e.getAttribute("href") != firstHref; })) + return false; + } + else if (chh.validHints.length > 1) + return false; + } + + var activeNum = chh.hintNumber || 1; + var loc = chh.validHints[activeNum - 1].href || ""; + switch (chh.submode) + { + case ";": chh.focusHint(); break; + case "a": chh.saveHint(false); break; + case "s": chh.saveHint(true); break; + case "o": chh.openHint(vimperator.CURRENT_TAB); break; + case "O": vimperator.commandline.open(":", "open " + loc, vimperator.modes.EX); break; + case "t": chh.openHint(vimperator.NEW_TAB); break; + case "T": vimperator.commandline.open(":", "tabopen " + loc, vimperator.modes.EX); break; + case "w": chh.openHint(vimperator.NEW_WINDOW); break; + case "W": vimperator.commandline.open(":", "winopen " + loc, vimperator.modes.EX); break; + case "y": chh.yankHint(false); break; + case "Y": chh.yankHint(true); break; + default: + vimperator.echoerr("INTERNAL ERROR: unknown submode: " + chh.submode); + } + + var timeout = followFirst ? 0 : 500; + chh.removeHints(timeout); + + if (vimperator.modes.extended & vimperator.modes.ALWAYS_HINT) + { + setTimeout(function () { + chh.canUpdate = true; + chh.hintString = ""; + chh.hintNumber = 0; + vimperator.statusline.updateInputBuffer(""); + }, timeout); + } + else + { + if (timeout == 0 || vimperator.modes.isReplaying) + { + // force a possible mode change, based on wheter an input field has focus + vimperator.events.onFocusChange(); + if (vimperator.mode == vimperator.modes.CUSTOM) + vimperator.modes.reset(false); + } + else + { + vimperator.modes.add(vimperator.modes.INACTIVE_HINT); + setTimeout(function () { + if (vimperator.mode == vimperator.modes.CUSTOM) + vimperator.modes.reset(false); + }, timeout); + } + } + + return true; +} +//}}} +// TODO: implement framesets +chh.show = function (mode, minor, filter)//{{{ +{ + if (mode == vimperator.modes.EXTENDED_HINT && !/^[;asoOtTwWyY]$/.test(minor)) + { + vimperator.beep(); + return; + } + + vimperator.modes.set(vimperator.modes.CUSTOM, mode); + chh.submode = minor || "o"; // open is the default mode + chh.hintString = filter || ""; + chh.hintNumber = 0; + chh.canUpdate = false; + + chh.generate(); + + // get all keys from the input queue + var mt = Components.classes["@mozilla.org/thread-manager;1"].getService().mainThread; + while (mt.hasPendingEvents()) + mt.processNextEvent(true); + + chh.canUpdate = true; + chh.showHints(); + + if (chh.validHints.length == 0) + { + vimperator.beep(); + vimperator.modes.reset(); + return false; + } + else if (chh.validHints.length == 1) + { + chh.processHints(true); + return false; + } + else // still hints visible + return true; +} +//}}} +chh.hide = function ()//{{{ +{ + chh.removeHints(0); +} +//}}} +chh.onEvent = function (event)//{{{ +{ + var key = vimperator.events.toString(event); + + if (chh.showcapitals && key.length == 1) + key = key.toLowerCase(); + + // clear any timeout which might be active after pressing a number + if (chh.activeTimeout) + { + clearTimeout(chh.activeTimeout); + chh.activeTimeout = null; + } + + switch (key) + { + case "": + chh.processHints(true); + break; + + case "": + case "": + chh.usedTabKey = true; + if (chh.hintNumber == 0) + chh.hintNumber = 1; + + var oldID = chh.hintNumber; + if (key == "") + { + if (++chh.hintNumber > chh.validHints.length) + chh.hintNumber = 1; + } + else + { + if (--chh.hintNumber < 1) + chh.hintNumber = chh.validHints.length; + } + chh.showActiveHint(chh.hintNumber, oldID); + return; + + case "": //TODO: may tweak orig hints.js too (adding 2 lines ...) + var oldID = chh.hintNumber; + if (chh.hintNumber > 0) + { + chh.hintNumber = Math.floor(chh.hintNumber / chh.hintchars.length); + chh.hintString = chh.hintString.substr(0, chh.hintString.length - 1); + chh.usedTabKey = false; + } + else + { + chh.usedTabKey = false; + chh.hintNumber = 0; + vimperator.beep(); + return; + } + chh.showActiveHint(chh.hintNumber, oldID); + break; + + case "": + case "": + chh.hintString = ""; + chh.hintNumber = 0; + break; + + default: + // pass any special or ctrl- etc. prefixed key back to the main vimperator loop + if (/^<./.test(key) || key == ":") + { + //FIXME: won't work probably + var map = null; + if ((map = vimperator.mappings.get(vimperator.modes.NORMAL, key)) || + (map = vimperator.mappings.get(vimperator.modes.CUSTOM, key))) //TODO + { + map.execute(null, -1); + return; + } + + vimperator.beep(); + return; + } + + if (chh.hintchars.indexOf(key) >= 0) // TODO: check if in hintchars + { + chh.hintString += key; + var oldHintNumber = chh.hintNumber; + if (chh.hintNumber == 0 || chh.usedTabKey) + { + chh.usedTabKey = false; + } + + chh.hintNumber = chh.hintchars2number(chh.hintString); + + chh.updateStatusline(); + + if (!chh.canUpdate) + return; + + if (chh.docs.length == 0) + { + chh.generate(); + chh.showHints(); + } + chh.showActiveHint(chh.hintNumber, oldHintNumber || 1); + + if (chh.hintNumber == 0 || chh.hintNumber > chh.validHints.length) + { + vimperator.beep(); + return; + } + + // orig hints.js comment: if we write a numeric part like 3, but we have 45 hints, only follow + // the hint after a timeout, as the user might have wanted to follow link 34 + if (chh.hintNumber > 0 && chh.hintNumber * chh.hintchars.length <= chh.validHints.length) + { + if (chh.timeout > 0) + chh.activeTimeout = setTimeout(function () { chh.processHints(true); }, chh.timeout); + + return false; + } + // we have a unique hint + chh.processHints(true); + return; + } + + if (chh.usedTabKey) + { + chh.usedTabKey = false; + chh.showActiveHint(1, chh.hintNumber); + } + } + + chh.updateStatusline(); +}//}}} + + +// <<<<<<<<<<<<<<< registering/setting up this plugin + +vimperator.modes.setCustomMode ("CHAR-HINTS", vimperator.plugins.charhints.onEvent, + vimperator.plugins.charhints.hide); + +vimperator.mappings.addUserMap([vimperator.modes.NORMAL], [chh.mapNormal], + "Start Custum-QuickHint mode", + function () { vimperator.plugins.charhints.show(vimperator.modes.QUICK_HINT); }, + { noremap: true } +); + +vimperator.mappings.addUserMap([vimperator.modes.NORMAL], [chh.mapNormalNewTab], + "Start Custum-QuickHint mode, but open link in a new tab", + function () { vimperator.plugins.charhints.show(vimperator.modes.QUICK_HINT, "t"); }, + { noremap: true } +); + +vimperator.mappings.addUserMap([vimperator.modes.NORMAL], [chh.mapExtended], + "Start an extended hint mode", + function (arg) + { + if (arg == "f") + vimperator.plugins.charhints.show(vimperator.modes.ALWAYS_HINT, "o"); + else if (arg == "F") + vimperator.plugins.charhints.show(vimperator.modes.ALWAYS_HINT, "t"); + else + vimperator.plugins.charhints.show(vimperator.modes.EXTENDED_HINT, arg); + }, + { + flags: vimperator.Mappings.flags.ARGUMENT, + noremap: true + } +); + +// vim: set fdm=marker sw=4 ts=4 et: diff --git a/direct_hb.js b/direct_hb.js new file mode 100644 index 0000000..e734e39 --- /dev/null +++ b/direct_hb.js @@ -0,0 +1,215 @@ +// Vimperator plugin: 'Direct Hatena Bookmark' +// Last Change: 14-Mar-2008. Jan 2008 +// License: Creative Commons +// Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid +// Parts: +// http://d.hatena.ne.jp/fls/20080309/p1 +// Pagerization (c) id:ofk +// AutoPagerize(c) id:swdyh +// +// Hatena bookmark direct add script for vimperator0.6.* +(function(){ + var isNormalize = true; + + function WSSEUtils(aUserName, aPassword){ + this._init(aUserName, aPassword); + } + + WSSEUtils.prototype = { + + get userName(){ + return this._userName; + }, + + get noce(){ + return this._nonce; + }, + + get created(){ + return this._created; + }, + + get passwordDigest(){ + return this._passwordDigest; + }, + + getWSSEHeader: function(){ + var result = [ + 'UsernameToken Username="' + this._userName + '", ', + 'PasswordDigest="' + this._passwordDigest + '=", ', + 'Nonce="' + this._nonce + '", ', + 'Created="' + this._created + '"' + ].join(""); + + return result; + }, + + _init: function(aUserName, aPassword){ + var uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator); + var seed = (new Date()).toUTCString() + uuidGenerator.generateUUID().toString(); + + this._userName = aUserName; + this._nonce = this._getSha1Digest(seed, true); + this._created = this._getISO8601String((new Date())); + this._passwordDigest = this._getSha1Digest(this._getSha1Digest(seed, false) + this._created + aPassword, true); + }, + + _getSha1Digest: function(aString, aBase64){ + var cryptoHash = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash); + cryptoHash.init(Ci.nsICryptoHash.SHA1); + + var inputStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream); + inputStream.setData(aString, aString.length); + cryptoHash.updateFromStream(inputStream, -1); + + return cryptoHash.finish(aBase64); + }, + + _getISO8601String: function(aDate){ + function zeropad(s, l) { + while(s.length < l){ + s = "0" + s; + } + return s; + } + + var result = [ + zeropad(aDate.getUTCFullYear(), 4), "-", + zeropad(aDate.getUTCMonth() + 1, 2), "-", + zeropad(aDate.getUTCDate(), 2), "T", + zeropad(aDate.getUTCHours(), 2), ":", + zeropad(aDate.getUTCMinutes(), 2), ":", + zeropad(aDate.getUTCSeconds(), 2), "Z" + ].join(""); + return result; + } + + }; + + // copied from AutoPagerize(c) id:swdyh + function getElementsByXPath(xpath, node) { + node = node || document; + var nodesSnapshot = (node.ownerDocument || node).evaluate(xpath, node, null, + XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); + var data = []; + for (var i = 0, l = nodesSnapshot.snapshotLength; i < l; + data.push(nodesSnapshot.snapshotItem(i++))); + return (data.length > 0) ? data : null; + } + + function getFirstElementByXPath(xpath, node) { + node = node || document; + var result = (node.ownerDocument || node).evaluate(xpath, node, null, + XPathResult.FIRST_ORDERED_NODE_TYPE, null); + return result.singleNodeValue ? result.singleNodeValue : null; + } + + // copied from Pagerization (c) id:ofk + function parseHTML(str) { + str = str.replace(/^[\S\s]*?]*>|<\/html\s*>[\S\s]*$/ig, ''); + var res = document.implementation.createDocument(null, 'html', null); + var range = document.createRange(); + range.setStartAfter(window.content.document.body); + res.documentElement.appendChild( + res.importNode(range.createContextualFragment(str), true) + ); + return res; + } + + // + // + // + // + + function httpGET(uri,callback){ + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function(){ + if(xhr.readyState == 4){ + if(xhr.status == 200) + callback.call(this,xhr.responseText); + else + throw new Error(xhr.statusText) + } + }; + xhr.open("GET",uri,true); + xhr.send(null); + } + + function getNormalizedPermalink(url){ + var xhr = new XMLHttpRequest(); + xhr.open("GET","http://api.pathtraq.com/normalize_url?url=" + url,false); + xhr.send(null); + if(xhr.status != 200){ + vimperator.echoerr("Pathtraq: URL normalize faild!!"); + return undefined; + } + return xhr.responseText; + } + + function getTags(arg){ + vimperator.plugins.hatena_tags = []; + httpGET("http://b.hatena.ne.jp/my", + function(mypage_text){ + var mypage_html = parseHTML(mypage_text); + var tags = getElementsByXPath("//ul[@id=\"taglist\"]/li/a",mypage_html); + for(var i in tags) + vimperator.plugins.hatena_tags.push(tags[i].innerHTML); + vimperator.echo("Hatena bookmark: Tag parsing is finished. taglist length: " + tags.length); + }); + } + getTags(); + + function addHatenaBookmarks(user,password,url,comment,normalize){ + var target = normalize ? getNormalizedPermalink(url) : url; + var request = + + dummy + + {comment} + ; + var xhr = new XMLHttpRequest(); + xhr.onreadystatechange = function(){ + if(xhr.readyState == 4){ + if(xhr.status == 201) + vimperator.echo("HatenaBookmark: success"); + else + vimperator.echoerr("HatenaBookmark:" + xhr.statusText); + } + }; + var wsse = new WSSEUtils(user,password); + xhr.open("POST","http://b.hatena.ne.jp/atom/post", true); + xhr.setRequestHeader("X-WSSE",wsse.getWSSEHeader()); + xhr.setRequestHeader("Content-Type","application/x.atom+xml"); + xhr.send(request.toString()); + } + vimperator.commands.addUserCommand(['hbtags'],"Update HatenaBookmark Tags", + getTags, + {} + ); + vimperator.commands.addUserCommand(['hb'],"Post to HatenaBookmark", + function(arg){ + try { + var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); + var logins = passwordManager.findLogins({}, 'https://www.hatena.ne.jp', 'https://www.hatena.ne.jp', null); + if(logins.length) + [hatenaUser, hatenaPassword] = [logins[0].username, logins[0].password]; + else + vimperator.echoerr("Hatena bookmark: account not found"); + } + catch(ex) { + } + addHatenaBookmarks(hatenaUser,hatenaPassword,vimperator.buffer.URL,arg,isNormalize); + },{ + completer: function(filter){ + var match_result = filter.match(/(.*)\[(\w*)$/); //[all, commited , now inputting] + var m = new RegExp("^" + match_result[2]); + var completionList = []; + for(var i in vimperator.plugins.hatena_tags) + if(m.test(vimperator.plugins.hatena_tags[i])){ + completionList.push([match_result[1] + "[" + vimperator.plugins.hatena_tags[i] + "]","Tag"]); + } + return [0, completionList]; + } + } + ); +})(); diff --git a/encodingSwitcher.js b/encodingSwitcher.js new file mode 100644 index 0000000..dc0de26 --- /dev/null +++ b/encodingSwitcher.js @@ -0,0 +1,197 @@ +/** + * encodingSwithcer (vimperator plugin) + * @author teramako teramako@gmail.com + * @version 0.1 + * + * Usage: + * + * change encoding + * :set fileencoding = {encodeName} + * :set fenc = {encodeName} + * + * list available encodings + * :listencoding [expr] + * :lsenc [expr] + * + * change auto detector + * :set autodetector = {detectorName} + * :set audet = {detectorName} + * + * list available auto detectors + * :listdetector [expr] + * :lsdet [expr] + */ +(function(){ + +var encodings = []; +var detectors = []; +const Cc = Components.classes; +const Ci = Components.interfaces; +if (!RDF) var RDF = Cc['@mozilla.org/rdf/rdf-service;1'].getService(Ci.nsIRDFService); +if (!RDFCU) var RDFCU = Cc['@mozilla.org/rdf/container-utils;1'].getService(Ci.nsIRDFContainerUtils); +var cm = RDF.GetDataSource('rdf:charset-menu'); +var sbService = Cc['@mozilla.org/intl/stringbundle;1'].getService(Ci.nsIStringBundleService); +var sbCharTitle = sbService.createBundle('chrome://global/locale/charsetTitles.properties'); +CreateMenu('browser'); +CreateMenu('more-menu'); +var allEnum = cm.GetAllResources(); +while (allEnum.hasMoreElements()){ + var res = allEnum.getNext().QueryInterface(Ci.nsIRDFResource); + var value = res.Value; + if (RDFCU.IsContainer(cm, res) || value.indexOf('charset.') == 0 || value.indexOf('----') == 0) { + continue; + } + var label = sbCharTitle.GetStringFromName(value.toLowerCase() + '.title'); + if (res.Value.indexOf('chardet.') == 0){ + value = value.substr('chardet.'.length); + var buf = createDetector(value); + buf[1] = label; + detectors.push(buf); + } else { + encodings.push([value,label]); + } +} +function createDetector(name){ + var i = name.indexOf('_'); + if ( i > 0 ){ + return [name.substr(0,i),null,name.substr(i)]; + } + return [name,null,'']; +} +function getDetector(name){ + detectors.forEach(function(detector){ + if (detector[0].toLowerCase() == name.toLowerCase()){ + return detector[0] + detector[2]; + } + }); +} +function getEncoding(name){ + for (var i=0; i:lsenc command', + defaultValue: DEFAULT_CHARSET, + setter: function(value){ + if (!value) return; + value = getEncoding(value); + SetForcedCharset(value); + SetDefaultCharacterSet(value); + BrowserSetForcedCharacterSet(value); + }, + getter: function(){ + return getBrowser().docShell.QueryInterface(Ci.nsIDocCharset).charset; + }, + validator: function(value){ + return isValid( encodings, value); + }, + completer: function(filter){ + return completion( encodings, filter); + } + } + +)); +var sbCharDetector = sbService.createBundle(gPrefService.getDefaultBranch('intl.charset.').getCharPref('detector')); +const DEFAULT_DETECTOR = createDetector(sbCharDetector.GetStringFromName('intl.charset.detector'))[0]; +vimperator.options.add(new vimperator.Option( ['autodetector','audet'], 'string', + { + shortHelp: 'set auto detect character encoding', + help: 'Please make certain of available value with :lsdet command', + defaultValue: DEFAULT_DETECTOR, + setter: function(value){ + SetForcedDetector(true); + var pref = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefBranch); + var str = Cc['@mozilla.org/supports-string;1'].createInstance(Ci.nsISupportsString); + if (!value || value == 'off') { + str.data = ''; + } else { + str.data = value = getDetector(value); + } + pref.setComplexValue('intl.charset.detector',Ci.nsISupportsString, str); + BrowserSetForcedCharacterSet(value); + }, + getter: function(){ + var elms = document.getElementById('charsetMenu').getElementsByAttribute('checed','true'); + for (var i=0; i'); + list.forEach(function(i){ + if (reg.test(i[0]) || reg.test(i[1])){ + str.push(''); + if (current == i[0]){ + str.push('' + i[0] + '' + i[1] + ''); + } else { + str.push('' + i[0] + '' + i[1] + ''); + } + str.push(''); + } + }); + str.push(''); + vimperator.echo( str.join(''), true); +} +vimperator.commands.add(new vimperator.Command(['listencoding','lsenc'], + function(arg){ + listCharset(arg, vimperator.options.fileencoding, encodings); + },{ + usage: ['listencoding [expr]','lsenc [expr]'], + shortHelp: 'list all encodings', + help: 'current encoding is hi-light', + completer: function(filter){ + return completion(encodings, filter); + } + } +)); +vimperator.commands.add(new vimperator.Command(['listdetector','lsdet'], + function(arg){ + listCharset(arg, vimperator.options.autodetector, detectors); + },{ + usage: ['listdetector [expr]','lsdet [expr]'], + shortHelp: 'list all auto detectors', + help: 'current encoding is hi-light', + completer: function(filter){ + return completion(detectors, filter); + } + } +)); + +})(); + +// vim: set fdm=marker sw=4 ts=4 et: diff --git a/ex_autocmd.js b/ex_autocmd.js new file mode 100644 index 0000000..e8a9661 --- /dev/null +++ b/ex_autocmd.js @@ -0,0 +1,17 @@ +// Vimperator plugin: 'Ex Autocmd' +// Last Change: 29-Feb-2008. Jan 2008 +// License: Creative Commons +// Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid +// +// extends autocmd for vimperator0.6.* +// Ex Events: +// TabSelect +// TabLeave + +var recentTab = null; +function tabSelect(e){ + vimperator.autocommands.trigger("TabSelect",gBrowser.selectedTab.linkedBrowser.contentWindow.location.href); + vimperator.autocommands.trigger("TabLeave",recentTab?recentTab:""); + recentTab = gBrowser.selectedTab.linkedBrowser.contentWindow.location.href; +} +gBrowser.tabContainer.addEventListener("TabSelect",tabSelect,false); diff --git a/googlesugest.js b/googlesugest.js new file mode 100644 index 0000000..f7e2643 --- /dev/null +++ b/googlesugest.js @@ -0,0 +1,29 @@ +// Vimperator plugin: 'Completion by Google Suggest' +// Last Change: 02-Mar-2008. Jan 2008 +// License: Creative Commons +// Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid +// +// search word completion using google suggest script for vimperator0.6.* + +vimperator.commands.addUserCommand(['google'],"Search web sites with google suggest", + function(arg){ + const endpoint = "http://www.google.co.jp/search?q="; + //vimperator.open(endpoint + encodeURIComponent(arg)); + vimperator.open(endpoint + encodeURIComponent(arg),vimperator.NEW_TAB); + }, + { + completer: function (filter) { + const endPoint = "http://suggestqueries.google.com/complete/search?output=firefox&client=firefox&hl=ja&qu=" + var xhr = new XMLHttpRequest(); + var completionList = []; + + xhr.open("GET",endPoint + encodeURIComponent(filter),false); + xhr.send(null); + var response = window.eval(xhr.responseText)[1]; + + for each (var r in response) + completionList.push([r,"Suggests"]); + return [0,completionList]; + } + } +); diff --git a/hatenabookmark_show.js b/hatenabookmark_show.js new file mode 100644 index 0000000..1211bd5 --- /dev/null +++ b/hatenabookmark_show.js @@ -0,0 +1,44 @@ +// Vimperator plugin: 'Show Hatena Bookmark Comments' +// Last Change: 02-Mar-2008. Jan 2008 +// License: Creative Commons +// Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid +// +// show hatena bookmark comments script for vimperator0.6.* + +(function(){ + function showComments(url){ + const endPoint = "http://b.hatena.ne.jp/entry/json/"; + var xhr = new XMLHttpRequest(); + var tagString,showString = "
"; + xhr.open("GET",endPoint + url,false); + xhr.send(null); + var response; + if(!(response = window.eval(xhr.responseText))){ + vimperator.echoerr("Does not exists!!");return; + } + var bookmarks = response["bookmarks"]; + showString += response["count"] + " users : " + response["title"] + "
"; + + for each (var bookmark in bookmarks){ + tagString = bookmark.tags.length ? "[" + bookmark.tags.join("][") + "]":""; + showString += "
" + bookmark.user + "
"; + showString += "
" + showString += tagString + (bookmark.tags.length > 0 && bookmark.comment ? "
":"") + bookmark.comment + "
"; + } + showString += "
"; + vimperator.commandline.echo(showString, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); + } + vimperator.commands.addUserCommand(["hbinfo"], "show hatena bookmark comments", + function(arg,special){ + var clipboard = readFromClipboard(); + if(special) + arg = window.content.document.getSelection() || clipboard; + showComments(arg?encodeURIComponent(arg):vimperator.buffer.URL); + },{ completer: vimperator.completion.url } + ); + vimperator.mappings.addUserMap([vimperator.modes.VISUAL], [",h"], "show hatena bookmark comments", + function(count){ + showComments(window.content.document.getSelection()); + },{ noremap: true } + ); +})(); diff --git a/ldrize_cooperation.js b/ldrize_cooperation.js new file mode 100644 index 0000000..be9cdec --- /dev/null +++ b/ldrize_cooperation.js @@ -0,0 +1,187 @@ +// Vimperator plugin: 'Cooperation LDRize Mappings' +// Version: 0.09 +// Last Change: 16-Mar-2008. Jan 2008 +// License: Creative Commons +// Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid +// +// Cooperation LDRize Mappings for vimperator0.6.* +(function(){ + var scrollCount = 3; + var programInfo = [ + //{ + // pattern: "http://www.nicovideo.jp/*", + // program: "c:\\usr\\SmileDownloader\\SmileDownloader.exe", + // wait: 5000 + //}, + //{ + // program: "C:\\usr\\irvine\\irvine.exe", + //}, + ]; + + programInfo.forEach(function(x){ + x.include = typeof x.include != "undefined" + ? typeof x.include == "string" ? new RegExp(x.include) : new RegExp(x.include[0],x.include[1]) + : typeof x.pattern != "undefined" + ? new RegExp("^"+String(x.pattern).replace(/\s+/g,"").replace(/[\\^$.+?|(){}\[\]]/g,"\\$&") + .replace(/(?=\*)/g,".")+"$","i") + : /(?:)/; + delete x.pattern; + }); + + var LDRize = {getSiteinfo: function(){return undefined;}}; + var Minibuffer; + + var isEnable = true; + + function addAfter(target,name,after) { + var original = target[name]; + target[name] = function() { + var tmp = original.apply(target,arguments); + after.apply(target,arguments); + return tmp; + }; + } + + var GreasemonkeyService = Cc["@greasemonkey.mozdev.org/greasemonkey-service;1"].getService().wrappedJSObject; + addAfter(GreasemonkeyService,'evalInSandbox',function(code,codebase,sandbox){ + if(sandbox.window.LDRize != undefined && sandbox.window.Minibuffer != undefined){ + sandbox.window.addEventListener("focus",function(){ + vimperator.plugins.LDRize = LDRize = window.eval("self",sandbox.LDRize.getSiteinfo); + vimperator.plugins.Minibuffer = Minibuffer = window.eval("command",sandbox.Minibuffer.addCommand); + },false); + sandbox.window.addEventListener("load",function(){ + if(window.content.wrappedJSObject == sandbox.unsafeWindow){ + vimperator.plugins.LDRize = LDRize = window.eval("self",sandbox.LDRize.getSiteinfo); + vimperator.plugins.Minibuffer = Minibuffer = window.eval("command",sandbox.Minibuffer.addCommand); + } + },false); + } + }); + + var feedPanel = document.createElement('statusbarpanel'); + const DISABLE_ICON = 'data:image/png;base64,' + +'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAA7E' + +'AAAOxAGVKw4bAAACL0lEQVR4nF2Sy0tUYRjGf9+Z4/HMjJfjBUZEMM2MSDII' + +'REjSVtVecBFZi6Bdi4RW/SFBq2oR0R8gSaUJhVJIBkEEMZOWl5kuM+fqnPN9' + +'52sxQ4kPv837Pu+zel4xMjkz/3h5p87pbhyDw4o1mzUOkubYbvLo2kVx+4Pe' + +'rAKMdTGQ5YgiWK/8z+QT3yyVUTFAzaBXHQ0IONPKOxepAH65dUOGSB/pM9LC' + +'whjyy/sg4DB3TjGZbjVuVIihQhKfxGdzmzhhNBvGXhr7NDiRY+fr573ibmtC' + +'4pN4GNJDukiXusvbIuMnh9K9YujSYKKPl6vrZu+EI5EuyheG9JEe0qPusfSR' + +'4cGBbPA98og8LMlAPlor2ZEvVIT0kD6G9EhcEpfY58c+xbKYHBaRl4Ye432s' + +'rqyo7pnQo/qTxEW62gy2CKoAbheu4mGGm5eHgsViOTh+5Sp37+2X4gJQC0gU' + +'Otb0j2hhaCG06NfC0K22/radzs6uTM3ojY1SobDcdHNaCC2Mimn2YZmQggEd' + +'kPJ0UczfyOzVWHr1xnVmrS5I0R6pgTC1mXdoUwB2Jj5QFvDsBc8fTCkpL82l' + +'uW6rWWEPQBoL07JwCgAaywbgd8ynIrultTB3wWk73LtWdS3OXtd/fBwH2+Yg' + +'xM4R14kqrzMZzM5pO9dcNlQrl832wTSoGiEok84eOrK0ZGB0+shTJYpyFUv7' + +'In/s/LlbTyq+/ufZFlkTK4MhAJKUMCGs6x473rg/9xe9wS0xVA1n/AAAAABJ' + +'RU5ErkJggg=='; + const ENABLE_ICON = 'data:image/png;base64,' + +'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAAsT' + +'AAALEwEAmpwYAAACI0lEQVR4nGWSzU7yQBSGp84UKalDY0MkLsSdYWtCIok3' + +'4YKV7tx7MWy9A6/ABZDgHbhghdFqU9M0FpH57cyUcdFA8Pue3fl5T07Oe5zz' + +'8/PhcEgpbbfbtVoN7LBer9M01VpX4f7+/t3dnfP4+JimKQDg6OgIYwz+UpZl' + +'HMdbjbUWZVkmpQQAEEJc1wX/EYZhHMdlWQIAKKV7cgPG+PLy8uPjg/+l3+/7' + +'vl/1KKVQURRCCABAFEVa6yAIOOeO41Tjj4+PoyiK49h1XSkl53xPbOCcz+fz' + +'bre7WCzYhpOTk+l0GoYhhFAIIaXck1JuNc/Pz51OpyiKahkAAMb49fVVCKGU' + +'qgTw4uKCUqq1RggZY05PT8uyTJJEa312dvby8rJcLq21y+WSUiqlhN1uN89z' + +'xpgxJs9zQkiv1xuNRlmWXV9f39/ff39/53meZRmllBCCZrNZkiTWWowxIWQ6' + +'nV5dXRFCGGOfn59PT0+MMWut67pa6/V6jZrNpjHGWus4TqPRsNaORqPBYCCE' + +'GI/Hvu/7vm+trc4KAEC+71dGQggrdyaTyXA4NMbc3NxsvW82mwCAoihQrVY7' + +'PDzctVYIEUXR29tbo9GAEO6WpJTO7e0tIQRjXK/XhRCe5ymlsiyDEAZB4Hle' + +'lawEX19fqNVqVS/kOE6r1fI8DyHU6XT++ShjzM/Pz8HBAXx/f+/3+9X2WmvO' + +'uVKq3GCMUUoxxlarVb1ef3h4+AWNW50eXTIBjgAAAABJRU5ErkJggg=='; + feedPanel.setAttribute('id','ldrizecopperation-status'); + feedPanel.setAttribute('class','statusbarpanel-iconic'); + feedPanel.setAttribute('src',ENABLE_ICON); + feedPanel.addEventListener("click",function(e){ + switchLDRizeCooperation(isEnable ? false : true); + },false); + document.getElementById('status-bar').insertBefore(feedPanel,document.getElementById('security-button')); + + function switchLDRizeCooperation(value){ + isEnable = value; + feedPanel.setAttribute("src",value ? DISABLE_ICON : ENABLE_ICON); + } + function sendRawKeyEvent(keyCode,charCode){ + var evt = window.content.wrappedJSObject.document.createEvent("KeyEvents"); + evt.initKeyEvent("keypress",true,true,window.content.wrappedJSObject,false,false,false,false,keyCode,charCode); + window.content.wrappedJSObject.document.dispatchEvent(evt); + } + function isEnableLDRize(){ return isEnable && LDRize.getSiteinfo() != undefined; } + function getPinnedLinks(){ + var xpath = LDRize.getSiteinfo()['link']; + return LDRize.getPinnedItems().map(function(i){return i.XPath(xpath)}); + } + function downloadLinksByProgram(links){ + var count = 0; + links.forEach(function(link){ + for(let i=0;i", ""], + "Scroll document down", + function(){isEnableLDRize() ? sendRawKeyEvent(74,106):vimperator.buffer.scrollLines(scrollCount);} ,{}); + vimperator.mappings.addUserMap([vimperator.modes.NORMAL], ["k", "", ""], + "Scroll document up", + function(){isEnableLDRize() ? sendRawKeyEvent(75,107):vimperator.buffer.scrollLines(-scrollCount);} ,{}); + vimperator.mappings.addUserMap([vimperator.modes.NORMAL], ["o"], + "Open a message", + function(){isEnableLDRize() ? sendRawKeyEvent(79,111):vimperator.commandline.open(":","open ",vimperator.modes.EX);},{}); + vimperator.mappings.addUserMap([vimperator.modes.NORMAL], ["p"], + "Open (put) a URL based on the current clipboard contents in the current buffer", + function(){isEnableLDRize() ? sendRawKeyEvent(80,112):vimperator.open(readFromClipboard());} ,{}); + + vimperator.mappings.addUserMap([vimperator.modes.NORMAL], [",f"], + "Focus on search field by LDRize", + function(){LDRize.bindFocus();} ,{}); + + //Commands + vimperator.commands.addUserCommand(["pin"], "LDRize Pinned Links", + function(){ + var links = getPinnedLinks(); + var showString = links.length + " Items
"; + links.forEach(function(link){ + showString += link + "
"; + }); + vimperator.commandline.echo(showString, vimperator.commandline.HL_NORMAL, vimperator.commandline.FORCE_MULTILINE); + } ,{}); + vimperator.commands.addUserCommand(["mb","m","minibuffer"], "Execute Minibuffer", + function(arg){Minibuffer.execute(arg)}, + { + completer: function(filter){ + var completionList = []; + var command = vimperator.plugins.Minibuffer.command; + var alias = vimperator.plugins.Minibuffer.alias_getter(); + var tokens = filter.split("|").map(function(str){return str.replace(/\s+/g,"")}); + var exp = new RegExp("^" + tokens.pop()); + for(let i in command) if(exp.test(i))completionList.push([tokens.concat(i).join(" | "),"MinibufferCommand"]); + for(let i in alias) if(exp.test(i))completionList.push([i,"MinibufferAlias"]); + return [0,completionList]; + } + }); + vimperator.commands.addUserCommand(["pindownload"], "Download pinned links by any software", + function(arg){ downloadLinksByProgram(getPinnedLinks());} ,{}); + vimperator.commands.addUserCommand(["toggleldrizecooperation","toggleldrc"], "Toggle LDRize Cooperation", + function(arg){ switchLDRizeCooperation(!isEnable);}, {}); + + //Options + vimperator.options.add(['ldrc','ldrizecooperation'],'LDRize cooperation','boolean',isEnable, + { + setter: function(value){ + switchLDRizeCooperation(value); + }, + getter: function(){ + return isEnable; + } + } + ); +})(); diff --git a/twitter.js b/twitter.js new file mode 100644 index 0000000..c8db18d --- /dev/null +++ b/twitter.js @@ -0,0 +1,38 @@ +// Vimperator plugin: 'Update Twitter' +// Last Change: 17-Mar-2008. Jan 2008 +// License: Creative Commons +// Maintainer: Trapezoid - http://unsigned.g.hatena.ne.jp/Trapezoid +// +// update twitter status script for vimperator0.6.* + +(function(){ + var passwordManager = Cc["@mozilla.org/login-manager;1"].getService(Ci.nsILoginManager); + function sayTwitter(username,password,stat){ + var xhr = new XMLHttpRequest(); + xhr.open("POST","http://twitter.com/statuses/update.json",false,username,password); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.send("status=" + encodeURIComponent(stat)); + } + vimperator.commands.addUserCommand(['twitter'], 'Change twitter status', + function(arg,special){ + var password; + var username; + try { + var logins = passwordManager.findLogins({}, 'http://twitter.com', 'https://twitter.com', null); + if(logins.length) + [username, password] = [logins[0].username, logins[0].password]; + else + vimperator.echoerr("Twitter: account not found"); + } + catch(ex) { + } + + if(special){ + arg = arg.replace(/%URL%/g, vimperator.buffer.URL) + .replace(/%TITLE%/g ,vimperator.buffer.title); + } + + sayTwitter(username,password,arg); + },{ } + ); +})(); -- cgit v1.2.3