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.
// ==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?