Участник:Neolexx/contributors.js

Перейти к: навигация, поиск
(void function() {

  var args = '';
  
  var func = ''.concat(
  
  '  var txt = (/*@cc_on!@*/false) ? "innerText" : "textContent"; ',
  '  var target = document.getElementById("siteSub"); ',
  '  if ( wgIsArticle && target ) { ',
  '    Nx_Dialog("Авторы и редакторы"); ',
  '    var lnk = document.createElement("A"); ',
  '    lnk.style.display = "inline-block"; ',
  '    lnk.style.marginLeft = "1.5em"; ',
  '    lnk.href = "#"; ',
  '    lnk.title = "Авторы и редакторы статьи (до 500 правок назад)"; ',
  '    lnk[txt] = "Авторы"; ',
  '    lnk.onclick = new Function("return Nx_showContributors();"); ',
  '    target.appendChild(lnk); ',
  '  } '
  );

  if (typeof window == 'object') { // not WSH
    if ('addEventListener' in window) {
      window.addEventListener( 'load',
      new Function(args, func), false );
    }
    else if ('attachEvent' in window) {
      window.attachEvent( 'onload',
      new Function(args, func) );
    }
    else {
      /*NOP*/
    }
  }
}())



function Nx_Dialog(title) {

  var DialogTitle = title || '';

  var isIE = /*@cc_on!@*/false;
    
  if (isIE && !!document.documentElement) {
    var viewportWidth = document.documentElement.offsetWidth;
    var viewportHeight = document.documentElement.offsetHeight;
  }
  else {
    var viewportWidth = self.innerWidth  || 300;
    var viewportHeight = self.innerHeight || 250;
  }
   
  var wnd = document.createElement('IFRAME');
  
  var w = Math.round(viewportWidth/2);
  var h = Math.round(viewportHeight/2);
  var x = Math.round((viewportWidth - w)/2);
  var y = Math.round((viewportHeight - h)/2);
  wnd.style.minWidth = '200px';
  wnd.style.minHeight = '100px';
  wnd.style.width = w + 'px';
  wnd.style.height = h + 'px';
  wnd.style.left = x + 'px';
  wnd.style.top = y + 'px';
  wnd.src = 'about:blank';
  wnd.application = 'yes'; // for HTA
  wnd.scrolling = 'no';
  wnd.frameBorder = '0'; // IE is case sensitive
  wnd.style.display = 'none';
  wnd.style.position = 'fixed';
  //wmd.style.zIndex = "1001";
  wnd.style.border = 'thin solid ActiveBorder';
  wnd.style.boxShadow = '8px 8px 4px rgba(0,0,0,0.2)';
  wnd.style.borderRadius = '8px';
  wnd.style.backgroundColor = 'Window';
  NxDialogWindow = document.body.appendChild(wnd);
  
  NxDialogWindow.isFirstUse = true;
  
  NxDialogWindow.loadingImg = '<img src="'.concat(
    'https://upload.wikimedia.org/wikipedia/commons/2/2a/Loading_Key.gif',
    '">'
  );
  
    
  NxDialogDocument = (
    NxDialogWindow.contentWindow || NxDialogWindow.contentDocument
  ).document;
  NxDialogDocument.open('text/html', 'replace');
  NxDialogDocument.write('<!DOCTYPE html>'.concat(
      '<html>',
      '<head>',
      '<meta http-equiv="Content-Type" content="text/html;charset=utf-8">',
      '<title>DialogWindow</title>',
      '<style>',
      'HTML,BODY,DIV {box-sizing:border-box; margin:0; padding:0;',
                     'width:100%; height:100%;}',
      'BODY {background-color:Window; color:WindowText;',
            'font:1em Calibri, sans-serif; }',
      'TABLE {height:100%;}',
      '#tBar {height:34px; background-color:ActiveCaption; color:CaptionText;}',
      '#tBarLeft {padding:2px 2px 2px 1em;}',
      '#tBarRight {padding:2px;}',
      '#tMain {padding: 1em;}',
      '#Main {height:', h-36, 'px; overflow:auto;}',
      'BUTTON {font:1em Calibri, sans-serif;}',
      'BUTTON:focus {outline: none}',
      'BUTTON::-moz-focus-inner {border: 0;}',
      'A {color:#0645AD; text-decoration:none;}',
      'A:hover {text-decoration:underline;}',
      '</style>',
      '</head>',
      '<body>',
      '<table width="100%" cellspacing="0" cellpadding="0" border="0">',
      '<tbody>',
      '<tr id="tBar"><td id="tBarLeft">', DialogTitle, '</td>',
      '<td align="right" id="tBarRight">',
      '<button type="button" hidefocus ',
      'onclick="parent.NxDialogWindow.style.display=\'none\';">\u00D7</button>',
      '</td></tr>',
      '<tr><td colspan="2" valign="top" id="tMain">',
      '<div id="Main">', NxDialogWindow.loadingImg, '</div>',
      '</td></tr>',
      '</tbody>',
      '</table>',
      '</body>',
      '</html>'
    )
  );
  NxDialogDocument.close();
  
  window.setTimeout('Nx_Dialog = null;', 100);
}


