GoToNextPage

A shortcut (ctrl+alt+n) to next-button of pagination. google.com and amazon.com are tested.

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

Advertisement:

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!)

Advertisement:

// ==UserScript==
// @name         GoToNextPage
// @namespace    com.gmail.fujifruity.greasemonkey
// @version      0.7
// @description  A shortcut (ctrl+alt+n) to next-button of pagination. google.com and amazon.com are tested.
// @author       fujifruity
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

{
    'use strict';

    // Keywords to filter buttons.
    const keywords = [
        'next', 'Next','NEXT', '>',
        '次', 'つぎ', '>'
    ]
    window.addEventListener('keydown', event => {
        if (["INPUT", "TEXTAREA"].includes(event.target.tagName)) return
        if (event.key != 'n' || !event.altKey || !event.ctrlKey) return

        const queries = [
            '[role*="navigation"]',
            '[role*="pagination"]',
            '[role*="pagenation"]',
            '[class*="navigation"]',
            '[class*="pagination"]',
            '[class*="pagenation"]',
            '[class*="pager"]'].join(',')
        const paginations = [...document.querySelectorAll(queries)]
        console.log('paginations', paginations)

        const nextButtons = paginations.map(pg => {
            const descendants = [...pg.querySelectorAll('*')]
            return descendants.reverse().find(e =>
                // is visible
                e.offsetParent != null
                // and has any keyword
                && keywords.some(keyword =>
                                 e.innerText?.includes(keyword)
                                 || e.getAttribute('aria-label')?.includes(keyword) )
            )
        })
        console.log('nextButtons', nextButtons)

        // Click them all.
        nextButtons.forEach(e => e?.click())

        // If it did not work, click the first clickable descendant.
        nextButtons.forEach(e => {
            const isClickable = e => e.tagName == 'A' || e.getAttribute('onclick')
            const clickable = [...e.querySelectorAll('*')].find(isClickable)
            console.log('clickable', clickable)
            clickable.click()
        })
    })
}