1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ページ移動するブックマークレット

Last updated at Posted at 2022-02-17

動機

  • 最下部までスクロールしないでもページをめくりたい
  • URL末尾の「/5/」や「?page=5」を「6」にしたり「4」にしたり、入力したり
  • 各種サイトの「隣のページ/エントリ/ユーザー」も見たい

二種類

  1. 1ページすすむ・もどる
  2. 1ページすすむ・もどる + 任意のページ入力

コード

1. 1ページすすむ・もどる

ブックマーク用

javascript:(()=>{const url=location.href;const res=url.match(/(\=|\/|\?)(\d{1,10})\/?$/)??!1;if(res){const n=parseInt(res[2],10);const tg=confirm('【OK】: next page\nor 【Cancel】: prev page')?n+1:n-1;let newUrl=url.replace(res[0],res[0].replace(n,tg));window.location.href=newUrl}else{alert('not work on this page.')}})()

全体

  function turn1page()
  {
    const url = location.href;
    const res = url.match( /(\=|\/|\?)(\d{1,10})\/?$/ ) ?? false;
    if( res ) {
      const n = parseInt(res[2], 10);
      const tg = confirm('【OK】: next page\nor 【Cancel】: prev page') ? n+1 : n-1;
      let newUrl = url.replace( res[0] , res[0].replace( n, tg ) );
      window.location.href = newUrl;
    } else {
      alert( 'not work on this page.' );
    }
  }

2. 1ページすすむ・もどる + 任意のページ入力

ブックマーク用

javascript:(()=>{const url=location.href;const res=url.match(/(\=|\/|\?)(\d{1,10})\/?$/)??!1;if(res){const n=parseInt(res[2],10);let tg=confirm(%27OK: Next Page\nor Cancel: Input%27)?(n+1):window.prompt(%27 Input page num! 】\n\nor Cancel: Previous Page%27)??(n-1);let newUrl=url.replace(res[0],res[0].replace(n,encodeURIComponent(tg)));window.location.href=newUrl}else{alert(%27not work on this page.%27)}})()

全体

  function turnPageWithInput()
  {
    const url = location.href;
    const res = url.match( /(\=|\/|\?)(\d{1,10})\/?$/ ) ?? false;
    if( res ) {
      const n = parseInt(res[2], 10);
      let tg = confirm( '【OK】: Next Page\nor 【Cancel】: Input' ) ? (n+1) :
        window.prompt( '【 Input page num! 】\n\nor 【Cancel】: Previous Page' ) ?? (n-1);
      let newUrl = url.replace( res[0] , res[0].replace( n, encodeURIComponent(tg) ) );
      window.location.href = newUrl;
    } else {
      alert( 'not work on this page.' );
    }
  }

利用方法

Android版Chromeはブックマーク欄のタップでは動作しないため、自分でつけたブクマ名「いどう」等をアドレスバーに手入力し、サジェスト表示された当該ブクマをタップすると動きます


読んで下さってありがとうございます:melon:

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?