Sunday, October 26, 2008

url incrementer firefox extension

So I go watch stuff at Viikii.net and noticed that I kept on having to go back a page, click on the next part of the episode and do it all over again. So then I thought, since the video id seems to increase by 1 for each part (for the most part, not always the case), why don't I create a Firefox extension that will do this for me? This way, it'll save me from clicking back and remembering which part I just saw (since I have a very very short term memory).

Here's some links I used for my development:
  • http://kb.mozillazine.org/Getting_started_with_extension_development
  • https://developer.mozilla.org/en/Building_an_Extension
  • http://ted.mielczarek.org/code/mozilla/extensionwiz/
  • https://developer.mozilla.org/en/Working_with_windows_in_chrome_code#Accessing_content_documents
  • http://www.viikii.net/videos/watch/2061
  • http://www.viikii.net/viewer/viikiiplayer2.swf?video_id=994
  • https://developer.mozilla.org/En/DOM/Window

I would recommend starting off with the extensionwiz link to create the stubs for you, then modify the icon.png and overlay.js to suit your needs. Took me about 1.5 days to learn it and get it up and running.

By the way, you put the link file in the profile folder that looks something like (Linux):
~/.mozilla/firefox/17jmqswm.default/extensions

Tried to upload the file, no luck and I'm too lazy to put it elsewhere :(

but here's the code

var newURL = content.document.URL;
var separator = "=";
var urlArray = newURL.split(separator);
var isFirstURL = (urlArray.length == 2) ? true : false;
var vidId = urlArray[urlArray.length-1];
var isFound = /^-?\d+$/.test(vidId);
if (isFound) {
++vidId;

// build the new URL, case 2
newURL = "";
for (var i = 0; i <>
newURL += urlArray[i] + separator;
}
newURL += vidId;
//promptService.alert(window, this.strings.getString("errorTitle"),"url="+newURL);

var strWindowFeatures = "toolbar=yes,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes,fullscreen=yes";
var windowObjectReference = window.open(newURL, "Viikii.net " + vidId, strWindowFeatures);
window.close();
} else {
promptService.alert(window, this.strings.getString("errorTitle"),
this.strings.getString("errorMessage") +
" '" + newURL + "' ");
}

No comments: