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.
I see, ty.

I've also noticed the sound does repeat if you change the page on the forum unless you read the alert or e.g. you have 5 alerts and you read them (visit the linked alert page) one by one, you always get the notification.

How would you add a check so it remembers that u've got the sound once? By cookie? If so, how could that work?
(2017-02-18, 11:09 PM)thelovelyone Wrote: [ -> ]I see, ty.

I've also noticed the sound does repeat if you change the page on the forum unless you read the alert or e.g. you have 5 alerts and you read them (visit the linked alert page) one by one, you always get the notification.

How would you add a check so it remembers that u've got the sound once? By cookie? If so, how could that work?


It's also easy, but I can't say for sure since I didn't test it out, so let me know the result. I suggest to use this small cookie library, as it's compatible with many browsers. In fact I use it in my site too.

https://github.com/js-cookie/js-cookie


1. Extract the file to the "/jscripts" of the  forum. If there is no jscripts folder, simply make a new one in the root directory of the forum.
2. Add the following line to the "headerinclude" template

<script src="jscripts/js.cookie.js"></script>

3. Use the following code in the header_welcomeblock_member template.

<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');
}


</script>

It considered here x scenarios. 

1. the user visits the site, see no notification, the sound doesn't play at all
2. the user visits the site, see x number of notifications, the sound play, the cookie sets to x
3. the user visits the site, see x number of notifications again, x in the notifications is compared with x in the cookie, since != is used, the condition isn't fulfilled, and thus sound doesn't play
4. the user visits the site, read the notifications, thus making the notification number to zero, and then visits again, since there is no new notification, the sound doesn't play at all, the cookie is removed.

I added the fontawesome icons to myalerts icons in the usercp. Use this in myalerts_usercp_nav. since I use standard class names, it doesn't matter what theme is being used, it comes out fine as long as the theme uses the standard names as well. 


[Image: CMGKSUl.png]

<tr>
    <td class="thead tcat_menu tcat_collapse">
        <div class="expcolimage">
            <img src="{$theme['imgdir']}/collapse{$collapsedimg['usercpalerts']}.png"
                 id="usercpalerts_img"
                 class="expander" alt="[-]" title="[-]"/>
        </div>
        <div>
			<span class="smalltext">
				<strong>{$lang->myalerts_usercp_nav}</strong>
			</span>
        </div>
    </td>
</tr>
<tbody style="{$collapsed['usercpalerts_e']}" id="usercpalerts_e">
<!-- -->
	<!-- usercp_nav_myalerts-->
	<td class="trow1 smalltext">
        <a href="alerts.php" class="usercp_nav_item"><i style="font-size: 14px;" class="fa fa-exclamation-triangle fa-fw"></i> {$lang->myalerts_usercp_nav_alerts}</a>
    </td>
</tr> 
<!-- -->
<tr>
    <td class="trow1 smalltext">
        <a href="alerts.php?action=settings"
           class="usercp_nav_item usercp_nav_options"><i style="font-size: 14px;" class="fa fa-cog fa-fw"></i> {$lang->myalerts_usercp_nav_settings}</a>
    </td>
</tr>

<!-- -->
<tr>
    <td class="trow1 smalltext">
        <a href="alerts.php?action=delete_read&amp;my_post_key={$mybb->post_code}"
           onclick="return confirm('{$lang->myalerts_delete_read_confirm}')"
           class="usercp_nav_item"><i style="font-size: 14px;" class="fa fa-trash-o fa-fw"></i> {$lang->myalerts_usercp_nav_delete_read}</a>
    </td>
</tr>

<!-- -->
<tr>
    <td class="trow1 smalltext">
        <a href="alerts.php?action=delete_all&amp;my_post_key={$mybb->post_code}"
           onclick="return confirm('{$lang->myalerts_delete_all_confirm}')"
           class="usercp_nav_item"><i style="font-size: 14px;" class="fa fa-times-circle fa-fw"></i> {$lang->myalerts_usercp_nav_delete_all}</a>
    </td>
</tr>
</tbody>
Hm, i don't get any notification now anymore.

I call the cookie script like this: <script src="/forum/jscripts/js-cookie-master/src/js.cookie.js"></script>
is that correct?


About that faicons, they show up, but the default icons are still there.
(2017-02-19, 12:48 AM)thelovelyone Wrote: [ -> ]Hm, i don't get any notification now anymore.

