NSFWalbum Downloader

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

  1. // ==UserScript==
  2. // @name NSFWalbum Downloader
  3. // @namespace https://nsfwalbum.com/
  4. // @version 1.1
  5. // @description Allow getting full album from NFSWalbum.com in an easy way
  6. // @author whatever
  7. // @match https://nsfwalbum.com/album/*
  8. // @grant GM_download
  9. // @grant GM_getResourceURL
  10. // @resource downloadIcon https://i.imgur.com/sj6kMRp.png
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js
  12. // ==/UserScript==
  13.  
  14. (async function() {
  15. const giraffe = {
  16. annihilate: function(r, a) {
  17. let n = '';
  18. r.toString();
  19. for (let t = 0; t < r.length; t++) {
  20. const e = r.charCodeAt(t) ^ a;
  21. n += String.fromCharCode(e);
  22. }
  23. return n;
  24. },
  25. };
  26.  
  27. const zeroFill = val => ('00000' + val).substr(-5);
  28.  
  29. const links = [];
  30. const images = document.querySelectorAll('.img.albumPhoto');
  31. for (let img of images.entries()) {
  32. links.push(img[1].dataset.imgId);
  33. }
  34.  
  35. const downloadAlbum = async idx => {
  36. const dlStatus = document.querySelector('.dlStatus');
  37. if (idx >= links.length) {
  38. dlStatus.innerText = 'Download complete!';
  39. return;
  40. }
  41.  
  42. dlStatus.innerText = `Download in progress: ${idx + 1}/${links.length}`;
  43.  
  44. const imgPage = await axios.get(`https://nsfwalbum.com/photo/${links[idx]}`);
  45. const matches = imgPage.data.match(/encodeURIComponent\(giraffe.annihilate\("([^"]+)/i);
  46. if (matches.length) {
  47. const spirit = encodeURIComponent(giraffe.annihilate(matches.pop(), 6));
  48. GM_download({
  49. url: `https://nsfwalbum.com/imageProxy.php?photoId=${links[idx]}&spirit=${spirit}`,
  50. name: `nsfwalbum-${document.location.href.split('/').pop()}-${zeroFill(idx + 1)}.jpg`,
  51. saveAs: false,
  52. onload: () => {
  53. downloadAlbum(idx + 1);
  54. },
  55. onerror: err => {
  56. console.error(err);
  57. downloadAlbum(idx + 1);
  58. },
  59. });
  60. } else {
  61. console.error('Unable to retrieve spirit for page', `https://nsfwalbum.com/photo/${links[idx]}`);
  62. }
  63. };
  64.  
  65. const img = document.createElement('img');
  66. const a = document.createElement('a');
  67. a.classList = 'downloadAlbum';
  68. a.appendChild(img);
  69. a.onclick = () => {
  70. downloadAlbum(0);
  71. };
  72. img.src = await GM_getResourceURL('downloadIcon');
  73. img.setAttribute('style', 'margin-left: 30px; width: 24px; height: 24px; cursor: pointer;');
  74. const dlStatus = document.createElement('span');
  75. dlStatus.classList = 'dlStatus';
  76. dlStatus.setAttribute('style', 'margin-left: 10px;');
  77. document
  78. .querySelector('.gallery_name h6')
  79. .appendChild(a)
  80. .appendChild(dlStatus);
  81. })();