User:GhostInTheMachine/TalkHelper2.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:GhostInTheMachine/TalkHelper2. |
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('<div id="mw-panel-wp" class="navbox" style="text-align: left;"></div>');
$subPanel = $('#mw-panel-wp');
$subPanel.wrapInner('<div class="mw-collapsible-content"></div>');
$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('<div id="mw-panel-' + when + '" class="navbox" style="text-align: left;"></div><p></p>');
var $subPanel = $('#mw-panel-' + when);
posts.forEach(
function(id){
var ts = new Date(id);
$($subPanel).append(
'<div class="talkHelperRef">' +
'<a href="#' + id + '">' +
ts.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit', hour12: false }) +
'</a></div>'
);
}
);
$subPanel.wrapInner('<div class="mw-collapsible-content"></div>');
$subPanel.prepend(posts.length + ' ' + when);
$subPanel.makeCollapsible();
$('.talkHelper' + when + ':contains(' + mw.config.get('wgUserName') + ')').addClass('talkHelperMe');
}