Thành viên:Unpear/hide pages in watchlist.js

Bách khoa toàn thư mở Wikipedia

Chú ý: Sau khi lưu thay đổi trang, bạn phải xóa bộ nhớ đệm của trình duyệt để nhìn thấy các thay đổi. Google Chrome, Firefox, Internet ExplorerSafari: Giữ phím ⇧ Shift và nhấn nút Reload/Tải lại trên thanh công cụ của trình duyệt. Để biết chi tiết và hướng dẫn cho các trình duyệt khác, xem Trợ giúp:Xóa bộ nhớ đệm.

// Greasemonkey version is the most recent.
// TODO: Indicate to the user that pages are hidden from view.
$(function()
{
	// WatchlistConfig = unsafeWindow.WatchlistConfig, wgPageName = unsafeWindow.wgPageName;
	
	// 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);
	}
});