注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
 *  Add Ultrafilter support
 */

function ultrafilter(cats) {

  function buildHtml(rc) {
    var html = '';
    if(rc.length > 0) {
      var group = 0;
      var date =  rc[0].timestamp.toString().split('T')[0];
      html += ("<h4>" + date + "</h4>");
      html += "<ul>";
      for(var ind in rc) {
        var change = rc[ind], date = change.timestamp.toString().split('T')[0], last;
        var closeOpen = last && (last!==date);
        if(closeOpen) {
          html += ("</ul><h4>" + date + "</h4><ul>");
        }
        var time = change.timestamp.toString().split('T')[1];
        html += ("<li>" + time + "&nbsp;&nbsp;<a href='/wiki/" + change.title + "'>" + change.title + "</a></li>");
        last = date;
      }
      html += "</ul>";
    }
    return html;
  }

  function buildAlert(record) {
    var html = '';
    if(record && record.ntf>0) {
      html += "<div style='background-color:#F6E3CE'>您有<a href='/wiki/User:" + wgUserName + "/Ultrafilter'>新讨论</a></div>";
    }
    return html;
  }

  function fetchRc(cats) {
      var path = wgPageName.split('/');
      if(wgNamespaceNumber===2 && path[path.length-1]==='Ultrafilter' && cats) {
          var node = $('#ultrafilter-rc');
          if(node) {
              cats = encodeURIComponent(cats);
              $.getJSON('http://ultrafilter.org/api/rc/' + wgContentLanguage + '/' + cats + '/0?jsonp=?', function(data) {
                  node.html(buildHtml(data));
              });
          }
      }
  }

  function fetchRt(cats) {
      var path = wgPageName.split('/');
      if(wgNamespaceNumber===2 && path[path.length-1]==='Ultrafilter' && cats) {
          var node = $('#ultrafilter-rt');
          if(node) {
              cats = encodeURIComponent(cats);
              $.getJSON('http://ultrafilter.org/api/rt/' + wgContentLanguage + '/' + cats + '/0?jsonp=?', function(data) {
                  node.html(buildHtml(data));
              });
          }
       }
  }

  function fetchNtf() {
      var path = wgPageName.split('/');
      if(wgNamespaceNumber===2 && path[path.length-1]==='Ultrafilter' && wgUserName) {
          var node = $('#ultrafilter-ntf');
          if(node) {
              var user = encodeURIComponent(wgUserName);
              $.getJSON('http://ultrafilter.org/api/ntf/' + wgContentLanguage + '/' + user + '/0?jsonp=?', function(data) {
                  node.html(buildHtml(data));
              });
          }
       }
  }

  function ultrafilterAlert(cats) {
      if(wgUserName) {
          var node = $('#firstHeading');
          if(node) {
              var user = encodeURIComponent(wgUserName);
              cats = encodeURIComponent(cats);
              $.getJSON('http://ultrafilter.org/api/alt/' + wgContentLanguage + '/' + user + '/' + cats +'?jsonp=?', function(data) {
                  node.after(buildAlert(data));
              });
          }
       }
  }

  fetchRc(cats);
  fetchRt(cats);
  fetchNtf();
  ultrafilterAlert(cats);

}