Zuletzt bearbeitet vor 2 Monaten
von Mark Wagner

MediaWiki:Common.js: Unterschied zwischen den Versionen

Keine Kategorien vergebenBearbeiten
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(40 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
/* Das folgende JavaScript wird für alle Benutzer geladen. */
 
/**
* Entfernt das Wort „Fortsetzung“ aus allen SMW-Spalten-Headern (div.smw-column-header).
* Leg die Datei MediaWiki:Common.js (oder Discovery.js) an bzw. bearbeite sie:
*
* 1. Gehe als Admin auf Special:Edit/MediaWiki:Common.js
* 2. Füge diesen Code ans Ende ein und speichere.
* 3. Leere den Browser-Cache (STRG + F5), damit das neue JS geladen wird.
*/
mw.loader.using(['jquery'], function () {
mw.loader.using(['jquery'], function () {
     $(document).ready(function () {
     $(document).ready(function () {
Zeile 31: Zeile 23:
      )
      )
      .appendTo('head');
      .appendTo('head');
});
});
$(function() {
});
    // 0. Variablen definieren
});
     var cookieName  = 'bs_lastNav',
$(function() {
        cookieMaxAge = 60 * 60 * 24 * 30; // 30 Tage
  // 1) Klick merken
  $('body').on('click', 'a.mws-tree-item-label', function() {
     try {
      window.name = JSON.stringify({ lastNav: this.getAttribute('href') });
    } catch (e) {}
  });


    // 1. Cookie‐Funktionen
  // 2) Polling & Aufklappen + Inline‐Styling
    function setCookie(name, value, maxAge) {
  var attempts = 0,
       document.cookie = name + '=' + encodeURIComponent(value) +
      interval = setInterval(function() {
        '; path=/; max-age=' + maxAge;
    attempts++;
    var data = {};
    try {
       data = JSON.parse(window.name || '{}');
    } catch (e) {}
    var last = data.lastNav;
    if (!last || attempts > 10) {
      clearInterval(interval);
      return;
     }
     }
     function getCookie(name) {
     var $link = $('a.mws-tree-item-label[href="' + last + '"]');
       return document.cookie.split(';').reduce(function(prev, curr) {
    if ($link.length) {
         var parts = curr.trim().split('=');
       clearInterval(interval);
         return parts[0] === name ? decodeURIComponent(parts[1]) : prev;
      // Zweige aufklappen
       }, null);
      $link.parents('li.mws-tree-item').each(function() {
         var $exp = $(this).children('div').children('a.mws-tree-expander.collapsed');
         if ($exp.length) {
          $exp.trigger('click');
        }
      });
      // Inline‐Styles setzen
      $link.css({
        'background-color': '#eef',
        'font-weight': 'bold',
        'color': '#000',
        'border-left': '3px solid #98A7C4',
        'padding-left': '0.5em'
      });
       // optional scrollen
      $('html, body').scrollTop($link.offset().top - 80);
     }
     }
  }, 300);
});
$(function(){
  // In allen Category-Ausgaben: jede LI, die einen <a class="new"> enthält, entfernen
  $('.smw-columnlist-container a.new').each(function(){
    $(this).closest('li').remove();
  });
});
$(function(){
  // 1. Rote Links raus (wie gehabt)
  $('.smw-columnlist-container a.new').each(function(){
    $(this).closest('li').remove();
  });


    // 2. Klick handler: speichere die URL
  // 2. Jetzt jede Buchstaben-Überschrift entfernen, deren Liste leer ist
    $('a.mws-tree-item-label').on('click', function() {
  $('.smw-column-header').each(function(){
      var href = $(this).attr('href');
    var $header = $(this),
      if (href) {
         $ul     = $header.next('ul');
         setCookie(cookieName, href, cookieMaxAge);
    if ($ul.length && $ul.children('li').length === 0) {
      }
      $ul.remove();
    });
      $header.remove();
 
     // 3. Beim Laden: letzten Eintrag aufklappen
    var last = getCookie(cookieName);
    if (last) {
      var $link = $('a.mws-tree-item-label[href="' + last + '"]');
      if ($link.length) {
        var $item    = $link.closest('li.mws-tree-item'),
            $expander = $item.find('> div > a.mws-tree-expander'),
            $children = $item.children('ul.mws-tree-item-children');
 
        // Expander‐Icon anpassen
        $expander
          .removeClass('collapsed')
          .addClass('expanded')
          .attr('aria-expanded', 'true');
 
        // Unterknoten einblenden
        $children.show();
 
        // Optional: scroll zum Link
        $('html, body').scrollTop($link.offset().top - 100);
      }
     }
     }
   });
   });
});
});
// attachments immer in neuem Tab öffnen
(function () {
  // Hilfs-Funktion, die alle neuen Attachment-Links anpasst
  function updateAttachmentLinks() {
    // Alle Download-Links in der Datei-Liste
    $('.attachments-filelist a.oojsplus-data-gridWidget-url-button')
      .attr('target','_blank')
      .attr('rel','noopener noreferrer');
  }
  // beim Seiten-Load einmal ausführen
  $(updateAttachmentLinks);
  // und mit MutationObserver auf nachträglich geladene Links achten
  var container = document.querySelector('.attachments-filelist');
  if (container) {
    new MutationObserver(function (mutations) {
      updateAttachmentLinks();
    }).observe(container, { childList: true, subtree: true });
  }
})();

