Skip to content

Instantly share code, notes, and snippets.

@blizzardengle
Created May 10, 2020 23:35
Show Gist options
  • Save blizzardengle/273510e618ffda57d631cb8bc128d60d to your computer and use it in GitHub Desktop.
Save blizzardengle/273510e618ffda57d631cb8bc128d60d to your computer and use it in GitHub Desktop.
// Attempt to find the message list on this page.
var msgList = document.querySelector('#content .message-list .messages');
var scroller = document.querySelector('#content .message-list-scroller');
// If the list was found continue.
if( msgList && scroller ){
console.log('Active.')
var li = document.createElement('LI');
li.id = 'controls'
var html = '<label>Ignore last <input type="text" id="days" style="display:inline-block;"> days.</label><br>'
html += '<button onclick="run();">Auto Check Messages</div>'
li.innerHTML = html;
msgList.prepend( li );
} else {
console.log('Something is wrong.');
}
function run(){
console.log('Start auto scroll.')
recursiveScroll( scroller );
}
// Auto scroll so the list loads all messages.
function recursiveScroll( scroller ){
var height = 0;
var limit = 0;
if( scroller.dataset.height ){
var height = parseInt( scroller.dataset.height )
}
if( scroller.dataset.limit ){
var limit = parseInt( scroller.dataset.limit )
}
if( scroller.scrollHeight == height ){
limit++;
} else {
limit--;
}
if( scroller.scrollHeight > height || limit < 10 ){
scroller.scrollTo( 0, scroller.scrollHeight );
scroller.dataset.height = scroller.scrollHeight;
scroller.dataset.limit = limit;
setTimeout( function(){
recursiveScroll( scroller );
}, 175 );
} else {
console.log( 'Scrolling done.' );
var days = parseInt( msgList.querySelector('li #days').value );
if( days < 0 ){
days = 30;
}
console.log('Start auto check.');
msgList.removeChild( msgList.querySelector('#controls') );
checker( days );
}
}
function checker( days ){
var lis = msgList.querySelectorAll('li');
var d, n, t;
lis.forEach( function( item ){
t = item.querySelector('time');
if( t ){
d = new Date( t.dateTime );
d = d.getTime();
n = new Date();
n = n.getTime() - ( 86400000 * days );
if( d < n ){
item.querySelector('label').click();
}
}
} );
console.log('Done auto check.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment