public
Last active

Viddler link video

  • Download Gist
gistfile1.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
/* This is a poorly designed, hardcoded, workaround hack... and will easily break */
CmdUtils.CreateCommand({
name: "watch viddler from",
author: { name: "Kris Walker", email: "kixxauth@gmail.com"},
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 wiki.mozilla.org/labs URL and you get the corresponding viddler.com 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: {
 
"https://wiki.mozilla.org/Labs/Ubiquity/Usability/Usability_Testing/Fall_08_1.2_Tests/Tester_11":
"http://www.viddler.com/explore/indolering/videos/4/",
 
"https://wiki.mozilla.org/Labs/Ubiquity/Usability/Usability_Testing/Fall_08_1.2_Tests/Tester_09":
"http://www.viddler.com/explore/indolering/videos/15/",
 
"https://wiki.mozilla.org/Labs/Ubiquity/Usability/Usability_Testing/Fall_08_1.2_Tests/Tester_08":
"http://www.viddler.com/explore/indolering/videos/8/",
 
"https://wiki.mozilla.org/Labs/Ubiquity/Usability/Usability_Testing/Fall_08_1.2_Tests/Tester_07":
"http://www.viddler.com/explore/indolering/videos/17/",
 
"https://wiki.mozilla.org/Labs/Ubiquity/Usability/Usability_Testing/Fall_08_1.2_Tests/Tester_06":
"http://www.viddler.com/explore/indolering/videos/10/",
 
"https://wiki.mozilla.org/Labs/Ubiquity/Usability/Usability_Testing/Fall_08_1.2_Tests/Tester_05":
"http://www.viddler.com/explore/indolering/videos/18/"
},
 
/**
* Make a string into a timestamp (number of seconds)
*/
_validateTimeStamp: function(aTimeStamp) {
CmdUtils.log(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);
if(!timestamp)
return true;
 
// append the timestamp in seconds to the end of the viddler URL
newURL += timestamp +"/";
 
// load, or focus, the new URL
Utils.focusUrlInBrowser(newURL);
return true;
}
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.