MediaWiki:Common.js: Unterschied zwischen den Versionen

Aus Rettungsdienst-Wiki
Zur Navigation springen Zur Suche springen
Markierung: Manuelle Zurücksetzung
Zeile 169: Zeile 169:
     console.log('[ad-box] testweise fixed positioniert');
     console.log('[ad-box] testweise fixed positioniert');
     */
     */
  });
})();
/* global mw, $ */
(function () {
  'use strict';
  $.when($.ready).then(function () {
    // Funktion, um festzustellen, ob Adblocker aktiv ist
    function detectAdblocker(callback) {
      var bait = document.createElement('div');
      bait.className = 'adsbox ad-banner ad-unit text-ad'; // typische Adblocker-Keywords
      bait.style.cssText = 'height:1px; width:1px; position:absolute; left:-9999px;';
      document.body.appendChild(bait);
      window.setTimeout(function () {
        var blocked = !bait.offsetHeight || !bait.clientHeight;
        document.body.removeChild(bait);
        callback(blocked);
      }, 300);
    }
    function showAdblockNotice() {
      if (document.getElementById('adblock-hinweis')) return;
      var div = document.createElement('div');
      div.id = 'adblock-hinweis';
      div.innerHTML =
        '<button id="adblock-close">×</button>' +
        '<strong>Hinweis:</strong> Wir finanzieren dieses Wiki durch Affiliate-Links und freiwillige Unterstützung. ' +
        'Bitte deaktiviere deinen Adblocker für <b>' + window.location.hostname + '</b>, um uns zu unterstützen. ❤️';
      document.body.appendChild(div);
      div.style.display = 'block';
      document.getElementById('adblock-close').onclick = function () {
        div.remove();
      };
    }
    // Nur zeigen, wenn Adblocker erkannt wird
    detectAdblocker(function (isBlocked) {
      if (isBlocked) {
        // Optional: Nur einmal pro Nutzer (mit LocalStorage)
        if (!localStorage.getItem('adblock_notice_shown')) {
          showAdblockNotice();
          localStorage.setItem('adblock_notice_shown', 'yes');
        }
      }
    });
   });
   });
})();
})();

Version vom 7. November 2025, 22:09 Uhr

