eXo-Necro / RealityGaming | Change de page avec les touches directionnelles

// ==UserScript==
// @name       RealityGaming | Change de page avec les touches directionnelles
// @namespace  https://realitygaming.fr
// @version    1.0
// @match      https://realitygaming.fr/*
// @match      http://realitygaming.fr/*
// @icon        https://i.imgur.com/B8O9rMU.png
// @grant      none
// ==/UserScript==


document.onkeydown = checkKey;

function checkKey(e) {

    if(window.location.href.indexOf('threads') != -1)
    {
    	e = e || window.event;
		//touche directionnelle droite
    	if (e.keyCode == '39') {
        	var pageIndex = window.location.href.indexOf("/page-");
        	if(pageIndex != -1)
        	{
                var pageNum = window.location.href.split('/page-')[1].split('#')[0];                           
            	window.location.href = window.location.href.substring(0,pageIndex) + '/page-' + (++pageNum);
        	}
        	else
        	{
            	window.location.href = window.location.href + 'page-2';
        	}
    	}
        //touche directionnelle gauche
    	else if (e.keyCode == '37') {
        	var pageIndex = window.location.href.indexOf("/page-");
        	if(pageIndex != -1)
        	{
            	var pageNum = window.location.href.split('/page-')[1].split('#')[0];     
            	window.location.href = window.location.href.substring(0,pageIndex) + '/page-' + (--pageNum);
        	}
    	}
	}
    if(window.location.href.indexOf('/forums/') != -1)
    {
    	e = e || window.event;
		//touche directionnelle droite
    	if (e.keyCode == '39') {
        	var pageIndex = window.location.href.indexOf("/page-");
        	if(pageIndex != -1)
        	{
                var pageNum = window.location.href.split('/page-')[1].split('#')[0];                           
            	window.location.href = window.location.href.substring(0,pageIndex) + '/page-' + (++pageNum);
        	}
        	else
        	{
            	window.location.href = window.location.href + 'page-2';
        	}
    	}
        //touche directionnelle gauche
    	else if (e.keyCode == '37') {
        	var pageIndex = window.location.href.indexOf("/page-");
        	if(pageIndex != -1)
        	{
            	var pageNum = window.location.href.split('/page-')[1].split('#')[0];     
            	window.location.href = window.location.href.substring(0,pageIndex) + '/page-' + (--pageNum);
        	}
    	}
	}
}