ThotHub.tv Forum Gallery Downloader

Download galleries from posts on forum.thothub.tv

  1. // ==UserScript==
  2. // @name ThotHub.tv Forum Gallery Downloader
  3. // @namespace ThotDev
  4. // @description Download galleries from posts on forum.thothub.tv
  5. // @version 1.1.0
  6. // @icon https://i.imgur.com/5xpgAny.jpg
  7. // @license WTFPL; http://www.wtfpl.net/txt/copying/
  8. // @match https://forum.thothub.tv/*
  9. // @require https://code.jquery.com/jquery-3.3.1.min.js
  10. // @require https://unpkg.com/jszip@3.2.0/dist/jszip.min.js
  11. // @require https://unpkg.com/file-saver@2.0.1/dist/FileSaver.min.js
  12. // @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js?v=a834d46
  13. // @noframes
  14. // @connect self
  15. // @run-at document-start
  16. // @grant GM.xmlHttpRequest
  17. // @grant GM_xmlhttpRequest
  18. // ==/UserScript==
  19.  
  20. jQuery(function ($) {
  21. $('.message-attribution-opposite')
  22. .map(function () { return $(this).children('li:first'); })
  23. .each(function () {
  24. var downloadLink = $('<li><a href="#">⭳ Download</a><li>');
  25. var $text = downloadLink.children('a');
  26. downloadLink.insertBefore($(this));
  27. downloadLink.click(function (e) {
  28. e.preventDefault();
  29. var urls = $(this)
  30. .parents('.message-main')
  31. .first()
  32. .find('a.js-lbImage,.lbContainer-zoomer')
  33. .map(function () { return $(this).is('[href]') ? $(this).attr('href') : $(this).data('src'); })
  34. .get();
  35. var zip = new JSZip(),
  36. current = 0,
  37. total = urls.length;
  38. $text.text('Downloading...');
  39. function next () {
  40. if (current < total) {
  41. $text.text('Downloading ' + (current+1) + '/' + total);
  42. GM.xmlHttpRequest({
  43. method: 'GET',
  44. url: urls[current++],
  45. responseType: 'arraybuffer',
  46. onload: function (response) {
  47. try {
  48. var name = response.responseHeaders.match(/^content-disposition.+(?:filename=)(?<filename>.+)$/mi).groups['filename'].replace(/\"/g, '');
  49. var data = response.response;
  50. zip.file(name, data);
  51. }
  52. catch (err) {
  53. }
  54. next();
  55. },
  56. onerror: function (response) {
  57. next();
  58. }
  59. });
  60. }
  61. else {
  62. $text.text('Generating zip...');
  63. zip.generateAsync({ type: 'blob' })
  64. .then(function (blob) {
  65. $text.text('Download complete!');
  66. saveAs(blob, 'Gallery.zip');
  67. });
  68. }
  69. }
  70. next();
  71. });
  72. }
  73. );
  74. });