MediaWiki:ScrollingList.js

From WikiLectures

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.
/* ======== Scrolling list ================================
   author:     [[User:Slepi]]
   date:       06/2011
   desc.:      This script's function is to display list
               of wanted articles and scroll it
               on the page (element id "wanted-articles").
   ======================================================== */

// FUNCTION THAT SCROLLS LIST OF WANTED ARTICLES
// in element with id="wanted-articles"
function wantedArticles(number) {

  // for list of articles the offset must be increased
  number += 1;
  number += '';

  // older browsers
  if (!window.XMLHttpRequest) {
    if (document.getElementById("wanted-pages-mp-box")) {
      // hide element
      document.getElementById("wanted-pages-mp-box").style.display = "none";
    }
    return false;
  }

  // wait until data available
  if (xmlWanted.readyState != 4 || xmlWanted.status != 200) return;

  // processing the server response
  var beginParse = "<ol start='" + number + "' class='special'>";
  var endParse = "</ol>";
  var htmlRes = xmlWanted.responseText;
  var start = htmlRes.indexOf(beginParse);
  var end = htmlRes.indexOf(endParse);

  // processing the output from the list
  var output = htmlRes.substring(start+29+number.length, end-6);
  output = output.replace(/<\/li>\n<li>/g, "&nbsp;•&nbsp;&nbsp;");
  output = output.replace(/<li>/g, "");
  output = output.replace(/<\/li>/g, "");
  output = output.replace(/\(<a href\=.*?\d{1,3} link.?<\/a>\)/g, "");
  if (navigator.appName == "Opera") output = output.replace(/\/a>\)/g, ""); // Opera fix

  // put the output into the element with id="wanted-articles"
  output = '<marquee scrolldelay="40" scrollamount="1">' + output + '</marquee>';
  document.getElementById("wanted-articles").innerHTML = output;

  // delete variables
  delete output;
  delete htmlRes;
  delete xmlWanted;
}

function wantedArticlesAdj() {
  wantedArticles(wantedOffsetNumber);
}

// START
var wantedOffsetNumber;

addOnloadHook(function() {
  if (document.getElementById("wanted-articles") != undefined) {
    var xmlWanted;
    wantedOffsetNumber = Math.round(Math.random()*500);
    getXMLHttpRequest("xmlWanted", wgServer + wgScript + "/Special:Wantedpages?limit=20&offset=" + wantedOffsetNumber, "wantedArticlesAdj");
  }
});

/* </pre> */