User:Evolution and evolvability/TalkHelper2.js

mw.loader.load( '/w/index.php?title=User:BrandonXLF/FloatSide.css&action=raw&ctype=text/css', 'text/css' );

mw.loader.using( [ 'ext.gadget.CommentsInLocalTime',    'jquery.makeCollapsible'  ],  TalkHelper2Init,  function{    alert('Could not load dependencies');  } );

function TalkHelper2Init { console.log('TalkHelper2 init');

if (window.commentsInLocalTimeWasRun) {

TalkHelper2CSS; TalkHelper2Run;

} else { setTimeout(TalkHelper2Init, 10); } }

function TalkHelper2CSS { mw.util.addCSS(`

.localcomments { border-bottom: solid 2px cornflowerblue; }

.talkHelperToday { background-color: #EEEEFB; padding: 5px; }

.talkHelperYesterday { background-color: #F0F0FF; padding: 5px; }

.talkHelperMe { border-left: 4px solid #3366CC; background-color: #F0F0FB; padding: 5px; }

.talkHelperRef { font-size: small; margin-left: 1em; }

`); }

function TalkHelper2Run {

$('#mw-panel').wrapInner(' ');

$subPanel = $('#mw-panel-wp');

$subPanel.wrapInner(' '); $subPanel.prepend('Wikipedia'); $subPanel.makeCollapsible; $subPanel.addClass('navbox');

TalkHelper2Build('Yesterday'); TalkHelper2Build('Today'); }

function TalkHelper2Build(when) { var posts = [];

$.each(   $(".localcomments:contains(', " + when + "')"),    function{

var id = $(this).attr('timestamp'); $(this).parent.addClass('talkHelper' + when).attr('id', id); posts.push(1 * id);

} );

if(posts.length < 1) return;

mw.util.addPortletLink(   'p-namespaces',    '#',    posts.length + ' ' + when.toLowerCase,    'ca-goto-' + when,    'Go to first post for ' + when  );

$('#ca-goto-' + when).click( function(e){   e.preventDefault;    $('html, body').animate({scrollTop: $('.talkHelper' + when).first.offset.top - 20});  });

posts.sort;

$('#mw-panel').prepend('  '); var $subPanel = $('#mw-panel-' + when);

posts.forEach(   function(id){      var ts = new Date(id);      $($subPanel).append( ' ' +       '' + ts.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false }) + ' ' );   }  );

$subPanel.wrapInner(' '); $subPanel.prepend(posts.length + ' ' + when); $subPanel.makeCollapsible;

$('.talkHelper' + when + ':contains(' + wgUserName + ')').addClass('talkHelperMe'); }