Advertisement
SPennLUE

ETI Image Width

Jan 8th, 2013
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           ETI Image Width
  3. // @namespace      pendevin
  4. // @description    Allows you to set a maximum width for an image so it doesn't stretch your page
  5. // @include        http://endoftheinter.net/inboxthread.php*
  6. // @include        http://links.endoftheinter.net/linkme.php*
  7. // @include        http://boards.endoftheinter.net/showmessages.php*
  8. // @include        http://archives.endoftheinter.net/showmessages.php*
  9. // @include        https://endoftheinter.net/inboxthread.php*
  10. // @include        https://links.endoftheinter.net/linkme.php*
  11. // @include        https://boards.endoftheinter.net/showmessages.php*
  12. // @include        https://archives.endoftheinter.net/showmessages.php*
  13. // ==/UserScript==
  14.  
  15. //BEGIN USER DEFINED VALUES
  16.  
  17. //This value is the desired maximum width
  18. const Width=1170;
  19.  
  20. //END USER DEFINED VALUES
  21.  
  22. function livelinks(func){
  23.     document.addEventListener(
  24.         'DOMNodeInserted',
  25.         function(e){if(e.target.firstChild&&e.target.firstChild.className=='message-container')func(e.target.firstChild);},
  26.         false
  27.     );
  28.     func(document);
  29. }
  30.  
  31. function getSmall(place){
  32.     var images=place.getElementsByClassName('img-placeholder');
  33.     var css='';
  34.  
  35.     for(var i=0;i<images.length;i++){
  36.         var imgWidth=parseInt(images[i].style.width.slice(0,-2));
  37.         if(imgWidth>Width){
  38.             var imgHeight=parseInt(images[i].style.height.slice(0,-2));
  39.             var ratio=imgHeight/imgWidth;
  40.             css+='\n\
  41.                 .message #'+images[i].id+', .message #'+images[i].id+' > img{\n\
  42.                     max-width:'+Width+'px;\n\
  43.                     max-height:'+parseInt(Width*ratio)+'px;\n\
  44.                 }';
  45.         }
  46.     }
  47.  
  48.     GM_addStyle(css);
  49. }
  50.  
  51. livelinks(getSmall);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement