Directly download image from zerochan.net

Downloads image when you click to "download image" on zerochan.net.

目前为 2022-10-31 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Directly download image from zerochan.net
  3. // @namespace https://myanimelist.net/profile/kyoyatempest
  4. // @match https://static.zerochan.net/*
  5. // @version 1.1
  6. // @author kyoyacchi
  7. // @description Downloads image when you click to "download image" on zerochan.net.
  8. // @license gpl-3.0
  9. // ==/UserScript==
  10.  
  11.  
  12. window.onload = function (){
  13.  
  14.  
  15. let isim = window.location.href.split("/")[3] || "zerochan.png"
  16. downloadImage(window.location.href,isim)
  17.  
  18. let dogrula = window.confirm("Wanna go back to zerochan after downloading image?")
  19. if (dogrula) {
  20.  
  21. setTimeout(() => {
  22. window.history.back()
  23. }, 10000) //ten secs.
  24. }
  25.  
  26.  
  27.  
  28. }
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. function downloadImage(url, name){
  36. fetch(url)
  37. .then(resp => resp.blob())
  38. .then(blob => {
  39. const url = window.URL.createObjectURL(blob);
  40. const a = document.createElement('a');
  41. a.style.display = 'none';
  42. a.href = url;
  43.  
  44. a.download = name;
  45. document.body.appendChild(a);
  46. a.click();
  47. window.URL.revokeObjectURL(url);
  48. })
  49. .catch(() => alert('An error occured.'));
  50.  
  51. }
  52.  
  53. // https://stackoverflow.com/a/68722398/19276081