Skip to content

Instantly share code, notes, and snippets.

@Querela
Last active February 22, 2021 09:27
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 Querela/7896095 to your computer and use it in GitHub Desktop.
Save Querela/7896095 to your computer and use it in GitHub Desktop.
[js][ff][bookmark][youtube][yt] Firefox Bookmarklet Youtube Image
/*
// -> http://stackoverflow.com/questions/10113366/load-jquery-with-javascript-and-use-jquery
// -> http://muaz-khan.blogspot.de/2012/10/save-files-on-disk-using-javascript-or.html
// -> http://stackoverflow.com/questions/5404839/how-can-i-refresh-a-page-with-jquery/7609411#7609411
*/
(function() {
var getUriParamByName = function(name, href) {
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( href );
if( results == null ) {
return "";
} else {
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
};
var doYouTubeMojo = function() {
/*
window.alert("locationl.host=" + location.host);
window.alert("document.domain="+document.domain);
*/
if (location.host.indexOf("youtube.com")!=-1) {
$.ajax({
url: "",
context: document.body,
success: function(html,state){
/*$(this).html(html);*/
var page = $(html);
var imgUri = page.filter("meta[property='og:image']").prop("content");
/*= page.filter("meta[name='twitter:image']").attr("content");*/
var imgTitle = page.filter("meta[property='og:title']").prop("content");
var imgFilename = imgTitle + imgUri.substring(imgUri.lastIndexOf("."));
window.alert("imgUri:\n\t" + imgUri + "\n\nimgTitle:\n\t" + imgTitle + "\n\nimgFilename:\n\t" + imgFilename);
var save = document.createElement('a');
save.href = imgUri;
save.target = '_blank';
save.download = imgFilename || 'unknown';
var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, window, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
save.dispatchEvent(evt);
(window.URL || window.webkitURL).revokeObjectURL(save.href);
}
});
}
};
var loadJQuery = function() {
var startingTime = new Date().getTime();
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);
var checkReady = function(callback) {
if (window.jQuery) {
callback(jQuery);
} else {
window.setTimeout(function() { checkReady(callback); }, 20);
}
};
checkReady(function($) {
$(function() {
var endingTime = new Date().getTime();
var tookTime = endingTime - startingTime;
window.alert("jQuery is loaded, after " + tookTime + " milliseconds!");
doYouTubeMojo();
});
});
};
if (window.jQuery) {
window.alert("has jQuery already");
doYouTubeMojo();
} else {
window.alert("inject jQuery");
loadJQuery();
}
})();
javascript:(function(){var%20a=function(){if(location.host.indexOf("youtube.com")!=-1){$.ajax({url:"",context:document.body,success:function(c,h){var%20page=$(c);var%20b=page.filter("meta[property='og:image']").prop("content");var%20d=page.filter("meta[property='og:title']").prop("content");var%20e=d+b.substring(b.lastIndexOf("."));window.alert("imgUri:\n\t"+b+"\n\nimgTitle:\n\t"+d+"\n\nimgFilename:\n\t"+e);var%20f=document.createElement('a');f.href=b;f.target='_blank';f.download=e||'unknown';var%20g=document.createEvent('MouseEvents');g.initMouseEvent('click',true,true,window,1,0,0,0,0,false,false,false,false,0,null);f.dispatchEvent(g);(window.URL||window.webkitURL).revokeObjectURL(f.href)}})}};var%20l=function(){var%20i=new%20Date().getTime();var%20h=document.createElement("SCRIPT");h.src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';h.type='text/javah';document.getElementsByTagName("head")[0].appendChild(h);var%20m=function(callback){if(window.jQuery){callback(jQuery)}else{window.setTimeout(function(){m(callback)},20)}};m(function($){$(function(){var%20j=new%20Date().getTime();var%20k=j-i;window.alert("jQuery%20is%20loaded,%20after%20"+k+"%20milliseconds!");a()})})};if(window.jQuery){a()}else{l()}})();
@linehammer
Copy link

More on JavaScript/jQuery reload()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment