Skip to content

Instantly share code, notes, and snippets.

@samogot
Last active July 11, 2022 16:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samogot/355ba0ff414a6a9551baff500b1af60e to your computer and use it in GitHub Desktop.
Save samogot/355ba0ff414a6a9551baff500b1af60e to your computer and use it in GitHub Desktop.
Button for counting unread messages
How to use:
I asume you have a channel with lot of unread messages. You can see blue line about 50+ unread messages.
1. Click left side of blue line. DO NOT click right side (mark as read)
2. There will appear bottom green line, about available new messages.
Unlike standart behaviour, this plugin adds new functions to this green line
3. Click right side of green line ("Count unread messages"). DO NOT click left side (this also will mark everything as read)
Plugin will start recursively load unread messages to count them. The more there are unread messages, the more will be loading time.
4. If you want to stop loading process, click right side of green line once more ("Cancel")
5. If there are more than 200 unread messages, you will end up with random scrolling position.
You need to click left side of blue line once more, to start reading from the begining of unread messages
(this will reset the messages counter to 25+ again, but it is ok, as you already know exact number)
Availiable locales: ru, ua, en, nl
Changelog:
1.2
- Add Dutch localization (thanks to HoLLy#2750)
//META{"name":"CountUnread"}*//
var CountUnread = function () {};
CountUnread.prototype.getName = function() {
return "CountUnread";
};
CountUnread.prototype.getDescription = function() {
return "Button for counting unread messages";
};
CountUnread.prototype.getVersion = function() {
return "1.2";
};
CountUnread.prototype.getAuthor = function() {
return "Samogot";
};
CountUnread.prototype.start = function() {
var cancelTO;
var localeStr;
switch(navigator.language) {
case 'ru':
case 'ru_RU':
localeStr = {
load: 'Посчитать непрочитанные',
cancel: 'Отмена',
};
break;
case 'uk':
case 'uk_UA':
localeStr = {
load: 'Підрахувати непрочитані',
cancel: 'Відміна',
};
break;
case 'nl':
case 'nl_BE':
localeStr = {
load: 'Tel ongelezen berichten',
cancel: 'Annuleer',
};
break;
default:
localeStr = {
load: 'Count unread messages',
cancel: 'Cancel',
};
break;
}
function loadDownRecurcive() {
cancelTO = undefined;
if ($('.jump-to-present-bar').length) {
$('.has-more:last-child button').click();
cancelTO = setTimeout(loadDownRecurcive, 50)
}
}
function setUpLoadButton(){
$('.jump-to-present-bar button:eq(1)').text(localeStr.load).click(onLoadButtonClick);
}
function setUpCancelButton(){
$('.jump-to-present-bar button:eq(1)').text(localeStr.cancel).click(onCancelButtonClick);
}
function onLoadButtonClick(){
loadDownRecurcive();
setUpCancelButton();
return false;
}
function onCancelButtonClick(){
if(cancelTO) clearTimeout(cancelTO);
cancelTO = undefined;
$('.new-messages-bar button:eq(0)').click();
return false;
}
$(document).on('click.lau', '.new-messages-bar button:first-child', function(e){
setTimeout(function() {
if($('.new-messages-bar button:eq(0)').text().indexOf('+') >= 0)
setUpLoadButton();
}, 500);
});
};
CountUnread.prototype.load = function() {};
CountUnread.prototype.unload = function() {
$(document).off("click.lau");
};
CountUnread.prototype.stop = function() {
$(document).off("click.lau");
};
CountUnread.prototype.getSettingsPanel = function() {
return null;
};
CountUnread.prototype.onMessage = function() {
};
CountUnread.prototype.onSwitch = function() {
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment