MyBB Community Forums

Full Version: MyAlerts v2.0.4
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[quote pid='1264453' dateline='1487469594']
I did that. But its not very important anyway, i don't mind using the normal icons.

Btw, i noticed another thing about that sound notification:

E.g. You open the forum, you get a sound notification because you have 3 alerts, now you open open the alerts box and then click on one of the alerts. You get redirected to that alerted thread and then you hear the sound again. I suppose thats because its changing from "3" to "2", since you visited that page.

Can that be fixed somehow, because imagine you have 10+ alerts and you need to hear the sound everytime.

Altough i am going to sleep now, ill see later again. Bye.
[/quote]

oh I didn't take that scenario into the account when developing this.  Undecided
Anyway you can use these code. What this does, whenever the user clicked on one of the UNREAD messages, it takes the existing value stored in the cookie, and reduces it by one, since at the same time value in myalerts is reduced by one (when alert--unread is clicked), the user won't be notified again until they receive a new notification. 

<audio id="alert_sound" src="myalert.mp3"></audio>

<script>

var number = document.getElementsByClassName("myalerts")[0].innerHTML;
var num = number.match(/\d/g)[0];

if(num > 0){
  if(num != Cookies.get('notification_sound')){
    document.getElementById("alert_sound").play();
    Cookies.set('notification_sound', num, { expires: 365 });
   }
}else
{
    Cookies.remove('notification_sound');
}


var getAllClass = document.getElementsByClassName("alert--unread");
for (var i = 0; i < getAllClass.length; i++) 
{

getAllClass[i].addEventListener("click", function(){

Cookies.set('notification_sound', paraseInt(Cookies.get('notification_sound')) -1, { expires: 365 });

});

}

</script>
That doesn't work unfortunately, i still get the notifcation when there are more alerts.
Yeah it plays once right after clicking on the unread message, but that's all, then no matter how many alerts you have, unless you received a new one, you won't hear the sound again.
Let me illustrate by this example:

You open the forum, you then get the notification sound, since u have 2 new alerts, now you open the alert box and click on e.g. the "private message" alert, you get redirected to the pm and then you hear another notification again because it changed from 2 to 1, so in other words, the latest code didn't make a difference at all.

[Image: 360ba37396b14e0c8f13f97420badca6.png]
(2017-02-19, 11:31 AM)thelovelyone Wrote: [ -> ]Let me illustrate by this example:

You open the forum, you then get the notification sound, since u have 2 new alerts, now you open the alert box and click on e.g. the "private message" alert, you get redirected to the pm and then you hear another notification again because it changed from 2 to 1, so in other words, the latest code didn't make a difference at all.

[Image: 360ba37396b14e0c8f13f97420badca6.png]

Yeah that's what I said, it plays the sound once when you clicked on one of the unread alerts, but that's it. After that it doesn't play the sound at all no matter how many alerts you have unless you received a new one.
Well, my point is: you still hear the notification for all alerts (old/new doesnt matter). So it doesn't stop after the first clicked alert.

If you have 5 alerts, and you check them one by one, you always get the notification.
Once and for all, it's fixed. I tested this multiple times. But make sure to remove the existing cookie in 
chrome://settings/cookies
search for your website's name, then remove notification_sound


<!---AUDIO SCRIPT  -->

<audio id="alert_sound" src="audio/alert.wav"></audio>

<script>
	
var num =  {$mybb->user['unreadAlerts']};
if(num > 0){
		
	if(Cookies.get('notification_sound') < num)
	{
       if(num != Cookies.get('notification_sound'))
	   {
		   document.getElementById("alert_sound").play();
		   Cookies.set('notification_sound', num, { expires: 365 });
		}
	}
}else
{
    Cookies.set('notification_sound', 0, { expires: 365 });
}

</script>

<!---AUDIO SCRIPT  -->
Now it worked. Thank you very much! Smile
(2017-02-19, 12:44 PM)thelovelyone Wrote: [ -> ]Now it worked. Thank you very much! Smile

Big Grin  no problem.
Hey mate,

I got some problems at my forum.
I use MyAlerts to get notification when someone "tag/shoutout" me.

But It does not show up as notification on my icon. When someone send me a PM it shows.

I got two notifications icons, one alerts (alerts.php) and one messages (private.php)
Look at this picture below:

[Image: nLPlfOH.png]


<span class="alerts {$newAlertsIndicator} sep"><a href="{$mybb->settings['bburl']}/alerts.php" title="alerts" class="myalerts open_modal"
       data-selector="#myalerts_alerts_modal" rel="modal:open"><i style="color: #fff; font-size: 17px;" class="fa fa-bell-o  fa"></i> <span class="pms">{$mybb->user['pms_unread']} </span></a></span>	
	
<span class="sep"><a href="{$mybb->settings['bburl']}/private.php" title="Private messages"><i style="color: #fff; font-size: 17px;" class="fa fa-envelope fa"></i> <span class="pms">{$mybb->user['pms_unread']} </span></a></span>		

---------
CSS
--------

.pms {
	color: #FFFFFF;
	position: relative;
	top: -6px;
	left: -8px;
	padding: 2px 4px;
	border-radius: 3px;
	text-align: center !important;
	background: #c02020;
	color: #fff;
	-moz-border-radius: 2px;
	-webkit-border-radius: 2px;
	border-radius: 2px;
	text-shadow: 1px 1px 0px #882929;
	box-shadow: 0px 0px 0px 1px rgba(0, 0, 0, 0.25) inset, 0px 1px 4px rgba(0, 0, 0, 0.15);
	font-size: 12px;
}

.sep {
	margin-right: 1px;
	margin-top: 5px;
}


My forum is at http://www.forum.sledtell.com

Best regards
Kernan