מדיה ויקי:Gadget-NotifCountTitle.js

מתוך אקו-ויקי, מקום מפגש בנושאי אקולוגיה, חברה וכלכלה.
קפיצה לניווט קפיצה לחיפוש

הערה: לאחר השמירה, ייתכן שיהיה צורך לנקות את זיכרון המטמון (cache) של הדפדפן כדי להבחין בשינויים.

  • פיירפוקס / ספארי: להחזיק את המקש Shift בעת לחיצה על טעינה מחדש (Reload), או ללחוץ על צירוף המקשים Ctrl-F5 או Ctrl-R (במחשב מק: ⌘-R).
  • גוגל כרום: ללחוץ על צירוף המקשים Ctrl-Shift-R (במחשב מק: ⌘-Shift-R).
  • אינטרנט אקספלורר: להחזיק את המקש Ctrl בעת לחיצה על רענן (Refresh), או ללחוץ על צירוף המקשים Ctrl-F5.
  • אופרה: לפתוח תפריט ← הגדרות (במחשב מק: Opera ← העדפות) ואז ללחוץ על פרטיות ואבטחה ← מחק היסטוריית גלישה ← Cached images and files.
// Author: Eee888
$(document).ready( function(){
	
		var initialDocTitle = document.title;
		var messageNotification = 0, alertNotification = 0;
	
		function addNotificationCounterToDocumentTitle(notificationType, newCountValue){
			
			if (!notificationType) { //first time the page is loaded
			
				var notificationElmArr = $('.mw-echo-notifications-badge').filter(function() { return $(this).closest('#pt-notifications-watchlist').length === 0; });
				for(var elemIndex = 0; elemIndex < notificationElmArr.length ; elemIndex++){
					
					var elementNotificationNumber = parseInt($(notificationElmArr[elemIndex]).data('counter-num'));
					notificationElmArr[elemIndex].parentElement.id.indexOf('alert') > -1 ? 
						alertNotification += elementNotificationNumber : messageNotification += elementNotificationNumber;
				}
			} else {// it's an update
			
				'alert' == notificationType ? alertNotification = newCountValue : messageNotification = newCountValue;
			}
			var notificationToTitle = messageNotification + alertNotification;
			document.title = notificationToTitle !== 0 ? '('+mediaWiki.language.convertNumber(notificationToTitle)+') ' + initialDocTitle : initialDocTitle;
		}
		addNotificationCounterToDocumentTitle(); //for the initial page load
		mw.hook('ext.echo.badge.countChange').add(addNotificationCounterToDocumentTitle); //for any other notification counter change
});