User:Ultimate Dark Carnage/fandomdesktop.js

/* * CategorizedNotifications * @description Separates notifications into five categories based on where they came from for easier navigation * @author Joritochip * * NOTE: This is still a work in progress and will be improved upon, so you * should import directly from here rather than copypasting */

$(function {	if (mw.config.get('skin') !== 'fandomdesktop' || window.CategorizedNotificationsLoaded === true) return;	window.CategorizedNotificationsLoaded = true;	console.log("Running CategorizedNotifications");	var categoryMap = [		// ['icon-name', ['array', 'of', 'notification', 'types']],		['bell', ['announcement']],		['envelope', ['message-wall-post', 'message-wall-reply', 'talk-page-message']],		['comment', ['article-comment-reply', 'article-comment-at-mention', 'article-comment-reply-at-mention']],		['blocks', ['discussion-reply', 'discussion-upvote-post', 'post-at-mention', 'thread-at-mention']],		['more', []]	];	function translateCategory(attr) {		attr = attr.slice(19);		var category = 'more';		categoryMap.forEach(function(array) { if (array[1].indexOf(attr) !== -1) { category = array[0]; }		});		return category;	}	function beginObserving(tabber) {		var hasOpened = false;		var container = $(".global-navigation__bottom .notifications");		new MutationObserver(function { var content = $('.NotificationsDropdown-module_tabber__1qKxW'); if (!hasOpened && content.length) { hasOpened = true; content.hide; tabber.appendTo(content.parent[0]); }			var notifications = $('.wds-tabber:not(.categorized-notifications) .NotificationCard-module_card__2YXOh'); notifications.each(function(index, notification) {				notification = $(notification);				var tabName = translateCategory(notification.attr('data-tracking-label'));				var tab = $('.categorized-notifications-'+tabName+' ul');				if (tab.length) {					notification.appendTo(tab);				}			}); var scroll = $('.NotificationsDropdown-module_scrollableListWrapper__2m4TQ ul'); if (notifications.length && scroll.length) { scroll[0].dispatchEvent(new CustomEvent('scroll')); }		}).observe(container[0], { childList: true, subtree: true });	}	mw.hook('dev.wds').add(function(wds) { var tabber = $(' '); var wrapper = $(' ').appendTo(tabber); var labels = $('').appendTo(wrapper); categoryMap.forEach(function(array, index) {			var icon = array[0];			var label = $(' ').appendTo(labels);			var tab = $('  You have no notifications. Check back later for new notifications. </ul> ').appendTo(tabber);		}); $('<style id="categorized-notifications"> ').text('.notifications .categorized-notifications .NotificationsZeroState-module_container__3Y2qX{display:none}.notifications .categorized-notifications .NotificationsZeroState-module_container__3Y2qX:only-child{display:block}.notifications .categorized-notifications{display: flex;flex-direction: column;height: 100%}.notifications .categorized-notifications .wds-tab__content{height: 100%;overflow: hidden}').appendTo('body'); beginObserving(tabber); });	if (!window.dev || !window.dev.wds) {       importArticle({ type: 'script', article: 'u:dev:MediaWiki:WDSIcons/code.js' });   }    importArticle( { type: "script", article: "u:dev:MediaWiki:PortableCSSPad/code.js" } ); });