Add Trailing Slash to Narou URL

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

  1. // ==UserScript==
  2. // @name Add Trailing Slash to Narou URL
  3. // @namespace haaarug
  4. // @version 1.2
  5. // @description なろうの小説トップページのURLが「/n0001a」「/n0001a/?p=1」のとき「/n0001a/」へリダイレクトする。
  6. // @license CC0
  7. // @match https://ncode.syosetu.com/*
  8. // @run-at document-start
  9. // ==/UserScript==
  10.  
  11. (function () {
  12. 'use strict';
  13.  
  14. const url = new URL(window.location.href);
  15.  
  16. // クエリが ?p=1 のとき → クエリ削除してそのままリダイレクト(スラッシュは追加しない)
  17. if (url.search === '?p=1') {
  18. url.search = '';
  19. window.location.replace(url.toString());
  20. return;
  21. }
  22.  
  23. // クエリがない & pathname がスラッシュで終わっていないとき → スラッシュ追加
  24. if (!url.search && !url.pathname.endsWith('/')) {
  25. url.pathname += '/';
  26. window.location.replace(url.toString());
  27. }
  28.  
  29. // それ以外(クエリがある or スラッシュ付き)は何もしない
  30. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址