// ==UserScript== // @name Backpack.tf Keyboard Navigator // @version 1.04 // @description Allows for the use of the left and right keyboard keys to navigate backpack.tf classifieds and premium search pages. // @author Matt-RJ // @include /https?://(www\.)?backpack\.tf/.+/ // @namespace https://greasyfork.org/users/313414 // @downloadURL none // ==/UserScript== let openingNewPage = false; let isFirstPage; let isLastPage; window.onkeydown = (e) => { const prevButton = document.getElementsByClassName('fa fa-angle-left')[0]; const nextButton = document.getElementsByClassName('fa fa-angle-right')[0]; try { isFirstPage = prevButton.parentElement.parentElement.className == "disabled"; isLastPage = nextButton.parentElement.parentElement.className == "disabled"; } catch(error) { return; } if (!openingNewPage) { if (e.keyCode === 37) { // Left arrow press if (prevButton && !isFirstPage) { console.log("Opening previous page..."); prevButton.click(); openingNewPage = true; } } else if (e.keyCode === 39) { // Right arrow press if (nextButton && !isLastPage) { console.log("Opening next page..."); nextButton.click(); openingNewPage = true; } } } };