Narou Index scroller

小説家になろうの目次で前後の章に移動するアイコンとナビをつける

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Narou Index scroller
// @namespace    http://ncode.syosetu.com/
// @version      0.7.3
// @description  小説家になろうの目次で前後の章に移動するアイコンとナビをつける
// @author       b2ox
// @match        *://ncode.syosetu.com/*
// @grant        none
// ==/UserScript==

{
    const chapters = $('div.index_box > div.chapter_title')
    const lst = $('<ul>')
    const n = chapters.length
    chapters.each((i,elm) => {
        const nav = $('<span>')
        const _up = $('<span>').text('⇧').attr('title','前章へ移動').css('cursor','pointer').click(() => {$('#ct'+(i-1))[0].scrollIntoView();window.scrollBy(0,-20);})
        const _down = $('<span>').text('⇩').attr('title','次章へ移動').css('cursor','pointer').click(() => {$('#ct'+(i+1))[0].scrollIntoView();window.scrollBy(0,-20);})
        lst.append($('<li>').text($(elm).text()).css('margin','1ex').css('cursor','pointer').click(() => {$('#ct'+i)[0].scrollIntoView();window.scrollBy(0,-20);}))
        if (i>0) nav.append(_up)
        if (i<n-1) nav.append(_down)
        $(elm).attr('id','ct'+i).prepend(nav)
    })
    if (n > 0) {
        const nhead = $('#novel_header');
        const style = window.getComputedStyle(nhead[0]);
        const lsize = parseFloat(style.lineHeight == 'normal' ? style.fontSize : style.lineHeight);
        const h = Math.min(lsize * (n + 3), $(window).height() * 0.6);
        const chNavi = $('<div id="chapter_navi"/>').css('margin','1em').css('border','solid 2px black').css('width','max-content').css('height',`${h}px`).css('overflow','scroll');
        chNavi.append(lst)
        nhead.append(chNavi)
    }
}