Block image >1mb

rfstrider

New Member
Joined
Aug 5, 2023
Messages
1
Reaction score
0
Achievement
Hello!
I'm new here, I'm trying to block large image because the 9hits application doesn't support external extensions.

This is the code I am trying to run:

Code:
Javascript:

function blockLargeImageURLs() {
  const maxImageSizeBytes = 2.5 * 1024 * 1024; // 2.5MB in bytes

  document.querySelectorAll('img').forEach(img => {
    const src = img.getAttribute('src');
    
    const fileExtensionRegex = /\.\w{3,4}$/;
    if (fileExtensionRegex.test(src)) {
      const fileExtension = src.match(fileExtensionRegex)[0].toLowerCase();
      const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.svg', '.tiff'];

      if (imageExtensions.includes(fileExtension)) {
        const estimatedSizeKB = 1000; // Adjust this value as needed

        if (estimatedSizeKB > maxImageSizeBytes / 1024) {
          img.style.display = 'none'; // Hide the image
          console.log(`Blocked image "${src}" because its estimated URL size exceeds 2.5MB.`);
        }
      }
    }
  });
}

blockLargeImageURLs();
But still the image are still loading when I tried it with Macro Editor,
Also please let me know if you have better idea..

TIA
 

opsfafsme

Well-Known Member
Rule The Universe
VIP
Joined
Jul 2, 2018
Messages
243
Reaction score
91
Website
OnlinePiercingShop.com
Achievement
If you do not have access to the html code of the site, it seems to me that what you want to do is impossible.
And your code just hides the images from displaying, not from downloading, which are two different things.
 

About us

  • Our community has been around for many years and pride ourselves on offering unbiased, critical discussion among people of all different backgrounds. We are working every day to make sure our community is one of the best.

Quick Navigation

User Menu