User:GhostInTheMachine/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('TalkHelper2 could not load dependencies');  } );

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

if (window.commentsInLocalTimeWasRun) { console.log('TalkHelper2 CILT loaded'); TalkHelper2CSS; TalkHelper2Run; } else { console.log('TalkHelper2 waiting'); setTimeout(TalkHelper2Init, 10); } }

function TalkHelper2CSS { mw.util.addCSS(`

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

.talkHelperToday { background-color: moccasin; border-color: #3366cc; border-style: solid; border-width: thin; padding: 5px; }

.talkHelperYesterday { background-color: cornsilk; border-color: #3366cc; border-style: dashed; border-width: thin; padding: 5px; }

.talkHelperMe { border-width: medium; }

.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);

} );

console.log('TalkHelper2 ' + when + '=' + posts.length); 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(' + mw.config.get('wgUserName') + ')').addClass('talkHelperMe'); }