Resp... with minor repairs:

// ==UserScript==
// @name        ModGHacks
// @namespace   nsModGHacks
// @description Modify ghacks.net
// @include     http://www.ghacks.net/*
// @version     1.0.0
// @grant       none
// ==/UserScript==

document.addEventListener("load",

  function () {
    var imgNodes = document.getElementsByTagName("img"),
                   imgNode,
                   i = imgNodes.length,
                   imgWidth,
                   imgHeight,
                   newWidth = 0,
                   newHeight = 0;

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

      imgWidth = imgNode.clientWidth;
      imgHeight = imgNode.clientHeight;
      if (imgWidth >= 200){
        newWidth = Math.round(imgNode.clientWidth * 0.8);
        newHeight = Math.round(imgNode.clientHeight * 0.8);
        imgNode.style.width = newWidth + "px";
        imgNode.style.height = newHeight + "px";
        console.log("Image with client width / height: " + imgWidth + "px / 
" + imgHeight + "px modified to width / height: "
                    + imgNode.clientWidth + "px (" + 
Math.round(imgNode.clientWidth 
/ imgWidth * 100) + "%) "
                    + imgNode.clientHeight + "px (" + 
Math.round(imgNode.clientHeight 
/ imgHeight * 100) + "%)");
      }
    }
  }, true
);




Dne středa 6. května 2015 10:18:36 UTC+2 janekptacijarabaci napsal(a):
>
> The answer is:
> http://www.w3schools.com/jsref/prop_style_width.asp:
>
> Defines the width in % of the *parent element*
>>
>
> // ==UserScript==
> // @name        ModGHacks
> // @namespace   nsModGHacks
> // @description Modify ghacks.net
> // @include     http://www.ghacks.net/*
> // @version     1.0.0
> // @grant       none
> // ==/UserScript==
>
> document.addEventListener("load",
>
>   function () {
>     var imgNodes = document.getElementsByTagName("img"),
>                    imgNode,
>                    i = imgNodes.length,
>                    imgWidth;
>
>
>     var minWidth =  0;
>     var minHeight = 0;
>     for (;i;) {
>       imgNode = imgNodes[--i];
>
>       imgWidth = imgNode.clientWidth;
>       imgHeight = imgNode.clientHeight;
>       if (imgWidth >= 200){
>         newWidth = Math.round(imgNode.clientWidth * 0.8);
>         newHeight = Math.round(imgNode.clientHeight * 0.8);
>         imgNode.style.width = newWidth + "px";
>         imgNode.style.height = newHeight + "px";
>         console.log("Image with client width / height: " + imgWidth + "px 
> / " + imgHeight + "px modified to width / height: "
>                     + imgNode.clientWidth + "px (" + 
> Math.round(imgNode.clientWidth 
> / imgWidth * 100) + "%) "
>                     + imgNode.clientHeight + "px (" + 
> Math.round(imgNode.clientHeight 
> / imgHeight * 100) + "%)");
>       }
>     }
>   }, true
> );
>
>
>
>
>
> Dne úterý 5. května 2015 13:29:45 UTC+2 Ben napsal(a):
>>
>> According to some recommendations I wrote a GM script to shrink all those 
>> images with a width greater than 200: 
>>
>> // ==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; 
>>
>>     for (;i;) { 
>>       imgNode = imgNodes[--i]; 
>>
>>       imgWidth = imgNode.clientWidth; 
>>       if (imgWidth >= 200){ 
>>         imgNode.style.width = "80%"; 
>>         imgNode.style.height = "80%"; 
>>         console.log('Image with client width: ' + imgWidth + 'px modified 
>> to 80%'); 
>>       } 
>>     } 
>>   }, true 
>> ); 
>>
>>
>> So when I install the script above and apply it to the following page 
>> then the first image is shrinked as intended but the second is enlarged 
>> !!!!! (see 
>> snapshot) 
>>
>>
>> http://www.ghacks.net/2015/05/04/look-up-security-information-about-a-domain-or-ip-with-targetanalyser/
>>  
>>
>> Why? 
>>
>> The more elaborated code is due to the fact that img could have or NOT a 
>> "width" attribute. 
>> The shrinking should be applied to ALL images. 
>>
>> Ben 
>>
>>

-- 
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