Jump to content

User:Þjarkur/Not latest contributions.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.
/**

  Only shows contributions where the user is not the last contributor to that page.
  (Note: Works best on the first page of the contributions, 
   later pages may show articles where the user has made later edits)
  CC0

*/
$.ready.then(function () {
	var url = $('#pt-mycontris a').attr('href')
	$('#pt-mycontris').append(` <a href="${url}?not_latest=true">(not latest)</a>`)

	if (mw.util.getParamValue('not_latest') && mw.config.get('wgCanonicalSpecialPageName') === 'Contributions') {

		let last_contributor_list = []

		$('.mw-uctop').each(function () {
			last_contributor_list.push($(this).closest('li').find('.mw-contributions-title').attr('href'))
		})

		let already_seen = []

		$('.mw-contributions-list > li .mw-contributions-title').each(function () {
			if (
				last_contributor_list.includes($(this).attr('href')) ||
				already_seen.includes($(this).attr('href'))
			) {
				$(this).closest('li').remove()
			} else {
				already_seen.push($(this).attr('href'))
			}
		})
	}
})