MediaWiki:Gadget-NotifCountTitle.js

    来自真佛百科
    蓮花祖泉讨论 | 贡献2024年3月4日 (一) 21:15的版本 (导入1个版本)
    (差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

    注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

    • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
    • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
    • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
    • Opera:Ctrl-F5
    // 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');
    				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
    });