Directly download image from zerochan.net

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Directly download image from zerochan.net
// @namespace   https://myanimelist.net/profile/kyoyatempest
// @match       https://www.zerochan.net/*
// @version     2.0
// @author      kyoyacchi
// @description Downloads image when you click to download icon on zerochan.net.
// @license     none
// @icon        https://www.zerochan.net/favicon.ico
// @supportURL  https://github.com/kyoyacchi/zerochan-downloader/issues
// ==/UserScript==

let urlcik = window.location.href.split("/")[3]
let nan = isNaN(urlcik) ? false : true
window.onload = function (){
/////
	function  toDataURL(url) {
    return fetch(url).then((response) => {
            return response.blob();
        }).then(blob => {
            return URL.createObjectURL(blob);
        });
  }

  async function downloadImage(url,isimcik) {
        const a = document.createElement("a");
        a.href = await toDataURL(url);
        a.download = isimcik
        document.body.appendChild(a);
        a.click();
        document.body.removeChild(a);
  }
/////




  function crumb () {
    let kirinti = document.querySelector(".breadcrumb")
    if (kirinti) {
    kirinti.remove();
      console.log("Removed left top corner button")
    } else {
      return
    }
  }

  crumb();//bonus

  let static = window.location.href.split("/")[2]
    if (static == "www.zerochan.net") {


var buton = document.getElementsByClassName("download-button")[0]



let link = buton.href
let yedek = []
yedek.push(link)
  let name = link.split("/")[3] || "zerochan.png"

  yedek.push(name)


buton.addEventListener("click", function(e) {

  e.preventDefault();
downloadImage(yedek[0],yedek[1])
  console.log(`downloaded image: ${yedek[1]||"??"}`)
  let titl = []
  titl.push(document.title)

  setTimeout(() => {
  document.title = "Image downloaded."
    console.log("I changed title of page,it will be reverted in 10 scs.")
  },500)
  setTimeout(() => {
    document.title = titl[0] || "Refresh page to see original title"
    console.log("I've reverted the page title.")
  },10000)
//console.log("Someone clicked to download button")
}, false);


}
function setLikeCount() {
  var like_count = 0;
  try {
 var  get_count = document.getElementById("favorites").getElementsByClassName("user").length

 } catch(e) {
   like_count = 0
 }
  like_count = get_count || 0
document.querySelector("p:nth-of-type(2)").style.color = "#FFFFFF"

let tmp = []
let boyutvs = document.querySelector("p:nth-of-type(2)").childNodes[0].textContent

tmp.push(boyutvs)

  setTimeout(() => {
    document.querySelector("p:nth-of-type(2)").childNodes[0].textContent = tmp[0] + ` (${like_count} ${like_count > 1? "likes":"like"})`
  },500)



document.querySelector(".fav-button").addEventListener("click",function(e) {
let exists = document.querySelector(".active.fav-button")
if (!exists){
document.querySelector("p:nth-of-type(2)").childNodes[0].textContent = tmp[0] + ` (${like_count+1} ${like_count+1>1?"likes" : "like"})`
} else {
  document.querySelector("p:nth-of-type(2)").childNodes[0].textContent = tmp[0] + ` (${like_count - 1 == "-1" ? 0 : like_count} ${like_count -1 > 1? "likes" :"like"})`
}
})
}
  setLikeCount();
}