Jump to content

User:Greg Tyler/watchlist.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// TODO: Indicate to the user that pages are hidden from view.
addOnloadHook(function()
{
	// WatchlistConfig = unsafeWindow.WatchlistConfig, wgPageName = unsafeWindow.wgPageName;
WatchlistConfig = {
        ignorePages : {a:'Talk:Twitter',b:'Sports game'},
};
 
	// The current page is the Watchlist
	if (wgPageName == 'Special:Watchlist' && typeof(WatchlistConfig) !== 'undefined' && typeof(WatchlistConfig.ignorePages) !== 'undefined' && WatchlistConfig.ignorePages.length > 0)
	{
		nodes_to_remove = [];
 
		// The user is using Enhanced Changes
		if (window.toggleVisibility)
		{
			// TODO: Make this work.
		}
		else
		{
			days = document.getElementById('bodyContent').getElementsByTagName('ul');
 
			for (day in days)
			{
				change = days[day].firstChild;
				nodes_to_remove = [];
 
				while (change)
				{
					pages = []
					set_page_variable(5);
					set_page_variable(7);
					set_page_variable(8);
 
					ignore_pages = WatchlistConfig.ignorePages;
					for (ignore_page = 0; ignore_page < ignore_pages.length; ignore_page++)
					{
						for (page in pages)
						{
							if (ignore_pages[ignore_page] == pages[page].nodeValue)
								nodes_to_remove.push(change);
						}
					}
 
					change = change.nextSibling;
				}
 
				// TODO: Replace 'removeChild' with 'replaceChild'; the node is replaced with '&rarr;' with a negative margin so that it is shifted to the left.
				for (node = 0; node < nodes_to_remove.length; node++)
					days[day].removeChild(nodes_to_remove[node]);
			}
		}
	}
 
	function set_page_variable(node_index)
	{
		if (typeof(change.childNodes[node_index]) !== 'undefined' && change.childNodes[node_index].firstChild !== null)
			pages.push(change.childNodes[node_index].firstChild);
	}
});