MediaWiki:Gadget-interactiveMap.js

From Hello Kitty Island Adventure Wiki
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
mw.hook( 'wikipage.content' ).add( function ( $content ) {
    var rootElement = $content[ 0 ].querySelector( '#map' );
    if ( !rootElement ) {
        return;
    }

    var embedElement = rootElement.querySelector( ':scope > .map-embed-container' );

    var textElement = embedElement.querySelector( ':scope > p' );
    textElement.innerHTML = 'This interactive map is hosted on Genial.ly, an external site unaffiliated with wiki.gg. <a href="https://genial.ly/privacy/">Privacy policy.</a>';
    var consentButton = document.createElement( 'button' );
		consentButton.innerText = 'View the map';
    textElement.appendChild( consentButton );

    consentButton.addEventListener( 'click', function () {
        var iframe = document.createElement( 'iframe' );
        iframe.title = 'hkia interactive map';
        iframe.width = '1200px';
        iframe.height = '692px';
        iframe.src = 'https://view.genial.ly/6516eedbe0c3d80011bda917';
        iframe.setAttribute( 'frameborder', '0' );
        iframe.setAttribute( 'type', 'text/html' );
        iframe.setAttribute( 'allowfullscreen', 'true' );
        iframe.setAttribute( 'scrolling', 'yes' );
        iframe.setAttribute( 'allownetworking', 'all' );
        embedElement.innerText = '';
        embedElement.appendChild( iframe );
    } );
} );