CrazyJeux / SmoothPost

// ==UserScript==
// @name        SmoothPost
// @namespace   CrazyJeux/Daring-Do
// @author		CrazyJeux/Daring-Do
// @match		*://www.jeuxvideo.com/forums/*
// @description Les rafraîchissements de la page ne scrollent plus vers votre dernier message posté.
// @version		2
// @grant       none
// ==/UserScript==

var changeColor = false;
var color = "royalblue";
var removeHash = true;
var fixScroll = false;

function getCurrentPageNumber() {
	return parseInt(String(window.location.href).split('-')[3], 10);
}

function toCall() {
	if (window.location.hash && window.location.hash.substring(0, 6) === "#post_") {
		//If the message doesn't exist on this page, then it's probably on the next page
		var hash = window.location.hash.substring(1);
		var element = document.getElementById(hash);
		//Highlight the message
		if (changeColor === true && element !== null) {
			element.style.backgroundColor = color;
		}
		//Remove the hash
		if (removeHash === true) {
			history.pushState("", document.title, window.location.pathname + window.location.search);
		}
		//Scroll a bit upwards (because of the black menu bar)
		if (fixScroll === true) {
			var savedPosition = window.pageYOffset;
			window.scrollTo(0, savedPosition - 100);
		}
	}
}

toCall();

//Respeed
addEventListener('instantclick:newpage', toCall);