Skip to content

Instantly share code, notes, and snippets.

@itsPG
Created January 3, 2014 19:00
Show Gist options
  • Save itsPG/8244180 to your computer and use it in GitHub Desktop.
Save itsPG/8244180 to your computer and use it in GitHub Desktop.
PG's auto img adjuster
// ==UserScript==
// @name PG's auto img adjuster
// @namespace http://itsPG.org
// @version 0.1
// @description
// @match http://*/*
// @copyright 2014, PG
// ==/UserScript==
PG_jQuery_loader = {};
PG_jQuery_loader.getScript = function(filename)
{
var script = document.createElement('script');
script.setAttribute("type","text/javascript");
script.setAttribute("src", filename);
document.getElementsByTagName("head")[0].appendChild(script);
}
PG_jQuery_loader.failed_times = 0;
PG_jQuery_loader.checker = function()
{
if (typeof(jQuery) == "undefined")
{
PG_jQuery_loader.failed_times++;
if (PG_jQuery_loader.failed_times >= 50)
{
console.log("Failed to load jQuery Lib.");
}
else
{
setTimeout("PG_jQuery_loader.checker()", 100);
}
}
else
{
console.log("PG_jQuery_loader loaded jQuery after", PG_jQuery_loader.failed_times, "try/tries.");
PG_jQuery_loader.main();
}
}
PG_jQuery_loader.main = function()
{
PG_adjust_img_size = function()
{
jQuery("img").each(function()
{
if (jQuery(this).width() > innerWidth-50)
{
jQuery(this).width(innerWidth-50);
}
});
setTimeout("PG_adjust_img_size()", 1000);
}
PG_adjust_img_size();
}
PG_jQuery_loader.go = function()
{
PG_jQuery_loader.getScript("//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js");
PG_jQuery_loader.checker();
}
console.log(PG_jQuery_loader);
PG_jQuery_loader.go();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment