Benutzer:Hlambert63/common.js

aus Wikipedia, der freien Enzyklopädie
Zur Navigation springen Zur Suche springen

Hinweis: Leere nach dem Veröffentlichen den Browser-Cache, um die Änderungen sehen zu können.

  • Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
  • Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
  • Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
console.log( "+++ --- start of common" );
popupShortcutKeys = true;
popupShortCutKeys = true; // von mir
popupHideDelay = 0;
popupOnlyArticleLinks = false;
popupMaxWidth = 500;
popupPreviewFirstParOnly = false;
popupPreviewFirstPartOnly = false; // von mir
// popupPreviewKillTemplates = true; // default
popupPreviewKillTemplates = false;
popupStructure = 'menus'; // for long menus
popupLazyPreviews = false; // load popup data since available; true: loads, if visible 

// 05.11.2023 shortdesc helper for show short descr. from wikidata object
mw.loader.getScript( 'https://en.wikipedia.org/w/load.php?modules=ext.gadget.libSettings' ).then( function() {
	mw.loader.load( 'https://en.wikipedia.org/w/load.php?modules=ext.gadget.Shortdesc-helper' );
});

// load tabellenstile 
mw.loader.load('https://de.wikipedia.org/wiki/Vorlage:Tabellenstile/styles.css?action=raw&ctype=text/css', 'text/css');

// add class 'tabelle-kopf-fixiert' to all elements with class "wikitable"

// debugger;
const addFunc = function( element ) {
//   console.log( "+++ +++ in func" );
    if (element .classList && ! element .classList.contains( 'tabelle-kopf-fixiert' ) ) {
      const thElements = element.getElementsByTagName( 'th' );
      // console.log("+ + + th elements length: " + thElements.length);
      var maxHeight = 0;
      for (var i=0; thElements && i < thElements.length; i++ ) {
            const thElem = thElements[i];
            // debugger;
            // console.log("+ + + th element at " + i + " is: " + thElem + " cl.height: " + thElem.clientHeight + " offs.height: " + thElem.offsetHeight);
            if ( thElem.clientHeight > maxHeight ) {
                 maxHeight = thElem.clientHeight;
            }
      }
      // console.log("+ + + maxHeight of th elements: " + maxHeight + " win.innerH*0.2: " + window.innerHeight*0.2 );
      if ( maxHeight > window.innerHeight * 0.2 ) {
          // console.log("+ + + maxHeight > win.innerH*0.2, return, no add class ");
          return;
      }
      element.classList.add( 'tabelle-kopf-fixiert' );
      // console.log( "+++ +++ added 'tabelle-kopf-fixiert' to wikitable" );
    }
};
const wikiTabClassElements = document.getElementsByClassName("wikitable");
// console.log("+++ wikiTabClassElements is: "+ wikiTabClassElements);
if (wikiTabClassElements && wikiTabClassElements.length > 0 ) {

  const elemsLen = wikiTabClassElements.length;
  // console.log("+++ +++ wikiTabClassElement has " + elemsLen + " elements");

  if ( elemsLen == 1) {
    const singleElem = wikiTabClassElements[0];
    addFunc( singleElem );
  } else {
    var i = 0;
    while ( i < elemsLen) {
      const elem = wikiTabClassElements[i];
      i++;
      // console.log("+++ +++ wikiTabClassElement: " + elem + " i=" + i);
      addFunc( elem );
    }  // end loop
  } // end else
} // end if wikitable elems

// Beobachtungslisten-Helferlein

/*
mw.loader.load("https://en.wikipedia.org/w/index.php?title=User:PerfektesChaos/js/listPageOptions/r.js&action=raw&bcache=1&maxage=604800&ctype=text/javascript",
               "text/javascript");
if ( typeof mw.libs.listPageOptions !== "object" ) {
   mw.libs.listPageOptions  =  { };
}
mw.libs.listPageOptions.lower = false;
mw.libs.listPageOptions.luxury = true;
*/

// Beob.liste: move node "Als gelesen" down / dont work
/* 
const elementsToMove = document.getElementsByClassName("mw-rcfilters-ui-watchlistTopSectionWidget-savedLinksTable");
if ( elementsToMove && elementsToMove.length == 1) {
   console.log( "watchlist 'mark as readed' to move found");
   
} else {
   console.log( "no watchlist  'mark as readed' to move found: " + ( elementsToMove ? elementsToMove.length : elementsToMove ) );
} */

// Change title of 'Aend. an verlinkten Seiten'

const allUrlParams = window.location.search, suchStr = "target=";
// debugger;
if ( allUrlParams.indexOf( suchStr ) >= 0 ) {
 const abTarg = allUrlParams.substring( allUrlParams.indexOf( suchStr ));
 const indNextPar = abTarg.indexOf( '&');
 const colonInd = abTarg.indexOf( '%3A' );
 if (colonInd < indNextPar ) {
   var newTitle;
   if ( colonInd >= 0 ) {
       newTitle = "Ae " + abTarg.substring( suchStr.length, suchStr.length+1) + ':' + abTarg.substring( colonInd+3, indNextPar );
   } else {
       newTitle = "Ae Li " + abTarg.substring( 7, indNextPar );
   }
   newTitle = newTitle.replace( '%28', "(" );
   newTitle = newTitle.replace( '%29', ")" );
   newTitle = newTitle.replace( '+', " " ); // 2 x + in 'Essen+und+Trinken'
   newTitle = newTitle.replace( '+', " " );

   newTitle = newTitle.replace( '%C3%A4', "ä" );
   document.title = newTitle;
 }
} 

console.log( "+++ --- end of common" );