Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Viddler link video
/* This is a poorly designed, hardcoded, workaround hack... and will easily break */
name: "watch viddler from",
author: { name: "Kris Walker", email: ""},
license: "GPL",
description: "Opens a browser tab, starting a Viddler video from the selected time stamp in the new tab.",
help: "Out of all the web pages on the planet, this command works for 10 of them."
+" But, if you dare, select a time code on the page, or enter one here on the command line.",
takes: {"time stamp": noun_arb_text},
preview: function( pblock, input ) {
pblock.innerHTML = "Out of all the web pages on the planet, this command works for 10 of them."
+" But, if you dare, (and this page contains the correctly embedded video) "
+"select a time code on the page, or enter one here on the command line.";
* TODO: Hack me!
* This is a basic lookup table.
* Lookup the URL and you get the corresponding URL.
* == The wiki page is where the user is located,
* == The viddler page is where the tagged video is located.
* Just manually stick another key/value pair in here to
* register a new video page on the wiki.
_URLDictionary: {
* Make a string into a timestamp (number of seconds)
_validateTimeStamp: function(aTimeStamp) {
// cover the basics first
if(typeof(aTimeStamp) != "string" || aTimeStamp.length < 1) {
displayMessage("Ubiquity needs you to select, or enter a timestamp to make this work.");
return false;
// split the string by the ":"
var s = aTimeStamp.split(":");
// if we get more that two parts, or less than 1, we return false
if(s.length != 2) {
displayMessage(aTimeStamp +" must have one ':' in it to work.");
return false;
// remove non numeric chars from each part of the string
// and set these strings as integers so javascript can do some math
var s1 = parseInt(s[0].replace(/\D/g, ""));
var s2 = parseInt(s[1].replace(/\D/g, ""));
// if we have nothing left, return false
if(s[0].length < 1 || s[1].length < 1) {
displayMessage(aTimeStamp +" needs to have some numbers in it to work.");
return false;
// multiply the first half by sixty
s1 = s1 * 60;
// add it to the second half
var r = s1 + s2;
// poof.. the number is a string again
return r.toString();
execute: function(input) {
// this just get the current document URL -- using a little magic
var url = CmdUtils.getDocument().documentURI;
// lookup our current URL in our manually created dictionary
var newURL = this._URLDictionary[url];
if(typeof(newURL) == "undefined") {
displayMessage("This page is not recognized as holding a viddler video: "
+"Hack this command to make it work!");
return true;
// what did the user select... mmmm.. we hope it was a video timecode
var timestamp = CmdUtils.getSelection();
// We clean up the input for backward compatibility issues regarding
// command names that did not accept spaces in them -- 2009.01.06
var inp = input.text.replace(/viddler from/, "");
// if our user did not select a timestamp... maybe they entered one in?
// so, a user entered timstamp will override a selection
if(inp.length > 1)
timestamp = input.text;
// before we move on...
timestamp = this._validateTimeStamp(timestamp);
return true;
// append the timestamp in seconds to the end of the viddler URL
newURL += timestamp +"/";
// load, or focus, the new URL
return true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.