MediaWiki:Common.js
Appearance
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */ // All ads setup $( function () { $('head').append('<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8332774039939178" crossorigin="anonymous"></script>'); // Define the HTML for your ad slot. // This will render the AdManager slot defined in MediaWiki:AdManager-top // The <ad slot="top" /> is a parser function processed by MediaWiki on the server, // but since we're injecting via JS, we're essentially telling the browser // to render whatever HTML is stored in MediaWiki:AdManager-top. // So, make sure MediaWiki:AdManager-top contains the *actual* ad code (HTML/JS). var adHtml = '<div class="my-ad-container" style="margin: 10px auto; text-align: center;">' + '<ad slot="top" />' + // This will be processed by MediaWiki's parser '</div>'; // Find the main content area and prepend the ad HTML // The ID for the main content area is typically 'bodyContent' in Vector 2022 var bodyContent = $( '#bodyContent' ); if ( bodyContent.length ) { bodyContent.prepend( adHtml ); } // You can add other slots similarly: var bottomAdHtml = '<div class="my-ad-container" style="margin-top: 20px; text-align: center;"><ad slot="bottom" /></div>'; if ( bodyContent.length ) { bodyContent.append( bottomAdHtml ); } } );