Skip to content

Instantly share code, notes, and snippets.

@Ivanca
Created March 14, 2013 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ivanca/5163352 to your computer and use it in GitHub Desktop.
Save Ivanca/5163352 to your computer and use it in GitHub Desktop.
Better control for Amara.org subtitle's editing (youtube subtitles creator and manager).
// ==UserScript==
// @name Amara Plus
// @namespace http://rapedinheaven.com
// @version 0.1
// @description enter something useful
// @match http://www.amara.org/es/onsite_widget/*
// @copyright 2012+, You
// ==/UserScript==
var getByClass = function (sel, parent) {
parent = parent || document;
if (document.querySelector)
return parent.querySelector("." + sel);
var all = parent.getElementsByTagName("*");
var reSel = new RegExp("\\b" + sel + "\\b");
for (var i = 0; i < all.length; i++) {
if (reSel.test(all[i].className)) {
return all[i];
}
}
return null;
};
// Click subtitle to go there
document.body.addEventListener("click", function (e) {
var ele = e.srcElement || e.toElement || e.target;
if (/\bunisubs-title\b/.test(ele.className)) {
var timeEle = getByClass("unisubs-timestamp-time-fixed", ele.parentNode);
var time = timeEle.innerHTML;
var parts = time.split(":");
if (parts.length > 1) {
time = parts[0] * 60 + Number(parts[1]);
}
var player = document.getElementsByTagName("object")[0];
player.seekTo(time);
}
}, false);
// Ctrl + Enter = Play/Pause video
document.body.addEventListener("keyup", function (e) {
if (e.ctrlKey && e.keyCode === 13) {
getByClass("unisubs-playPause").click();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment