Author Topic: Programmers hate this one trick: Chatgpt  (Read 92 times)

Have you guys successfully got chatgpt to spit out working scripts? I got it to spit out a tampermonkey script that actually functions. It took a few tries but it functions. I can tell it's not great though since I had to ask it one step at a time to fix each issue.

The script just replaces broken images on a map with a new image.

Code: [Select]
// ==UserScript==
// @name         HearthWorld Thingwall Marker Fix (Zoom Safe)
// @namespace    https://map.hearthworld.com/
// @version      1.1
// @description  Replace the broken thingwall marker icon on the HearthWorld map (zoom-safe)
// @match        https://map.hearthworld.com/*
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function () {
    'use strict';

    const BROKEN_ICON_PATH = '/icons/thingwall.png';
    const REPLACEMENT_ICON = 'https://files.catbox.moe/wqb370.png';

    function fixThingwallMarker(img) {
        if (!img.classList.contains('leaflet-marker-icon')) return;

        const src = img.getAttribute('src');
        if (!src || !src.includes(BROKEN_ICON_PATH)) return;

        // Prevent infinite loops
        if (img.dataset.thingwallFixed === 'true') return;

        img.dataset.thingwallFixed = 'true';
        img.src = REPLACEMENT_ICON;
    }

    function watchMarker(img) {
        if (img.dataset.thingwallWatched) return;
        img.dataset.thingwallWatched = 'true';

        // Fix immediately (important for zoom rebuilds)
        fixThingwallMarker(img);

        // Fix if image fails to load
        img.addEventListener('error', () => {
            img.dataset.thingwallFixed = 'false';
            fixThingwallMarker(img);
        });

        // Fix if Leaflet resets the src during zoom
        const attrObserver = new MutationObserver(mutations => {
            for (const m of mutations) {
                if (m.attributeName === 'src') {
                    img.dataset.thingwallFixed = 'false';
                    fixThingwallMarker(img);
                }
            }
        });

        attrObserver.observe(img, {
            attributes: true,
            attributeFilter: ['src']
        });
    }

    // Handle existing markers
    document
        .querySelectorAll('img.leaflet-marker-icon')
        .forEach(watchMarker);

    // Watch for new markers added during pan/zoom
    const domObserver = new MutationObserver(mutations => {
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                if (node.nodeType !== 1) continue;

                if (node.tagName === 'IMG') {
                    watchMarker(node);
                } else {
                    node
                        .querySelectorAll?.('img.leaflet-marker-icon')
                        .forEach(watchMarker);
                }
            }
        }
    });

    domObserver.observe(document.body, {
        childList: true,
        subtree: true
    });
})();
Anybody know anything about programming? Does this happen to be an absolutely terrible way to do this? Have you guys got chatgpt to write a simple program for you?
« Last Edit: Yesterday at 02:59:38 AM by Soukuw »

plenty of times. ive created custom GPTs that build python and JSON scripts to help automate data entry at my company. i would never trust it to make a full fleshed program but its pretty damn good at organizing numbers and categorizing information

whether it’s the most optimized thing or not is a swing in the dark but forget it if it works it works

plenty of times. ive created custom GPTs that build python and JSON scripts to help automate data entry at my company. i would never trust it to make a full fleshed program but its pretty damn good at organizing numbers and categorizing information

whether it’s the most optimized thing or not is a swing in the dark but forget it if it works it works
Yeah it's a bit funky, maybe if it was the paid version it wouldn't be but it frequently seems to forget things in between prompts