Decode and Reload Cached Images Button

Add a button beside each <img> to decode and reload its URL by removing a prefix and decoding URI component

As of 10.11.2025. See апошняя версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Decode and Reload Cached Images Button
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license      MIT
// @author       codr
// @description  Add a button beside each <img> to decode and reload its URL by removing a prefix and decoding URI component
// @match        https://gazellegames.net/forums.php*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    const urlParams = new URLSearchParams(window.location.search);
    if (!(urlParams.get('action') === 'viewthread' && urlParams.has('threadid'))) {
        return; // Exit if not matching the desired page
    }

    // The prefix to remove from the image src before decoding
    const prefix = "https://gazellegames.net/image.php?i=";

    // Select all <img> elements inside <td class="body">
    const images = document.querySelectorAll('td.body img');

    images.forEach(img => {
        // Only add button if img.src starts with the prefix
        if (!img.src.startsWith(prefix)) return;

        // Create a button element
        const btn = document.createElement('button');
        btn.textContent = 'Decode & Reload';
        btn.style.marginLeft = '6px';
        btn.style.cursor = 'pointer';

        btn.addEventListener('click', () => {
            let src = img.src;

            // Remove the prefix
            let encodedPart = src.substring(prefix.length);

            // Remove trailing "&c=1" if it exists
            if (encodedPart.endsWith('&c=1')) {
                encodedPart = encodedPart.slice(0, -4);
            }

            // Decode the URI component
            let decodedUrl;
            try {
                decodedUrl = decodeURIComponent(encodedPart);
            } catch(e) {
                console.log('Failed to decode URL');
                return;
            }

            // Set the image src to the decoded URL to reload it
            img.src = decodedUrl;
        });

        // Insert the button right after the image
        img.insertAdjacentElement('afterend', btn);
    });
})();