function Nx_showContributors() {

  NxDialogWindow.style.display='block';
  
  if (NxDialogWindow.isFirstUse) {
    var out = NxDialogDocument.getElementById('Main');
    out.innerHTML = NxDialogWindow.loadingImg;
    var req = new XMLHttpRequest;
    req.onreadystatechange = callBack;
    req.open('GET', 'https://ru.wikipedia.org/w/api.php?'.concat(
    'action=query&prop=revisions&format=json&rvlimit=500&rvdir=newer',
    '&rvprop=user|comment&titles=', wgPageName), true);
    req.send('');
  }
  return false;
  
  function callBack() {
    if (req.readyState == 4) {
      if (req.status == 200) {
        NxDialogWindow.isFirstUse = false;
        processData();
      }
      else {
        out.innerHTML = '<p>Ошибка соединения '.concat(
          req.status,
          '<p><button type="button" onclick="',
          'parent.Nx_showContributors();',
          '">Повторить</button>'
        );
      }
    }
  }
  
  function processData() {
    out.innerHTML = '';
    var data = JSON.parse(req.responseText);
    var revs = data.query.pages[wgArticleId].revisions;
    var cloud = {};
    var URL = 'https://ru.wikipedia.org/wiki/User:';
    var isBot = new RegExp('Bot$', 'i');
    var len = revs.length;
    var name = '';
    var rback = -1;
    var tmp = '';
    for (var i=0; i<len; i++) {
      name = revs[i].user;
      rback = revs[i].comment.indexOf('ОТКАТ');
      if (rback != -1) {
        tmp = revs[i].comment;
        name = tmp.substring(tmp.indexOf('|', rback)+1, tmp.indexOf(']]', rback));
        if (name in cloud) {
          --cloud[name];
        }
      }
      else if (
        (name != 'WebCite Archiver') &&
        (name != 'РобоСтася') &&
        (!isBot.test(name) ) ) {
        (name in cloud) ? ++cloud[name] : cloud[name] = 1;
      }
      else {
        /*NOP*/
      }
    }
      
    var span = 'null';
      
    for (var key in cloud) {
      if (!cloud.hasOwnProperty(key)) {continue;}
      if (cloud[key] <= 0) {continue;}
      span = document.createElement('SPAN');
      span.style.display = 'inline-block';
      span.style.marginRight = '1.5em';
      if (cloud[key] >= 20) {
        span.style.fontSize = 'x-large';
      }
      else if (cloud[key] >= 10) {
        span.style.fontSize = 'large';
      }
      else if (cloud[key] >= 2) {
        span.style.fontSize = 'medium';
      }
      else {
        span.style.fontSize = 'small';
      }
      span.innerHTML = '<a href="'.concat(
      URL, key, '" target="_parent">', key, '</a>'
      );
      out.appendChild(span);
    }
  }

}

Участник:Neolexx/contributors.js.

© 2019–2023 sizcrimea.ru, Россия, Нальчик, ул. Черкесская 49, +7 (8662) 59-22-71