Directly download image from zerochan.net

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

目前為 2023-01-07 提交的版本,檢視 最新版本

  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. // @match https://s1.zerochan.net/*
  7. // @version 1.9
  8. // @author kyoyacchi
  9. // @description Downloads image when you click to download icon on zerochan.net.
  10. // @license none
  11. // @icon https://www.zerochan.net/favicon.ico
  12. // @supportURL https://github.com/kyoyacchi/zerochan-downloader/issues
  13. // ==/UserScript==
  14.  
  15. let urlcik = window.location.href.split("/")[3]
  16. let nan = isNaN(urlcik) ? false : true
  17.  
  18. window.onload = function (){
  19. /////
  20. function toDataURL(url) {
  21. return fetch(url).then((response) => {
  22. return response.blob();
  23. }).then(blob => {
  24. return URL.createObjectURL(blob);
  25. });
  26. }
  27.  
  28. async function downloadImage(url,isimcik) {
  29. const a = document.createElement("a");
  30. a.href = await toDataURL(url);
  31. a.download = isimcik
  32. document.body.appendChild(a);
  33. a.click();
  34. document.body.removeChild(a);
  35. }
  36. /////
  37. // https://stackoverflow.com/a/56041756/19276081
  38.  
  39.  
  40. if (document.zerochanTurkishizer) {
  41. console.log('Wow! You are also using Turkishizer one!')
  42. }
  43.  
  44. function crumb () {
  45. let kirinti = document.querySelector(".breadcrumb")
  46. if (kirinti) {
  47. kirinti.remove();
  48. console.log("Removed left top corner button")
  49. } else {
  50. return
  51. }
  52. }
  53.  
  54. crumb();//bonus
  55.  
  56. let static = window.location.href.split("/")[2]
  57. /*if (static == "static.zerochan.net" || static == "s1.zerochan.net"){
  58.  
  59. let isim = window.location.href.split("/")[3] || "zerochan.png"
  60. downloadImage(window.location.href,isim)
  61. popup()
  62. console.log(`downloaded image: ${isim}`)
  63.  
  64.  
  65. } else*/
  66.  
  67. if (static == "www.zerochan.net") {
  68. //console.log(window.location.href + " adresindesiniz.")
  69. //let buton = document.querySelector(".download-button")
  70.  
  71. var buton = document.getElementsByClassName("download-button")[0]
  72.  
  73. ///
  74.  
  75.  
  76. let link = buton.href
  77. let yedek = []
  78. yedek.push(link)
  79. let name = link.split("/")[3] || "zerochan.png"
  80. // console.log(name)
  81. yedek.push(name)
  82.  
  83.  
  84. buton.addEventListener("click", function(e) {
  85. e.preventDefault()
  86. downloadImage(yedek[0],yedek[1])
  87. //popup()
  88. console.log(`downloaded image: ${yedek[1]||"??"}`)
  89. let titl = []
  90. titl.push(document.title)
  91.  
  92. setTimeout(() => {
  93. document.title = "Image downloaded."
  94. console.log("I changed title of page,will be revert in 10 scs.")
  95. },500)
  96. setTimeout(() => {
  97. document.title = titl[0] || "Refresh page to see original title"
  98. console.log("I've reverted page title.")
  99. },10000)
  100. //console.log("Someone clicked to download button")
  101. }, false);
  102.  
  103.  
  104. }
  105. function setLikeCount() {
  106. var like_count = 0;
  107. try {
  108. var get_count = document.getElementById("favorites").getElementsByClassName("user").length
  109.  
  110. } catch(e) {
  111. like_count = 0
  112. }
  113. like_count = get_count || 0
  114. document.querySelector("p:nth-of-type(2)").style.color = "#FFFFFF"
  115.  
  116. let tmp = []
  117. let boyutvs = document.querySelector("p:nth-of-type(2)").childNodes[0].textContent
  118.  
  119. tmp.push(boyutvs)
  120.  
  121. setTimeout(() => {
  122. document.querySelector("p:nth-of-type(2)").childNodes[0].textContent = tmp[0] + ` (${like_count} ${like_count > 1? "likes":"like"})`
  123. },500)
  124. // console.log(`Like sayısı başarıyla ayarlandı.(${like_count}) like var gibii.`)
  125.  
  126.  
  127. }
  128. setLikeCount();
  129. }
  130.