Directly download image from zerochan.net

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

当前为 2022-11-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Directly download image from zerochan.net
  3. // @namespace https://myanimelist.net/profile/kyoyatempest
  4. // @match https://static.zerochan.net/*
  5. // @match https://www.zerochan.net/*
  6. // @version 1.7
  7. // @author kyoyacchi
  8. // @description Downloads image when you click to download icon on zerochan.net.
  9. // @license none
  10. // @icon https://www.google.com/s2/favicons?domain=zerochan.net
  11. // ==/UserScript==
  12.  
  13.  
  14. window.onload = function (){
  15. let static = window.location.href.split("/")[2]
  16. if (static == "static.zerochan.net"){
  17.  
  18. let isim = window.location.href.split("/")[3] || "zerochan.png"
  19. downloadImage(window.location.href,isim)
  20. console.log(`downloaded image: ${isim}`)
  21.  
  22.  
  23. function toDataURL(url) {
  24. return fetch(url).then((response) => {
  25. return response.blob();
  26. }).then(blob => {
  27. return URL.createObjectURL(blob);
  28. });
  29. }
  30.  
  31. async function downloadImage(url,isimcik) {
  32. const a = document.createElement("a");
  33. a.href = await toDataURL(url);
  34. a.download = isimcik
  35. document.body.appendChild(a);
  36. a.click();
  37. document.body.removeChild(a);
  38. }
  39.  
  40. // https://stackoverflow.com/a/56041756/19276081
  41. } else if (static == "www.zerochan.net") {
  42. //console.log(window.location.href + " adresindesiniz.")
  43. //let buton = document.querySelector(".download-button")
  44. let buton = document.getElementsByClassName("download-button")[0]
  45.  
  46. ///
  47. function toDataURL(url) {
  48. return fetch(url).then((response) => {
  49. return response.blob();
  50. }).then(blob => {
  51. return URL.createObjectURL(blob);
  52. });
  53. }
  54.  
  55. async function downloadImage(url,isimcik) {
  56. const a = document.createElement("a");
  57. a.href = await toDataURL(url);
  58. a.download = isimcik
  59. document.body.appendChild(a);
  60. a.click();
  61. document.body.removeChild(a);
  62. }
  63. /////
  64.  
  65. let link = buton.href
  66. let yedek = []
  67. yedek.push(link)
  68. let name = link.split("/")[3] || "zerochan.png"
  69. // console.log(name)
  70. yedek.push(name)
  71.  
  72. buton.removeAttribute("href")
  73.  
  74. buton.addEventListener("click", function(e) {
  75. downloadImage(yedek[0],yedek[1])
  76. //console.log("Someone clicked to download button")
  77. }, false);
  78.  
  79. }
  80. }