aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrry2008-10-02 11:31:37 +0000
committerdrry2008-10-02 11:31:37 +0000
commit9c9d5755501e49649959a94843e7e2b9a3a717d8 (patch)
treece8b2bf8a161855c0e8d4194c4eab1d9c22960a1
parentdd2683c3815eb2c230d2b326e3ddecaa084d8686 (diff)
downloadvimperator-plugins-9c9d5755501e49649959a94843e7e2b9a3a717d8.tar.bz2
* 新しい API に変更しました。
* シャスデリ? * ほか。 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20515 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r--pukka.js70
1 files changed, 33 insertions, 37 deletions
diff --git a/pukka.js b/pukka.js
index 696af1d..90e5bf3 100644
--- a/pukka.js
+++ b/pukka.js
@@ -1,12 +1,12 @@
-/*
+/**
* ==VimperatorPlugin==
* @name Pukka
- * @description Add bookmark to del.icio.us with Pukka
- * @description-ja Pukkaを使用してdel.icio.usにブックマークする
+ * @description Add bookmark to Delicious with Pukka
+ * @description-ja Pukkaを使用してDeliciousにブックマークする
* @author otsune info@otsune.com
* @namespace http://www.otsune.com/
* @minVersion 0.6pre
- * @version 0.3
+ * @version 0.4
* ==/VimperatorPlugin==
*
* see also http://codesorcery.net/pukka/
@@ -19,42 +19,42 @@
* '[C-z]':
* Commands:
* 'pukka' or 'pu':
- * Post bookmark to del.icio.us with Pukka
+ * Post bookmark to Delicious with Pukka
* usage: :pu[kka] [http://example.com/]
* Options:
* not implemented
*/
-(function(){
- var useNormalizelink = liberator.globalVariables.pukka_normalizelink || true;
-liberator.commands.addUserCommand(['pukka','pu'], 'Post to Pukka bookmark',
-function(args){
- if (!liberator.buffer.title || !liberator.buffer.URL || liberator.buffer.URL=='about:blank'){
+(function() {
+var useNormalizelink = liberator.globalVariables.pukka_normalizelink || true;
+
+liberator.commands
+ .addUserCommand(['pukka', 'pu'], 'Post to Pukka bookmark', function(args) {
+ if (!liberator.buffer.title || !liberator.buffer.URL || liberator.buffer.URL == 'about:blank') {
return false;
}
var scheme = 'pukka:';
var title = encodeURIComponent(liberator.buffer.title);
var url = encodeURIComponent(liberator.buffer.URL);
var extend = encodeURIComponent(window.content.getSelection().toString() || '');
- if (args){
+ if (args) {
url = encodeURIComponent(args);
}
liberator.open(scheme + 'url=' + url + '&title=' + title + '&extended=' + extend);
-},{
- completer: function(filter){
+}, {
+ completer: function(filter) {
var complist = [];
complist.push([liberator.buffer.URL, 'Raw URL: ' + liberator.buffer.title]);
- if(useNormalizelink){
+ if (useNormalizelink) {
complist.push([getNormalizedPermalink(liberator.buffer.URL), 'Normalized URL: ' + liberator.buffer.title]);
}
// detect rel="bookmark"
var elem;
var relb = liberator.buffer.evaluateXPath(
-// '//*[@rel="bookmark"]',
- '//*[contains(concat(" ", normalize-space(@rel), " "), " bookmark ")]',
+ '//*[contains(concat(" ", normalize-space(@rel), " "), " bookmark ")]',
null, null, true);
while ((elem = relb.iterateNext()) !== null) {
complist.push([elem.toString(), '@rel="bookmark" URL: ' + elem]);
@@ -62,33 +62,29 @@ function(args){
return [0, complist];
}
-}
-);
+});
-liberator.mappings.addUserMap([liberator.modes.NORMAL],
-['<C-z>'], 'Post to Pukka',
-function() {
+liberator.mappings
+ .addUserMap([liberator.modes.NORMAL], ['<C-z>'], 'Post to Pukka', function() {
var urlarg = liberator.globalVariables.pukka_normalizelink ?
getNormalizedPermalink(liberator.buffer.URL) :
- liberator.buffer.URL ;
- liberator.commandline.open(
- ':',
- 'pukka ' + urlarg,
- liberator.modes.EX
- );
-},{
-}
-);
+ liberator.buffer.URL;
+ liberator.commandline
+ .open(':', 'pukka ' + urlarg, liberator.modes.EX);
+}, {});
-// copied from trapezoid's direct_hb.js
-function getNormalizedPermalink(url){
- var xhr = new XMLHttpRequest();
- xhr.open("GET","http://api.pathtraq.com/normalize_url?url=" + url,false);
+// copied from Trapezoid's direct_hb.js
+function getNormalizedPermalink(url) {
+ var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"]
+ .createInstance(Components.interfaces.nsIXMLHttpRequest);
+ xhr.open('GET', 'http://api.pathtraq.com/normalize_url2?api=json;url=' + encodeURIComponent(url), false);
xhr.send(null);
- if(xhr.status != 200){
- liberator.echoerr("Pathtraq: FAILED to normalize URL!!");
+ if (xhr.status != 200) {
+ liberator.echoerr('Pathtraq: FAILED to normalize URL!!');
return url;
}
- return xhr.responseText;
+ return window.eval('(' + xhr.responseText + ')');
+ //return xhr.responseText.substring(1, xhr.responseText.length - 1);
+ //api=xml;return xhr.responseXML.documentElement.getElementsByTagName('url').item(0).childNodes.item(0).nodeValue;
}
})();