「小説家になろう」一括ダウンロード(IE系非対応)

    @@ -8,21 +8,23 @@ * @javascript_url */ -(()=>{ +(async ()=>{ -var sleep = time => new Promise(resolve=>setTimeout(resolve,time)); -var title = document.querySelector('title').textContent.split(' - ')[0]; + const sleep = time => new Promise(resolve=>setTimeout(resolve,time)); -var test = async ()=>{ - var noArr = Array.from(document.querySelectorAll('select[name=no] option')); - var noEnd = document.querySelector('select[name=no]').value; - var hankaku = document.querySelector('select[name=hankaku]').value; - var code = document.querySelector('select[name=code]').value; - var kaigyo = document.querySelector('select[name=kaigyo]').value; - var param = {no:1,hankaku,code,kaigyo}; - var url = document.querySelector('form[name=dl]').action; - var blob = Array.from(title+'\r\n'); - for ( var x of noArr ){ + const title = document.querySelector('title').textContent.split(' - ')[0]; + const noArr = Array.from(document.querySelectorAll('select[name=no] option')); + const noEnd = document.querySelector('select[name=no]').value; + const hankaku = document.querySelector('select[name=hankaku]').value; + const code = document.querySelector('select[name=code]').value; + const kaigyo = document.querySelector('select[name=kaigyo]').value; + + const param = {no:1,hankaku,code,kaigyo}; + const url = document.querySelector('form[name=dl]').action; + + let blob = Array.from(title+'\r\n'); + + for ( let x of noArr ){ param.no =x.value; response = await fetch( url, @@ -36,17 +38,13 @@ if ( x.value == noEnd ) break; await sleep(5000); }; - return blob; -}; -test().then(blob=>{ - var a = document.createElement('a'); + const a = document.createElement('a'); a.href = URL.createObjectURL(new Blob(blob), { type: "text/plain" }); a.download = title+'.txt'; document.body.insertAdjacentElement('beforeend', a); a.click(); -}); })()
  • /*
     * @title 「小説家になろう」一括ダウンロード(IE系非対応)
     * @description テキストファイルダウンロードページで、「部分番号」の指定を末尾にして先頭の部分からダウンロード。その後、txt形式で保存します。サーバに配慮して各部分は5秒ごとにリクエストを飛ばしますので、時間がかかります。なお、利用規約14条17に抵触するかもしれないので、自己責任で使ってください。
     * @__caution__ https://syosetu.com/site/rule/
     * @include https://ncode.syosetu.com/txtdownload/top/ncode/*
     * @license public domain
     * @require 
     * @javascript_url
     */
    
    (async ()=>{
    
      const sleep = time => new Promise(resolve=>setTimeout(resolve,time));
    
      const title = document.querySelector('title').textContent.split(' - ')[0];
      const noArr = Array.from(document.querySelectorAll('select[name=no] option'));
      const noEnd = document.querySelector('select[name=no]').value;
      const hankaku = document.querySelector('select[name=hankaku]').value;
      const code = document.querySelector('select[name=code]').value;
      const kaigyo = document.querySelector('select[name=kaigyo]').value;
    
      const param = {no:1,hankaku,code,kaigyo};
      const url = document.querySelector('form[name=dl]').action;
    
      let blob = Array.from(title+'\r\n');
    
      for ( let x of noArr ){
        param.no =x.value;
        response = await fetch(
          url,
          {
            method:'POST',
            body:new URLSearchParams(param),
          }
        );
        blob.push((await response.blob()).slice());
        blob.push('\r\n');
        if ( x.value == noEnd ) break;
        await sleep(5000);
      };
    
      const a = document.createElement('a');
      a.href = URL.createObjectURL(new Blob(blob), {
        type: "text/plain"
      });
      a.download = title+'.txt';
      document.body.insertAdjacentElement('beforeend', a);
      a.click();
    
    })()
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2019/04/13 10:12:11 - 2019-04-13
  2. 2019/03/19 17:44:17 - 2019-03-19
  3. 2019/03/18 13:29:14 - 2019-03-18
  4. 2019/03/16 12:59:00 - 2019-03-16
  5. 2019/03/16 12:44:37 - 2019-03-16