/* global mw, $ */
(function () {
  'use strict';

  $.when( mw.loader.using( [ 'mediawiki.api', 'mediawiki.util' ] ), $.ready ).then( function () {

    // 1) Referenz-Portlet finden (Werkzeuge = p-tb). Daran hängen wir unseren Block direkt DARUNTER an.
    var tools = document.getElementById('p-tb') || document.getElementById('p-navigation');
    if ( !tools ) {
      console.warn('[NewPages] Referenz-Portlet nicht gefunden.');
      return;
    }

    // 2) Eigenen Portlet-Block erstellen – Klassen/Struktur von bestehendem Portlet ableiten
    var block = document.createElement('div');
    block.id = 'p-newpages';
    // Klassen vom Werkzeuge-Portlet übernehmen (wirkt in Timeless/Vector/MonoBook sauber)
    block.className = tools.className || 'mw-portlet';

    // passende Überschrift (h3 oder h2 – je nach Skin) ermitteln
    var headingTag = (tools.querySelector('h3,h2') || { tagName: 'H3' }).tagName;
    var heading = document.createElement(headingTag);
    heading.textContent = 'Neueste Beiträge';

    // Body + UL wie bei anderen Portlets
    var body = document.createElement('div');
    body.className = 'body';

    var list = document.createElement('ul');

    body.appendChild(list);
    block.appendChild(heading);
    block.appendChild(body);

    // Block direkt UNTERHALB von "Werkzeuge" einfügen
    if (tools.insertAdjacentElement) {
      tools.insertAdjacentElement('afterend', block);
    } else if (tools.parentNode) {
      tools.parentNode.insertBefore(block, tools.nextSibling);
    }

    // 3) Einträge via API laden
    var api = new mw.Api();
    api.get({
      action: 'query',
      list: 'recentchanges',
      rctype: 'new',
      rcprop: 'title|timestamp',
      rcnamespace: 0,            // nur Artikel
      rcshow: '!bot|!redirect',  // Bots & Weiterleitungen ausblenden
      rclimit: 3,
      format: 'json'
    }).done(function (data) {
      var items = (data.query && data.query.recentchanges) || [];

      // Helper: <li><a/></li> hinzufügen
      function addItem(href, text, title) {
        var li = document.createElement('li');
        var a = document.createElement('a');
        a.href = href;
        a.textContent = text;
        if (title) a.title = title;
        li.appendChild(a);
        list.appendChild(li);
      }

      if (!items.length) {
        addItem(mw.util.getUrl('Special:NewPages'), 'Keine neuen Seiten', 'Zur vollständigen Liste');
        return;
      }

      for (var i = 0; i < items.length; i++) {
        var rc = items[i];
        var href = mw.util.getUrl(rc.title);
        var tip  = new Date(rc.timestamp).toLocaleString('de-DE', { dateStyle: 'medium', timeStyle: 'short' });
        addItem(href, rc.title, tip);
      }

      // Abschluss-Link
      addItem(mw.util.getUrl('Special:NewPages'), 'Alle neuen Seiten →', 'Zur vollständigen Liste');
    }).fail(function (err) {
      console.error('[NewPages] API-Fehler:', err);
      var li = document.createElement('li');
      li.textContent = 'Fehler beim Laden';
      list.appendChild(li);
    });
  });
})();
/* global mw, $ */
(function () {
  'use strict';
  $.when( $.ready ).then(function () {

    // 1) Mögliche Einfügepunkte (Timeless/Vector/MonoBook)
    var content =
      document.getElementById('mw-content-text') ||
      document.getElementById('mw-content') ||
      document.getElementById('bodyContent') ||
      document.getElementById('content');

    if (!content) {
      console.warn('[ad-box] Kein Content-Container gefunden.');
      return;
    }

    // Doppelt vermeiden
    if (document.getElementById('ad-box')) {
      console.log('[ad-box] existiert bereits');
      return;
    }

    // 2) Box bauen
    var box = document.createElement('aside');
    box.id = 'ad-box';
    box.setAttribute('role','complementary');
    box.setAttribute('aria-label','Werbung');

    // Notfall-Styles, falls Common.css noch nicht greift (damit du es SOFORT siehst)
    box.style.cssText = 'float:right;width:300px;margin:0 0 1rem 1rem;background:#fffef7;border:1px solid #e5dfb3;border-radius:6px;box-shadow:0 1px 3px rgba(0,0,0,.06);font-size:90%;';

    var header = document.createElement('div');
    header.className = 'ad-header';
    header.innerHTML = '<span class="ad-badge" style="background:#ffea9e;border:1px solid #e0c200;padding:2px 6px;border-radius:4px;font-weight:700;text-transform:uppercase;">Anzeige</span> <span style="font-weight:700;margin-left:.5em;">Unterstütze dieses Wiki</span>';

    var body = document.createElement('div');
    body.className = 'ad-body';
    body.style.padding = '.6em .8em';

    // 3) Amazon-URL dynamisch (Spamfilter umgehen)
    var amazonHost  = 'amazon.' + 'de';
    var amazonBase  = 'https://www.' + amazonHost + '/';
    var partnerTag  = 'rettungsdie00-21'; // <-- anpassen

    var u = new URL(amazonBase);
    u.searchParams.set('tag', partnerTag);
    var amazonUrl = u.toString();

    // 4) Inhalt
    var html = '' +
      '<ul style="list-style:none;margin:.2em 0;padding:0">' +
      '  <li style="margin:.35em 0"><a href="' + amazonUrl + '" target="_blank" rel="nofollow sponsored noopener noreferrer">Bei Amazon einkaufen (Affiliate)</a></li>' +
      '  <li style="margin:.35em 0"><a href="https://www.paypal.me/rettungsdienstblog" target="_blank" rel="nofollow noopener noreferrer">PayPal – jetzt unterstützen</a></li>' +
      '  <li style="margin:.35em 0"><a href="/index.php?title=Spezial:Zufällige_Seite">Zufälliger Artikel →</a></li>' +
      '</ul>' +
      '<div style="font-size:85%; color:#555; margin-top:.5em;">' +
      '  * Als Amazon-Partner verdienen wir an qualifizierten Verkäufen.' +
      '</div>';

    body.innerHTML = html;
    box.appendChild(header);
    box.appendChild(body);

    // 5) Einfügen – zuerst im Content oben
    try {
      content.insertBefore(box, content.firstChild);
      console.log('[ad-box] eingefügt in', content.id || content.className);
    } catch (e) {
      console.warn('[ad-box] insertBefore fehlgeschlagen, versuche Fallback:', e);
      (content.appendChild || function(){ })(box);
    }

    // 6) Hard-Check: Wenn du ihn immer noch nicht siehst, als Test FIXIERT rechts oben einblenden
    //    Kommentiere die nächsten 5 Zeilen EIN, um zu testen:
    /*
    box.style.position = 'fixed';
    box.style.right = '1rem';
    box.style.top = '6rem';
    box.style.zIndex = 1000;
    console.log('[ad-box] testweise fixed positioniert');
    */
  });
})();
/* global mw, $ */
(function () {
  'use strict';
  $.when($.ready).then(function () {

    // Funktion, um festzustellen, ob Adblocker aktiv ist
    function detectAdblocker(callback) {
      var bait = document.createElement('div');
      bait.className = 'adsbox ad-banner ad-unit text-ad'; // typische Adblocker-Keywords
      bait.style.cssText = 'height:1px; width:1px; position:absolute; left:-9999px;';
      document.body.appendChild(bait);
      window.setTimeout(function () {
        var blocked = !bait.offsetHeight || !bait.clientHeight;
        document.body.removeChild(bait);
        callback(blocked);
      }, 300);
    }

    function showAdblockNotice() {
      if (document.getElementById('adblock-hinweis')) return;

      var div = document.createElement('div');
      div.id = 'adblock-hinweis';
      div.innerHTML =
        '<button id="adblock-close">×</button>' +
        '<strong>Hinweis:</strong> Wir finanzieren dieses Wiki durch Affiliate-Links und freiwillige Unterstützung. ' +
        'Bitte deaktiviere deinen Adblocker für <b>' + window.location.hostname + '</b>, um uns zu unterstützen. ❤️';

      document.body.appendChild(div);
      div.style.display = 'block';

      document.getElementById('adblock-close').onclick = function () {
        div.remove();
      };
    }

    // Nur zeigen, wenn Adblocker erkannt wird
    detectAdblocker(function (isBlocked) {
      if (isBlocked) {
        // Optional: Nur einmal pro Nutzer (mit LocalStorage)
        if (!localStorage.getItem('adblock_notice_shown')) {
          showAdblockNotice();
          localStorage.setItem('adblock_notice_shown', 'yes');
        }
      }
    });
  });
})();