OurPagination

Operate Torn's pagination using left-right arrow keys

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         OurPagination
// @namespace    dotp.cc
// @version      0.2
// @description  Operate Torn's pagination using left-right arrow keys
// @author       Lenin (2199004)
// @match        https://www.torn.com/hospitalview.php*
// @match        https://www.torn.com/jailview.php*
// @match        https://www.torn.com/page.php?sid=UserList*
// @match        https://www.torn.com/forums.php*
// @match        https://www.torn.com/bounties.php*
// @match        https://www.torn.com/comics.php*
// @match        https://www.torn.com/properties.php*
// @match        https://www.torn.com/joblist.php*
// @match        https://www.torn.com/messages.php*
// @match        https://www.torn.com/amarket.php*
// @match        https://www.torn.com/page.php?sid=travel*
// @match        https://www.torn.com/personals.php*
// @match        https://www.torn.com/page.php?sid=gallery*
// @license      MIT
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keydown', function(e) {
        // Check if the focus is on a text input or textarea
        if (document.activeElement.tagName === 'INPUT' || document.activeElement.tagName === 'TEXTAREA' || document.activeElement.isContentEditable) {
            return; // Do nothing if the user is focused on an input box or textarea
        }

        // Check if the right arrow key is pressed
        if (e.keyCode === 39) { // 39 is the keycode for the right arrow key
            let rightPaginationLink = document.querySelector('i.pagination-right').parentNode;
            if (rightPaginationLink) {
                rightPaginationLink.click();
            }
        }
        // Check if the left arrow key is pressed
        else if (e.keyCode === 37) { // 37 is the keycode for the left arrow key
            let leftPaginationLink = document.querySelector('i.pagination-left').parentNode;
            if (leftPaginationLink) {
                leftPaginationLink.click();
            }
        }
    });
})();