"മീഡിയവിക്കി:Common.js" എന്ന താളിന്റെ പതിപ്പുകൾ തമ്മിലുള്ള വ്യത്യാസം
No edit summary |
No edit summary |
||
| വരി 3: | വരി 3: | ||
============================================================ */ | ============================================================ */ | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
var images = | function replaceOSMMarkers(root) { | ||
var images = root.querySelectorAll('img[src*="tile.openstreetmap.org/v4/marker/"]'); | |||
images.forEach(function (img) { | |||
) { | |||
img.src = img.src.replace( | img.src = img.src.replace( | ||
'https://tile.openstreetmap.org/v4/marker/', | 'https://tile.openstreetmap.org/v4/marker/', | ||
'https://maps.wikimedia.org/v4/marker/' | 'https://maps.wikimedia.org/v4/marker/' | ||
); | ); | ||
} | }); | ||
} | } | ||
// Initial pass | |||
replaceOSMMarkers(document); | |||
// Watch for dynamically added images | |||
var observer = new MutationObserver(function (mutations) { | |||
mutations.forEach(function (mutation) { | |||
mutation.addedNodes.forEach(function (node) { | |||
if (node.nodeType === 1) { | |||
replaceOSMMarkers(node); | |||
} | |||
}); | |||
}); | |||
}); | |||
observer.observe(document.body, { | |||
childList: true, | |||
subtree: true | |||
}); | |||
}); | }); | ||
/* ============================================================ | /* ============================================================ | ||