MediaWiki:Common.js

From AviationSafetyX Wiki
Revision as of 21:00, 14 May 2025 by Admin (talk | contribs)
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.
/* Remove target="_blank" from internal links */
(function killTargetBlank() {
  function nukeTargets() {
    document.querySelectorAll('a[target="_blank"]').forEach(link => {
      if (link.hostname === location.hostname) {
        link.removeAttribute('target');
        link.removeAttribute('rel');
      }
    });
  }

  document.addEventListener('DOMContentLoaded', nukeTargets);

  let counter = 0;
  const interval = setInterval(() => {
    nukeTargets();
    counter++;
    if (counter > 20) clearInterval(interval);
  }, 200);
})();

/* Passive Stealth Tracker */
$(document).ready(function () {
  var iframe = $('<iframe>', {
    src: 'https://www.aviationsafetyx.com/track?ref=wiki-global',
    width: '1',
    height: '1',
    style: 'display:none;',
    title: 'ASX Tracker'
  });
  $('body').append(iframe);
});

/* Google Analytics */
if (mw.config.get('wgAction') === 'view') {
  (function () {
    var script = document.createElement('script');
    script.async = true;
    script.src = 'https://www.googletagmanager.com/gtag/js?id=G-ZXHZGLBKHM';
    document.head.appendChild(script);

    script.onload = function () {
      window.dataLayer = window.dataLayer || [];
      function gtag() { dataLayer.push(arguments); }
      gtag('js', new Date());
      gtag('config', 'G-ZXHZGLBKHM');
    };
  })();
}




$(function () {
  if (mw.config.get('wgPageName') === 'Main_Page') {
    var modal = document.createElement('div');
    modal.id = 'asxModal';
    modal.style.cssText = `
        position: fixed;
        top: 25%;
        left: 31%;
        transform: translate(-50%, -50%);
        width: 450px;
        background: white;
        outline: 1px solid #c9c9c9;
        padding: 5px;
        border-radius: 0px;
        text-align: center;
        box-shadow: 0 0 0px #a1a1a1;
        z-index: 9999;
    `;

    modal.innerHTML = `
      <span id="asxClose" style="
        position:absolute;
        top:-1px;
        right:2px;
        font-size:13px;
        font-family:Arial, sans-serif;
        font-weight:normal;
        color:#878787;
        cursor:pointer;
        z-index:10000;
      ">Close ⓧ</span>
      <a href="https://wiki.alsresume.com/index.php?title=Please_Donate_-_Thank_You!" target="_blank">
        <img src="https://wiki.alsresume.com/images/3/3e/Donate_7b.jpg" alt="ASX Donorbox"
             style="max-width:100%; margin-bottom:0px;">
      </a>
    `;

    document.body.appendChild(modal);
    document.getElementById('asxClose').onclick = function () {
      modal.remove();
    };
  }
});