MediaWiki:Common.js: Difference between revisions

From [STAGING] Destiny Wiki
Jump to navigation Jump to search
(Adding JS for file preloading fix)
 
(modifying JS for preload)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
document.addEventListener('DOMContentLoaded', function () {
const observer = new MutationObserver((mutations) => {
     // Select all videos embedded using [[File:...]] syntax
     mutations.forEach((mutation) => {
    const embeddedVideos = document.querySelectorAll('video');
        mutation.addedNodes.forEach((node) => {
    embeddedVideos.forEach(video => {
            if (node.tagName === 'VIDEO') {
        // Set preload attribute to "none"
                node.setAttribute('preload', 'none');
        video.setAttribute('preload', 'none');
            }
        });
     });
     });
});
});
// Start observing the document for changes
observer.observe(document.body, { childList: true, subtree: true });

Revision as of 20:58, 10 December 2024

/* Any JavaScript here will be loaded for all users on every page load. */
const observer = new MutationObserver((mutations) => {
    mutations.forEach((mutation) => {
        mutation.addedNodes.forEach((node) => {
            if (node.tagName === 'VIDEO') {
                node.setAttribute('preload', 'none');
            }
        });
    });
});

// Start observing the document for changes
observer.observe(document.body, { childList: true, subtree: true });