Add Trailing Slash to Narou URL

なろうの小説トップページのURLが「/n0001a」「/n0001a/?p=1」のとき「/n0001a/」へリダイレクトする。

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Add Trailing Slash to Narou URL
// @namespace    haaarug
// @version      1.2
// @description  なろうの小説トップページのURLが「/n0001a」「/n0001a/?p=1」のとき「/n0001a/」へリダイレクトする。
// @license      CC0
// @match        https://ncode.syosetu.com/*
// @run-at       document-start
// ==/UserScript==

(function () {
    'use strict';

    const url = new URL(window.location.href);

    // クエリが ?p=1 のとき → クエリ削除してそのままリダイレクト(スラッシュは追加しない)
    if (url.search === '?p=1') {
        url.search = '';
        window.location.replace(url.toString());
        return;
    }

    // クエリがない & pathname がスラッシュで終わっていないとき → スラッシュ追加
    if (!url.search && !url.pathname.endsWith('/')) {
        url.pathname += '/';
        window.location.replace(url.toString());
    }

    // それ以外(クエリがある or スラッシュ付き)は何もしない
})();