Improved EH Reader

Simplifies the reader layout, adds a hotkey and preloads the next image. Inspired by Handy ExHentai, ExHentai - Preload next page, and G.E/EX Keyboard Navigation.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name          Improved EH Reader
// @namespace     karoo
// @version       2023.10.30
// @description   Simplifies the reader layout, adds a hotkey and preloads the next image. Inspired by Handy ExHentai, ExHentai - Preload next page, and G.E/EX Keyboard Navigation.
// @match         *://e-hentai.org/s/*
// @match         *://exhentai.org/s/*
// @run-at        document-end
// @noframes
// ==/UserScript==

function id(id) {return document.getElementById(id);}
if (window.top !== window.self) {return;}

// hide top panel and front page link
id('i1').firstElementChild.style.display = 'none';
id('i2').style.display = 'none';
document.getElementsByClassName('dp')[0].style.display = 'none';

// hide frame and fix margins
id('i1').style.background = 'none';
id('i1').style.border = 'none';
id('i1').style.margin = '0px auto 0px';

// add extra hotkeys
document.addEventListener('keydown', function(e) {
    // alt+right, next page if no future history
    if (e.altKey && e.keyCode == '39') {
        var currentUrl = window.location.href;
        history.forward();
        // if the url hasn't changed after 20ms, click next
        setTimeout(function() {
            if(currentUrl === window.location.href){
                id('next').click();
            }
        }, 20);
        e.preventDefault();
        return;
    }
    // ignore further hotkeys if a modifier is held
    if (e.shiftKey || e.ctrlKey || e.altKey || e.metaKey) {return;}
    // q key, return to gallery
    if (e.keyCode == '81') {
        id('i5').firstElementChild.firstElementChild.click();
        return;
    }
    // f key, search all galleries
    if (e.keyCode == '70') {
        var tagSearch = prompt('Search ' + document.location.hostname);
        if (tagSearch !== null) {
            window.location.href = '/?f_search=' + tagSearch;
        }
        return;
    }
});

// insert script to continue preloading beyond initial userscript load
// lookahead http request used to avoid creating an iframe
// doesn't preload when opening pages in new tabs
var script = document.createElement('script');
script.type = 'text/javascript';
script.innerHTML = `
var preload = new Image();
function preloadNext() {
    var href = document.getElementById('next').href;
    if (history.length <= 1 || href == window.location.href) {return;}
    var lookahead = new XMLHttpRequest();
    lookahead.open('GET', href, true);
    lookahead.onload = function(e) {
        var doc = document.implementation.createHTMLDocument('lookahead');
        doc.documentElement.innerHTML = lookahead.responseText;
        var nextImage = doc.getElementById('img').src;
        preload.src = nextImage;
    }
    lookahead.send();
}
var uweo = update_window_extents;
update_window_extents = function() {
    uweo();
    document.getElementById('img').addEventListener('load', preloadNext());
}`;
document.head.appendChild(script);