Try to change the code:
From:
document.addEventListener("load", function () {}, true);
To:
window.addEventListener("load", function () {});
// ==UserScript==
// @name ModGHacks
// @namespace nsModGHacks
// @description Modify ghacks.net
// @include http://www.ghacks.net/*
// @version 1.0.0
// @grant none
// ==/UserScript==
window.addEventListener("load",
function () {
var imgNodes = document.getElementsByTagName("img"),
imgNode,
i = imgNodes.length,
imgWidth = 0,
imgHeight = 0,
newWidth = 0,
newHeight = 0,
minWidth = 200,
newSize = 0.8;
for (;i;) {
imgNode = imgNodes[--i];
imgWidth = imgNode.width;
imgHeight = imgNode.height;
if (imgWidth >= minWidth) {
newWidth = Math.round(imgNode.width * newSize);
newHeight = Math.round(imgNode.height * newSize);
imgNode.style.width = newWidth + "px";
imgNode.style.height = newHeight + "px";
console.log("Image (href = \"" + imgNode.src + "\")\n"
+ "with client width / height: " + imgWidth + "px" + " / "
+ imgHeight + "px\n"
+ "modified to width / height: " + imgNode.clientWidth + "px
/ " + imgNode.clientHeight + "px"
+ " (" + Math.round(imgNode.clientWidth / imgWidth * 100)
+ "% / " + Math.round(imgNode.clientHeight / imgHeight * 100) + "%)"
);
}
}
}
);
Dne pátek 8. května 2015 10:44:47 UTC+2 Ben napsal(a):
>
> @ janekptacijarabaci:
>
> Thank you for your suggestion, but it does NOT work.
>
> As you can see at the attached snapshot the first image on my sample page
> is not shrinked by 80% but by a much higher rate.
> Furthermore it is strange that the original image width of 839 pixel is
> NOT displayed on the console.
> Where is it?
>
> Could you verify again?
>
> Thank you
> Ben
>
> On Wednesday, 6 May 2015 10:24:41 UTC+2, janekptacijarabaci wrote:
>>
>> 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.