From e4630f444b7f0f4918cda2ac3087fb7c8d3ec42d Mon Sep 17 00:00:00 2001 From: Egon Hyszczak Date: Tue, 5 Oct 2010 23:44:55 +0000 Subject: [PATCH 1/6] Private bookmarks and post to twitter functionality. Changed README to reflect correct plugin (not "plugins") location. --- plugins/delicious.js | 52 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/plugins/delicious.js b/plugins/delicious.js index aab3ba0..7fc8f07 100644 --- a/plugins/delicious.js +++ b/plugins/delicious.js @@ -4,27 +4,69 @@ // Maintainer: Travis Jeffery // Usage: Use :delicious "description in quotes (optional)" command // Usage: if successfully posted you will see "done" echoed +// Modified by: Egon Hyszczak Added private bookmarks (pvt) and Twitter functionality (for:@twitter) -commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious", +commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious ('pvt': privacy, 'for:@twitter': Twitter)", function(args) { + var title = buffer.title; var url = "https://api.del.icio.us/v1/posts/add?"; url += "&url=" + encodeURIComponent(buffer.URL); - url += "&description=" + encodeURIComponent(buffer.title); + url += "&description=" + encodeURIComponent(title); + var tags; + var statusString = ''; + var re = new RegExp(/"([^"]+)"/); var ext = args.string.match(re); if (ext) { url += "&extended=" + encodeURIComponent(ext[1]); - url += "&tags=" + encodeURIComponent(args.string.substr(ext[0].length)); + //url += "&tags=" + encodeURIComponent(args.string.substr(ext[0].length)); + tags = args.string.substr(ext[0].length); + } else { + //url += "&tags=" + encodeURIComponent(args.string); + tags = args.string; + } + + //If the 'pvt' tag is used lock the bookmark from public access + if(tags.match("pvt")) { + //Replace pvt with empty string + tags = tags.replace("pvt", ""); + url += "&shared=no"; + statusString += '[PRIVATE] '; } else { - url += "&tags=" + encodeURIComponent(args.string); + url += "&shared=yes"; } + //Remove superflous whitespace + var whitespace = new RegExp(/\s{2,}/); + tags = tags.replace(whitespace, " "); + tags = tags.trim(); + + url += "&tags=" + encodeURIComponent(tags); + + //Twitter + if(tags.match("for:@twitter")) { + if(title.length >= 110) { + title = title.substr(0,110).trim(); + title += "..."; + url += "&share_msg=" + encodeURIComponent(title); + } else { + url += "&share_msg=" + encodeURIComponent(title); + } + url += "&recipients=" + encodeURIComponent("@twitter"); + } + + var xhr = new XMLHttpRequest(); xhr.open("POST", url, false); xhr.send(null); var xml = (new DOMParser()).parseFromString(xhr.responseText, "text/xml"); var status = xml.getElementsByTagName('result')[0].getAttribute('code'); - liberator.echo(status); + if(status == "done") { + statusString += "Added bookmark for " + buffer.URL + " [" + tags + "]"; + liberator.echo(statusString); + } else { + liberator.echo(status); + } } ); From f566e9be7a31d731650a77933eec2aa9b6f8bbe2 Mon Sep 17 00:00:00 2001 From: Egon Hyszczak Date: Tue, 5 Oct 2010 23:48:06 +0000 Subject: [PATCH 2/6] Correct location for plugins are in the "plugin" (singular) directory. --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index 2130936..dfd73c1 100644 --- a/README.markdown +++ b/README.markdown @@ -6,7 +6,7 @@ Firefox's [Vimperator](http://vimperator.org/trac/wiki/Vimperator) extension. ### Install -Copy delicious.js to your ~/.vimperator/plugins directory. +Copy delicious.js to your ~/.vimperator/plugin directory. ### Usage Use by going to some site you want to bookmark and do :delicious followed by From c0b6ea3e037a27ac4327d876eafb3f6276723622 Mon Sep 17 00:00:00 2001 From: Egon Hyszczak Date: Tue, 5 Oct 2010 23:54:26 +0000 Subject: [PATCH 3/6] Minor changes. Moved to correct (plugin) directory. --- plugin/delicious.js | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 plugin/delicious.js diff --git a/plugin/delicious.js b/plugin/delicious.js new file mode 100644 index 0000000..46b157d --- /dev/null +++ b/plugin/delicious.js @@ -0,0 +1,70 @@ +// Vimperator Plugin: 'Delicious' +// Last Change: 25-Aug-2009 +// License: MIT +// Maintainer: Travis Jeffery +// Usage: Use :delicious "description in quotes (optional)" command +// Usage: if successfully posted you will see "done" echoed +// Modified by: Egon Hyszczak +// Changes made: Added private bookmarks (pvt) and Twitter functionality (for:@twitter) + +commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious", + function(args) { + var title = buffer.title; + var url = "https://api.del.icio.us/v1/posts/add?"; + url += "&url=" + encodeURIComponent(buffer.URL); + url += "&description=" + encodeURIComponent(title); + var tags; + var statusString = ''; + + var re = new RegExp(/"([^"]+)"/); + var ext = args.string.match(re); + if (ext) { + url += "&extended=" + encodeURIComponent(ext[1]); + tags = args.string.substr(ext[0].length); + } else { + tags = args.string; + } + + //If the 'pvt' tag is used lock the bookmark from public access + if(tags.match("pvt")) { + //Replace pvt with empty string + tags = tags.replace("pvt", ""); + url += "&shared=no"; + statusString += '[PRIVATE] '; + } else { + url += "&shared=yes"; + } + + //Remove superflous whitespace + var whitespace = new RegExp(/\s{2,}/); + tags = tags.replace(whitespace, " "); + tags = tags.trim(); + + url += "&tags=" + encodeURIComponent(tags); + + //Twitter + if(tags.match("for:@twitter")) { + if(title.length >= 110) { + title = title.substr(0,110).trim(); + title += "..."; + url += "&share_msg=" + encodeURIComponent(title); + } else { + url += "&share_msg=" + encodeURIComponent(title); + } + url += "&recipients=" + encodeURIComponent("@twitter"); + } + + var xhr = new XMLHttpRequest(); + xhr.open("POST", url, false); + xhr.send(null); + var xml = (new DOMParser()).parseFromString(xhr.responseText, "text/xml"); + var status = xml.getElementsByTagName('result')[0].getAttribute('code'); + + if(status == "done") { + statusString += "Added bookmark for " + buffer.URL + " [" + tags + "]"; + liberator.echo(statusString); + } else { + liberator.echo(status); + } + } +); From 7d2e82bb9f8f821d83f1db44f93786c1e580847e Mon Sep 17 00:00:00 2001 From: Egon Hyszczak Date: Tue, 5 Oct 2010 23:58:44 +0000 Subject: [PATCH 4/6] Moved "plugins" to "plugin". --- plugins/delicious.js | 72 -------------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 plugins/delicious.js diff --git a/plugins/delicious.js b/plugins/delicious.js deleted file mode 100644 index 7fc8f07..0000000 --- a/plugins/delicious.js +++ /dev/null @@ -1,72 +0,0 @@ -// Vimperator Plugin: 'Delicious' -// Last Change: 25-Aug-2009 -// License: MIT -// Maintainer: Travis Jeffery -// Usage: Use :delicious "description in quotes (optional)" command -// Usage: if successfully posted you will see "done" echoed -// Modified by: Egon Hyszczak Added private bookmarks (pvt) and Twitter functionality (for:@twitter) - -commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious ('pvt': privacy, 'for:@twitter': Twitter)", - function(args) { - var title = buffer.title; - var url = "https://api.del.icio.us/v1/posts/add?"; - url += "&url=" + encodeURIComponent(buffer.URL); - url += "&description=" + encodeURIComponent(title); - var tags; - var statusString = ''; - - var re = new RegExp(/"([^"]+)"/); - var ext = args.string.match(re); - if (ext) { - url += "&extended=" + encodeURIComponent(ext[1]); - //url += "&tags=" + encodeURIComponent(args.string.substr(ext[0].length)); - tags = args.string.substr(ext[0].length); - } else { - //url += "&tags=" + encodeURIComponent(args.string); - tags = args.string; - } - - //If the 'pvt' tag is used lock the bookmark from public access - if(tags.match("pvt")) { - //Replace pvt with empty string - tags = tags.replace("pvt", ""); - url += "&shared=no"; - statusString += '[PRIVATE] '; - } else { - url += "&shared=yes"; - } - - //Remove superflous whitespace - var whitespace = new RegExp(/\s{2,}/); - tags = tags.replace(whitespace, " "); - tags = tags.trim(); - - url += "&tags=" + encodeURIComponent(tags); - - //Twitter - if(tags.match("for:@twitter")) { - if(title.length >= 110) { - title = title.substr(0,110).trim(); - title += "..."; - url += "&share_msg=" + encodeURIComponent(title); - } else { - url += "&share_msg=" + encodeURIComponent(title); - } - url += "&recipients=" + encodeURIComponent("@twitter"); - } - - - var xhr = new XMLHttpRequest(); - xhr.open("POST", url, false); - xhr.send(null); - var xml = (new DOMParser()).parseFromString(xhr.responseText, "text/xml"); - var status = xml.getElementsByTagName('result')[0].getAttribute('code'); - - if(status == "done") { - statusString += "Added bookmark for " + buffer.URL + " [" + tags + "]"; - liberator.echo(statusString); - } else { - liberator.echo(status); - } - } -); From 3aab3c70c3f5ab2046e2666e52e12abaeeea7458 Mon Sep 17 00:00:00 2001 From: Egon Hyszczak Date: Wed, 6 Oct 2010 16:17:33 +0000 Subject: [PATCH 5/6] Added extended message capability to twitter message title. --- plugin/delicious.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugin/delicious.js b/plugin/delicious.js index 46b157d..ae6405e 100644 --- a/plugin/delicious.js +++ b/plugin/delicious.js @@ -15,11 +15,13 @@ commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious", url += "&description=" + encodeURIComponent(title); var tags; var statusString = ''; + var extended; var re = new RegExp(/"([^"]+)"/); var ext = args.string.match(re); if (ext) { - url += "&extended=" + encodeURIComponent(ext[1]); + extended = encodedURIComponent(ext[1]); + url += "&extended=" + extended; tags = args.string.substr(ext[0].length); } else { tags = args.string; @@ -44,12 +46,17 @@ commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious", //Twitter if(tags.match("for:@twitter")) { - if(title.length >= 110) { - title = title.substr(0,110).trim(); - title += "..."; - url += "&share_msg=" + encodeURIComponent(title); + //Use extended message if given + if(ext) { + url += "&share_msg=" + extended; } else { - url += "&share_msg=" + encodeURIComponent(title); + if(title.length >= 110) { + title = title.substr(0,110).trim(); + title += "..."; + url += "&share_msg=" + encodeURIComponent(title); + } else { + url += "&share_msg=" + encodeURIComponent(title); + } } url += "&recipients=" + encodeURIComponent("@twitter"); } From c6d91325e53962b1c05ec7acd8428be40ea87747 Mon Sep 17 00:00:00 2001 From: Egon Hyszczak Date: Thu, 7 Oct 2010 18:37:26 +0000 Subject: [PATCH 6/6] Fixed spelling error in comment "superflous" now spelled correctly as "superfluous". --- plugin/delicious.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/delicious.js b/plugin/delicious.js index ae6405e..445cb9e 100644 --- a/plugin/delicious.js +++ b/plugin/delicious.js @@ -37,7 +37,7 @@ commands.addUserCommand(['delicious'], "Save page as a bookmark on Delicious", url += "&shared=yes"; } - //Remove superflous whitespace + //Remove superfluous whitespace var whitespace = new RegExp(/\s{2,}/); tags = tags.replace(whitespace, " "); tags = tags.trim();