NSFWalbum Downloader

Allow getting full album from NFSWalbum.com in an easy way

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         NSFWalbum Downloader
// @namespace    https://nsfwalbum.com/
// @version      1.1
// @description  Allow getting full album from NFSWalbum.com in an easy way
// @author       whatever
// @match        https://nsfwalbum.com/album/*
// @grant        GM_download
// @grant        GM_getResourceURL
// @resource     downloadIcon https://i.imgur.com/sj6kMRp.png
// @require      https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js
// ==/UserScript==

(async function() {
  const giraffe = {
    annihilate: function(r, a) {
      let n = '';
      r.toString();
      for (let t = 0; t < r.length; t++) {
        const e = r.charCodeAt(t) ^ a;
        n += String.fromCharCode(e);
      }
      return n;
    },
  };

  const zeroFill = val => ('00000' + val).substr(-5);

  const links = [];
  const images = document.querySelectorAll('.img.albumPhoto');
  for (let img of images.entries()) {
    links.push(img[1].dataset.imgId);
  }

  const downloadAlbum = async idx => {
    const dlStatus = document.querySelector('.dlStatus');
    if (idx >= links.length) {
      dlStatus.innerText = 'Download complete!';
      return;
    }

    dlStatus.innerText = `Download in progress: ${idx + 1}/${links.length}`;

    const imgPage = await axios.get(`https://nsfwalbum.com/photo/${links[idx]}`);
    const matches = imgPage.data.match(/encodeURIComponent\(giraffe.annihilate\("([^"]+)/i);
    if (matches.length) {
      const spirit = encodeURIComponent(giraffe.annihilate(matches.pop(), 6));
      GM_download({
        url: `https://nsfwalbum.com/imageProxy.php?photoId=${links[idx]}&spirit=${spirit}`,
        name: `nsfwalbum-${document.location.href.split('/').pop()}-${zeroFill(idx + 1)}.jpg`,
        saveAs: false,
        onload: () => {
          downloadAlbum(idx + 1);
        },
        onerror: err => {
          console.error(err);
          downloadAlbum(idx + 1);
        },
      });
    } else {
      console.error('Unable to retrieve spirit for page', `https://nsfwalbum.com/photo/${links[idx]}`);
    }
  };

  const img = document.createElement('img');
  const a = document.createElement('a');
  a.classList = 'downloadAlbum';
  a.appendChild(img);
  a.onclick = () => {
    downloadAlbum(0);
  };
  img.src = await GM_getResourceURL('downloadIcon');
  img.setAttribute('style', 'margin-left: 30px; width: 24px; height: 24px; cursor: pointer;');
  const dlStatus = document.createElement('span');
  dlStatus.classList = 'dlStatus';
  dlStatus.setAttribute('style', 'margin-left: 10px;');
  document
    .querySelector('.gallery_name h6')
    .appendChild(a)
    .appendChild(dlStatus);
})();