EHentai Torrent Rename

Remove "{EHT PERSONALIZED TORRENT - DO NOT REDISTRIBUTE}" prefix for EHentai torrent downloading.

  1. // ==UserScript==
  2. // @name EHentai Torrent Rename
  3. // @namespace https://github.com/Cirn09
  4. // @version 0.2
  5. // @description Remove "{EHT PERSONALIZED TORRENT - DO NOT REDISTRIBUTE}" prefix for EHentai torrent downloading.
  6. // @author Cirn09
  7. // @match https://exhentai.org/gallerytorrents.php*
  8. // @match https://e-hentai.org/gallerytorrents.php*
  9. // @icon https://e-hentai.org/favicon.ico
  10. // @grant none
  11. // @license GPLv3
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. 'use strict';
  16. const start = "document.location='";
  17. const end = "'; return false";
  18.  
  19. let downloadLinks = document.querySelectorAll('a');
  20. for (let a of downloadLinks) {
  21. if ('onclick' in a.attributes) {
  22. let onclick = a.attributes['onclick'].nodeValue;
  23. if (!onclick.startsWith(start)) { return; }
  24. a.href = onclick.slice(start.length, onclick.indexOf(end));
  25. a.attributes.removeNamedItem('onclick');
  26. a.onclick = (function (event) {
  27. let url = this.href;
  28. let filename = a.innerText.trim() + '.torrent';
  29.  
  30. fetch(url)
  31. .then(function (response) {
  32. if (response.ok) {
  33. return response.blob();
  34. }
  35. throw new Error('Network response was not ok.');
  36. })
  37. .then(function (blob) {
  38. var downloadLink = document.createElement('a');
  39. downloadLink.href = URL.createObjectURL(blob);
  40. downloadLink.download = filename;
  41. document.body.appendChild(downloadLink);
  42. downloadLink.click();
  43. document.body.removeChild(downloadLink);
  44. })
  45. .catch(function (error) {
  46. console.log('Error:', error);
  47. });
  48.  
  49. return false;
  50.  
  51. });
  52. }
  53. }
  54. })();