Next/Previous navigation with arrow keys!

Use the arrow keys to navigate the next or previous pages of tutorials ;)

目前為 2025-03-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Next/Previous navigation with arrow keys!
// @namespace   Violentmonkey Scripts
// @match       https://www.w3schools.com/*/*
// @grant       none
// @version     1.1
// @author      AvinashReddy3108 (assisted by ChatGPT)
// @license     WTFPL
// @description Use the arrow keys to navigate the next or previous pages of tutorials ;)
// ==/UserScript==

(function() {
    'use strict';

    document.addEventListener('keydown', function(event) {
        if (event.target.tagName.toLowerCase() === 'input' || event.target.tagName.toLowerCase() === 'textarea') {
            return; // Ignore inputs and textareas
        }

        // Container which has the next/previous buttons
        let container = document.querySelector("div.w3-clear.nextprev");
        if (!container) return;

        // The Next/Previous buttons
        let prevButton = container.querySelector("a.w3-left.w3-btn");
        let nextButton = container.querySelector("a.w3-right.w3-btn");

        if (event.key === 'ArrowLeft' && prevButton) {
            window.location.href = prevButton.href;
        } else if (event.key === 'ArrowRight' && nextButton) {
            window.location.href = nextButton.href;
        }
    });
})();