Benutzer:Hannes Röst/flagged user.js

aus Wikipedia, der freien Enzyklopädie

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
  • Internet Explorer/Edge: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
  • Opera: Strg+F5
// callback function 
function revhistory_callback (res) {
    var logevents = res.query.logevents ;
    var result = logevents[0]["params"]["0"];
    var urlopen = wgScriptPath + '/index.php?diff=cur&oldid=' + result;
    window.open( urlopen, '_blank');
}

function open_unflagged_by_user() {

    // This function opens links in the Spezial:Beiträge/User page

    // The structure is the following:
    // <div id="bodyContent">
    //   <div id="mw-content-text">
    //     <div>
    //     <form>
    //     <p>
    //     <ul>
    //       <li>
    //         <span class="flaggedrevs-pending">
    //           <a href="..." title="Title">

    //  we look for an ul inside the body that does not have an ID
    //  its li elements may have a first child that 

    // TODO: make a list of all links and then open each link once at most
    //       (right now we have duplicates)

    var content = document.getElementById("mw-content-text");
    for (i in content.children) {
      if (content.children[i].tagName == 'UL') {
        var myul = content.children[i];
        for(j in myul.children) {
          var myli = myul.children[j];
          if(  myli && myli.className.indexOf('flaggedrevs-pending') !== -1 ) {
            //we got a pending revision for this user
            var pending = myli;
            for (var k=0; aNode = pending.getElementsByTagName("A")[k]; k++) {
            //we look for a diff link
            if ( (href = aNode.getAttribute("href")) && (href.search(/oldid=/) != -1) 
                           && (href.search(/diff=/) != -1)  ) {
                //now we have found one such link
                var mytitle = href.match('title=[^&]*')[0].slice(6);

                var url = wgScriptPath + '/api.php?format=json&callback=revhistory_callback' 
                + '&action=query&list=logevents&letype=review&lelimit=1&letitle=' + mytitle;
                mw.loader.load(url);

               }
            }
          }
        }
      }
    }
}

function open_unflagged_special() {

    // This function opens links in the Spezial:Seiten_mit_ungesichteten_Versionen page

    // The structure is the following:
    // <div id="bodyContent">
    //   <div id="mw-content-text">
    //     <div>
    //     <form>
    //     <p>
    //     <ul>
    //       <li>
    //         <a href="..." title="Title">

    //we look for an ul inside the body that does not have an ID
    //its li elements may have a first child that 

    var content = document.getElementById("mw-content-text");
    for (i in content.children) {
      if (content.children[i].tagName == 'UL') {
        var myul = content.children[i];
        for(j in myul.children) {
          var myli = myul.children[j];
          var pending = myli;
          for (var k=0; aNode = pending.getElementsByTagName("A")[k]; k++) {
            //we look for a diff link
            if ( (href = aNode.getAttribute("href")) && (href.search(/oldid=/) != -1) 
                           && (href.search(/diff=/) != -1)  ) 
            {
                //now we have found one such link
                window.open( href, '_blank');
            }
          }
        }
      }
    }
}




function add_flagged_button() {

  //we leave unless we find the correct heading
  var heading = document.getElementById("firstHeading");
  if (heading.innerHTML == 'Benutzerbeiträge' || (heading.children.length > 0 && heading.children[0].innerHTML == 'Benutzerbeiträge') ) { 
      var flag_button_name = "Öffne Ungesichtete"
      var tab = document.getElementById("ca-nstab-special");

      var flag_button  = document.createElement('a');
      flag_button.setAttribute('href', '#'); 
      flag_button.setAttribute('onclick', 'open_unflagged_by_user()');
      var flag_li  = document.createElement('li');
      var TextNode = document.createTextNode(flag_button_name);

      flag_li.appendChild( flag_button );
      flag_button.appendChild( TextNode );

      tab.parentNode.insertBefore( flag_li, tab.nextSibling );
  }
  else if (heading.innerHTML == 'Seiten mit unmarkierten Änderungen' || heading.innerHTML == "Seiten mit ungesichteten Versionen" || (heading.children.length > 0 && heading.children[0].innerHTML == 'Seiten mit unmarkierten Änderungen') ) { 

      var flag_button_name = "Öffne Ungesichtete"
      var tab = document.getElementById("ca-nstab-special");

      var flag_button  = document.createElement('a');
      flag_button.setAttribute('href', '#'); 
      flag_button.setAttribute('onclick', 'open_unflagged_special()');
      var flag_li  = document.createElement('li');
      var TextNode = document.createTextNode(flag_button_name);

      flag_li.appendChild( flag_button );
      flag_button.appendChild( TextNode );

      tab.parentNode.insertBefore( flag_li, tab.nextSibling );
  }

}
try  {
  addOnloadHook(add_flagged_button);
}
catch(err)  {
  //No error handling
}