I call the cookie script like this: <script src="/forum/jscripts/js-cookie-master/src/js.cookie.js"></script>
is that correct?


About that faicons, they show up, but the default icons are still there.

That's too long. It's just this. Download this file
https://raw.githubusercontent.com/js-coo....cookie.js
extract it into the jscripts folder, but make sure the file's name is js.cookie.js
file's full address is this
yourforum.com/jscripts/js.cookie.js
don't include the forwarding slash at the beginning of the script. so it should be this
jscripts/js.cookie.js


<script src="jscripts/js.cookie.js"></script>

If it still doesn't work, then change 

Cookies.remove('notification_sound'); 
TO
Cookies.set('notification_sound', 0, { expires: 365 });

well technically they should be removed, because I removed the class names to the background images. did you refresh the page? f12->empty cache and hard reload on refresh icon on chrome.
Unfortunately none of this solutions worked.

I changed the files and path, so its: <script src="forum/jscripts/js.cookie.js"></script>
since my forum is located under root/forum/

and changing that code didnt help either.

Also i usually hard refresh anyway, after making changes, so the last thing didn't help too.
(2017-02-19, 01:15 AM)thelovelyone Wrote: [ -> ]Unfortunately none of this solutions worked.

I changed the files and path, so its: <script src="forum/jscripts/js.cookie.js"></script>
since my forum is located under root/forum/

and changing that code didnt help either.

Also i usually hard refresh anyway, after making changes, so the last thing didn't help too.

I am going to check the sound script now, but the frontawesome one should work fine.

https://nucuta.com/community/usercp.php
see the proof
[Image: CMGKSUl.png]

As you can see the background images apply to tags with these classes, hence removing these classes from the anchor tags, will make the icons to disassociate with them. 

[Image: Vvk2jvQ.png]

I just saw this. I forgot to use one parenthesis

CHANGE
if(num != Cookies.get('notification_sound'){
TO
if(num != Cookies.get('notification_sound')){
Thanks, that worked (cookie one).

Idk still about the icons though. LIke i only replace the code u sent me with the existing alerts user cp nav template, am i supposed to do smth else?
It should be 
myalerts_usercp_nav
Home » Template Sets » <YOUR THEME> Templates » Edit Template: myalerts_usercp_nav

NOT 
usercp_nav
Home » Template Sets » <YOUR THEME> Templates » Edit Template: usercp_nav
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.
(2017-02-19, 01:59 AM)thelovelyone Wrote: [ -> ]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.


Here ya go, if you have font awesome on your website, this will work RE:myalerts_usercp_nav

<tbody style="{$collapsed['usercpalerts_e']}" id="usercpalerts_e">
<tr>
    <td class="trow1 smalltext">
        <a href="alerts.php" class="usercp_nav_item usercp_nav_myalerts"><i style="font-size: 14px;" class="fa fa-search-plus fa-fw"></i>{$lang->myalerts_usercp_nav_alerts}</a>
    </td>
</tr>
<tr>
    <td class="trow1 smalltext">
        <a href="alerts.php?action=settings" class="usercp_nav_item usercp_nav_options"><i style="font-size: 14px;" class="fa fa-cog fa-fw"></i>{$lang->myalerts_usercp_nav_settings}</a>
    </td>
</tr>
<tr>
    <td class="trow1 smalltext">
        <a href="alerts.php?action=delete_read&amp;my_post_key={$mybb->post_code}"
           onclick="return confirm('{$lang->myalerts_delete_read_confirm}')"
           class="usercp_nav_item usercp_nav_myalerts_delete_read"><i style="font-size: 14px;" class="fa fa-trash fa-fw"></i>{$lang->myalerts_usercp_nav_delete_read}</a>
    </td>
</tr>
<tr>
    <td class="trow1 smalltext">
        <a href="alerts.php?action=delete_all&amp;my_post_key={$mybb->post_code}"
           onclick="return confirm('{$lang->myalerts_delete_all_confirm}')"
           class="usercp_nav_item usercp_nav_myalerts_delete_all"><i style="font-size: 14px;" class="fa fa-times-circle fa-fw"></i>{$lang->myalerts_usercp_nav_delete_all}</a>
    </td>
</tr>
</tbody>