Aktuelle Version vom 18. Juni 2025, 20:25 Uhr

mw.loader.using(['jquery'], function () {
    $(document).ready(function () {
        $('.smw-column-header').each(function () {
            // aktuellen HTML-Inhalt holen
            var html = $(this).html();
            // "Fortsetzung" entfernen, Leerzeichen ggf. bereinigen
            var newHtml = html.replace(/Fortsetzung/g, '').trim();
            // falls nach dem Entfernen gar kein Text übrig ist, komplette Header-Box ausblenden:
            if (newHtml === '') {
                $(this).hide();
            } else {
                // ansonsten nur den Text überschreiben, sodass z. B. "B Fortsetzung" → "B" wird
                $(this).html(newHtml);
            }
        });
        $(function () {
			    $('<style>')
			      .prop('type', 'text/css')
			      .html(
			        '.breadcrumb-item { font-size: 17px !important; }' +
			        '.breadcrumb-nav  { border-bottom: 2px solid #85bc20!important; margin-bottom: 20px !important; }'
			      )
			      .appendTo('head');
		});
	});
});
$(function() {
  // 1) Klick merken
  $('body').on('click', 'a.mws-tree-item-label', function() {
    try {
      window.name = JSON.stringify({ lastNav: this.getAttribute('href') });
    } catch (e) {}
  });

  // 2) Polling & Aufklappen + Inline‐Styling
  var attempts = 0,
      interval = setInterval(function() {
    attempts++;
    var data = {};
    try {
      data = JSON.parse(window.name || '{}');
    } catch (e) {}
    var last = data.lastNav;
    if (!last || attempts > 10) {
      clearInterval(interval);
      return;
    }
    var $link = $('a.mws-tree-item-label[href="' + last + '"]');
    if ($link.length) {
      clearInterval(interval);
      // Zweige aufklappen
      $link.parents('li.mws-tree-item').each(function() {
        var $exp = $(this).children('div').children('a.mws-tree-expander.collapsed');
        if ($exp.length) {
          $exp.trigger('click');
        }
      });
      // Inline‐Styles setzen
      $link.css({
        'background-color': '#eef',
        'font-weight': 'bold',
        'color': '#000',
        'border-left': '3px solid #98A7C4',
        'padding-left': '0.5em'
      });
      // optional scrollen
      $('html, body').scrollTop($link.offset().top - 80);
    }
  }, 300);
});
$(function(){
  // In allen Category-Ausgaben: jede LI, die einen <a class="new"> enthält, entfernen
  $('.smw-columnlist-container a.new').each(function(){
    $(this).closest('li').remove();
  });
});
$(function(){
  // 1. Rote Links raus (wie gehabt)
  $('.smw-columnlist-container a.new').each(function(){
    $(this).closest('li').remove();
  });

  // 2. Jetzt jede Buchstaben-Überschrift entfernen, deren Liste leer ist
  $('.smw-column-header').each(function(){
    var $header = $(this),
        $ul     = $header.next('ul');
    if ($ul.length && $ul.children('li').length === 0) {
      $ul.remove();
      $header.remove();
    }
  });
});
// attachments immer in neuem Tab öffnen
(function () {
  // Hilfs-Funktion, die alle neuen Attachment-Links anpasst
  function updateAttachmentLinks() {
    // Alle Download-Links in der Datei-Liste
    $('.attachments-filelist a.oojsplus-data-gridWidget-url-button')
      .attr('target','_blank')
      .attr('rel','noopener noreferrer');
  }

  // beim Seiten-Load einmal ausführen
  $(updateAttachmentLinks);

  // und mit MutationObserver auf nachträglich geladene Links achten
  var container = document.querySelector('.attachments-filelist');
  if (container) {
    new MutationObserver(function (mutations) {
      updateAttachmentLinks();
    }).observe(container, { childList: true, subtree: true });
  }
})();