LivemarksLiberated
From Chickenfoot Script Repository
Originally, I was going to make LivemarksLiberated a full-fledged Firefox extension, but then I realized that it would be much quicker to release it as a Chickenfoot script. As Chickenfoot has only been verified to work up until Firefox 1.0.7, I'm not sure if this script will work with Firefox 1.5. Specifically, the code to attach the listener to the Live Bookmarks button may no longer be valid, as the XUL for Firefox tends to change from version to version.
To install this script in Chickenfoot, add the code below to an empty Chickenfoot editor, then hit the + button in the Triggers pane to add this script as a trigger. You can give the trigger any name you want (LivemarksLiberated is preferred), but make sure the value of the For Pages textbox is *.
(The details about how this script was created (http://www.bolinfest.com/changeblog/2005/12/05/livemarksliberated-the-first-chickenfoot-script-to-hit-the-repository/) are on my blog.)
// ==UserScript==
// @name LivemarksLiberated
// @description Put your feeds where you want them.
// @include *
// ==/UserScript==
/**
* LivemarksLiberated overrides the orange Live Bookmarks button,
* giving the user other options for what to do when adding a feed.
* Set your option by assigning a value to the variable "myMode",
* defined below.
*
* Here are the possible values for myMode:
*
* DEFAULT - do what Firefox normally does, add it to your live bookmarks
* CLIPBOARD - add the URL of the feed to the clipboard
* GOOGLE_READER - add the feed to Google Reader
* GOOGLE_HOMEPAGE - add the feed to your Google Personalized home page
* PROMPT - ask the user to select one of the above options when a feed is selected
*
* Michael Bolin, bolinfest@gmail.com, (c) 2005
*/
var DEFAULT = 1;
var CLIPBOARD = 2;
var GOOGLE_READER = 3;
var GOOGLE_HOMEPAGE = 4;
var PROMPT = 6;
/** set myMode to one of the options listed above; uses DEFAULT by default */
var myMode = DEFAULT;
/**
* addFeed() is called when the user clicks on one of the popup options
* from the Live Bookmarks button.
*
* @param mode is one of the values of myMode listed above
* @param url is the URL of the feed to add
*/
var defaultPromptValue = CLIPBOARD;
function addFeed(mode, url) {
if (mode == PROMPT) {
var newMode = window.prompt('What would you like to do with this feed?\n' +
'(1) add to my bookmarks folder\n' +
'(2) add the URL of the feed to the clipboard\n' +
'(3) add the feed to Google Reader\n' +
'(4) add the feed to Google Personalized Home\n',
defaultPromptValue,
'What would you like to do with this feed?'
);
try {
mode = parseInt(newMode);
if (isNan(mode)) throw new Error(mode);
} catch(e) {
window.alert('Sorry, ' + newMode + ' was not a valid response. ' +
'Nothing will be done with this feed.');
return;
}
}
switch(mode) {
case DEFAULT:
chromeWindow.livemarkAddMark(window._content, url);
break;
case CLIPBOARD:
copyToClipboard(url);
break;
case GOOGLE_READER:
case GOOGLE_HOMEPAGE:
url = window.encodeURIComponent(url);
with(fetch('http://fusion.google.com/add?feedurl=' + url)) {
if (mode == GOOGLE_READER) {
click('Add to Google reader link');
} else {
click('Add to Google homepage link');
}
}
break;
default:
throw new Error("unknown mode: " + mode);
}
}
/** adds the listener to the Live Bookmarks button */
var xuldoc = chromeWindow.document;
var button = xuldoc.getElementById('livemark-button');
var menupopup = button.childNodes[0];
menupopup.oncommand = function(event) {
addFeed(myMode,event.target.getAttribute('data'));
}
/** a utility function for copying a string to the clipboard */
function copyToClipboard(text) {
if (!text) return false;
text = text.toString();
var contractid = "@mozilla.org/widget/clipboardhelper;1";
var iid = Components.interfaces.nsIClipboardHelper;
var clipboard = Components.classes[contractid].getService(iid);
clipboard.copyString(text);
return true;
}
/*
* Note: This script will NOT work in Greasemonkey because it uses
* chromeWindow, click(), and fetch() which are part of the Chickenfoot API.
*/
