Skip to content

Instantly share code, notes, and snippets.

@attilapiros
Forked from attilapiros/gist:8181870
Last active January 1, 2016 18:09
Show Gist options
  • Save attilapiros/8181913 to your computer and use it in GitHub Desktop.
Save attilapiros/8181913 to your computer and use it in GitHub Desktop.
JQuery based bookmarklet solution to collect youtube links (not working when CSP denies acces to ajax.googleapis.com).
(function(){
// the minimum version of jQuery we want
var v = "1.3.2";
// check prior inclusion and version
if (window.jQuery === undefined || window.jQuery.fn.jquery < v) {
var done = false;
var script = document.createElement("script");
script.src = "https://ajax.googleapis.com/ajax/libs/jquery/" + v + "/jquery.min.js";
script.onload = script.onreadystatechange = function(){
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
initMyBookmarklet();
}
};
document.getElementsByTagName("head")[0].appendChild(script);
} else {
initMyBookmarklet();
}
function initMyBookmarklet() {
(window.myBookmarklet = function() {
var createTextLinks = function(arrayOfAnchors) {
var text = '<ul>';
$(arrayOfAnchors).each(function(i) { text = text + '\n <li><a href=\"' + $(this).attr('href') + '\">' + $(this).html() + '</a>'; });
text = text + '\n</ul>';
return text;
};
var filterForHrefFactory = function(pattern) {
return function(anchor) {
return $(anchor).attr('href').toLowerCase().indexOf(pattern) != -1;
}
};
alert(createTextLinks($.grep($('a'), filterForHrefFactory('youtube'))));
})();
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment