Created
August 5, 2015 13:20
-
-
Save phts/42c76861833b2f22131c to your computer and use it in GitHub Desktop.
Bookmarklet for adding youtube video links under tut.by's players
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){ | |
"use strict"; | |
var $objects = $("object[type='application/x-shockwave-flash']"); | |
$.each($objects, function(index, object) { | |
var $object = $(object); | |
var flashvars = $("param[name='flashvars']", $object).attr("value"); | |
var pairs = flashvars.split("&"); | |
for (var pair of pairs) { | |
var items = pair.split("="); | |
if (items[0] === "id") { | |
var youtubeUrl = items.slice(1).join("="); | |
break; | |
} | |
} | |
if (youtubeUrl) { | |
$("<br><a target='_blank' href='"+youtubeUrl+"'>Open YouTube video</a>").insertAfter($object); | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment