Hello again! ;)

The root problem is that this site using load time booster technics (parts
of the site loads separate) that triggers the scripts to run many times.
The very first attempt to shrink the pics had that problem as we used
percentage to shrink, but at times when the picture is more or less fine in
size but exceeds the 200px limit it will become 80% of its parent element,
but it was smaller...so it will be pumped up. :)

Now that we know this, you can understand that the modified script that was
provided is working perfectly, but runs as many times as the site finishes
to load its parts. (5-8 times or more)
Each time the script checks the pictures if they are bigger than
200px...and yes the shrinked pictures are smaller by 80% than the original
size but still larger than 200px, so they will be shrinked again and again,
until they become smaller than 200px or no more script runs are ahead. ;)

This time i could think of 2 solutions:

1, define the absolute maximum width of a picture that you want to see on
that page, and shrink those to that max size. Regarding the relative height
too (set it to auto).
2, mark the already shrinked nodes for the script to recognise them.

I prefer the first one because we don't want to interfere other scripts by
altering the node with custom attributes. ;)


// ==UserScript==
// @name            ModGHacks
// @namespace       nsModGHacks
// @description     Modify ghacks.net
// @include         http://www.ghacks.net/*
// @version         1.0.0
// @grant           GM_addStyle
// @require         http://code.jquery.com/jquery-latest.js
// ==/UserScript==

document.addEventListener("load",

  function (){
    var imgNodes = document.getElementsByTagName("img"),
        imgNode,
        i = imgNodes.length,
        imgWidth,
        maxWidth = 640;    // modify this to your own max size ;)

    for (;i;) {
      imgNode = imgNodes[--i];

      imgWidth = imgNode.clientWidth;
      imgHeight = imgNode.clientHeight;
      if (imgWidth > maxWidth) {
        imgNode.style.maxWidth = maxWidth + "px";
        imgNode.style.height = "auto";
        console.log('Image with client width: %dpx modified to %dpx.',
imgWidth, maxWidth);
      }
    }
  }, true
);

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to