Greasy Fork

Backpack.tf Keyboard Navigator

Allows for the use of the left and right keyboard keys to navigate backpack.tf classifieds and premium search pages.

当前为 2019-06-25 提交的版本,查看 最新版本

// ==UserScript==
// @name         Backpack.tf Keyboard Navigator
// @version      1.0
// @description  Allows for the use of the left and right keyboard keys to navigate backpack.tf classifieds and premium search pages.
// @author       Matt-RJ
// @match        *backpack.tf/*
// @namespace https://greasyfork.org/users/313414
// ==/UserScript==

window.onkeydown = function(e) {

    var prevButton = document.getElementsByClassName('fa fa-angle-left')[0];
    var nextButton = document.getElementsByClassName('fa fa-angle-right')[0];

    var isFirstPage = prevButton.parentElement.parentElement.className == "disabled";
    var isLastPage = nextButton.parentElement.parentElement.className == "disabled";

    if (e.keyCode == 37) { // Left arrow press
        if (prevButton !== undefined && !isFirstPage) {
            console.log("Opening previous page...");
            prevButton.click();
        }
    }

    else if (e.keyCode == 39) { // Right arrow press
        if (nextButton !== undefined && !isLastPage) {
            console.log("Opening next page...");
            nextButton.click();
        }
    }
}