Skip to content

Instantly share code, notes, and snippets.

@tdchien
Last active August 24, 2019 03:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tdchien/5f0a3c7d65202c047392a9a7197d9187 to your computer and use it in GitHub Desktop.
Save tdchien/5f0a3c7d65202c047392a9a7197d9187 to your computer and use it in GitHub Desktop.
Intergrate zalo with Rambox. This script is used update unread message for zalo on rambox
function checkUnread() {
console.log('checkUnread run');
var msg = document.getElementById("message-tab");
var img = msg.querySelector(".tab-red-dot");
if ((img == null) || (img == undefined)) {
// rambox.clearUnreadCount();
document.title = originalTitle;
return;
}
var src = img.attributes["src"];
src = src.value;
// src = 'https://zalo-chat-static.zadn.vn/message_notification_more.png';
t = src.replace(/https\:\/\/zalo-chat-static.zadn.vn\/message_notification_|png|\./g, '');
if (t === 'more') {
// rambox.setUnreadCount('5+')
document.title = "(5+) " + originalTitle
} else if (t >= 1) {
// rambox.setUnreadCount(e)
document.title = "(" + t + ") " + originalTitle
} else {
// rambox.clearUnreadCount()
document.title = originalTitle;
}
}
var originalTitle = document.title;
setInterval(checkUnread, 3000);
@Ash258
Copy link

Ash258 commented Jun 15, 2018

  • updateBadge is bad in many ways, no need to mix 2 types of if blocks
  • It should use if.. else ifs, because it save some time and processing time (no need to return out of function).
  • Dont use title hack.
  • === should be use everytime in JS, unless its not needed
  • Why do you use 5+ and not exact number??
  • Why do you use that image hack? What is it's purpose?
function updateBadge(e) {
    if (e === 0) {
        rambox.clearUnreadCount()
    } else if (e === 'more') {
        rambox.setUnreadCount('5+')
    } else if (e >= 1) {
        rambox.setUnreadCount(e)
    } else {
        rambox.clearUnreadCount()
    }
}

setInterval(checkUnread, 3000);

@tdchien
Copy link
Author

tdchien commented Jun 16, 2018

@Ash258 Thank for your commend. I updated script with remove updateBadge method and using if else for update unread count.

For your question:

Dont use title hack.
Why do you use 5+ and not exact number??
Why do you use that image hack? What is it's purpose?

I have no idea for get unread messsage of zalo serrvice. They have no api for get so I get unread count from image icon.

I checked rambox api for update unread count but it's not work with me. So that is why I have to hack title.

rambox.setUnreadCount
rambox.setUnreadCount

@qspeed
Copy link

qspeed commented Jun 19, 2018

Yeah... I think it work... Thanks, Chien ;)

@tdchien
Copy link
Author

tdchien commented Jun 25, 2018

@qspeed You're welcome

@D-Zen
Copy link

D-Zen commented Nov 3, 2018

@tdchien i used your code and add to custom code on rambox 64bit 0.6.2 but nothing happen. what's wrong?
image

@kiemnx
Copy link

kiemnx commented Jan 31, 2019

@D-Zen: Replace URL to https://chat.zalo.me. It worked for me.

@D-Zen
Copy link

D-Zen commented Aug 23, 2019

@D-Zen: Replace URL to https://chat.zalo.me. It worked for me.

@kiemnx i follow your guide but nothing worked for me?

@kiemnx
Copy link

kiemnx commented Aug 23, 2019

@D-Zen: Replace URL to https://chat.zalo.me. It worked for me.

@kiemnx i follow your guide but nothing worked for me?
![image](https://user-images.githubusercontent.com/30859070/63582724-21d04700-c589-11e9-9265-b305710f04af.png
Here is my configuration in Rambox.

@D-Zen
Copy link

D-Zen commented Aug 23, 2019

@D-Zen: Replace URL to https://chat.zalo.me. It worked for me.

@kiemnx i follow your guide but nothing worked for me?
![image](https://user-images.githubusercontent.com/30859070/63582724-21d04700-c589-11e9-9265-b305710f04af.png
Here is my configuration in Rambox.

@kiemnx my config same but nothing worked, please show your advanced code

@kiemnx
Copy link

kiemnx commented Aug 24, 2019

@D-Zen: Replace URL to https://chat.zalo.me. It worked for me.

@kiemnx i follow your guide but nothing worked for me?
![image](https://user-images.githubusercontent.com/30859070/63582724-21d04700-c589-11e9-9265-b305710f04af.png
Here is my configuration in Rambox.

@kiemnx my config same but nothing worked, please show your advanced code

Here my whole config, no need advanced code. I add _Custom Service and just fill https://chat.zalo.me in url box, after that I can login zalo by my account.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment