Directly download image from zerochan.net

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

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Directly download image from zerochan.net
// @namespace   https://myanimelist.net/profile/kyoyatempest
// @match       https://static.zerochan.net/*
// @match       https://www.zerochan.net/*
// @match       https://s1.zerochan.net/*
// @version     1.9
// @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);
  }
/////
  // https://stackoverflow.com/a/56041756/19276081


  if (document.zerochanTurkishizer) {
    console.log('Wow! You are also using Turkishizer one!')
  }

  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 == "static.zerochan.net" || static == "s1.zerochan.net"){

let isim = window.location.href.split("/")[3] || "zerochan.png"
 downloadImage(window.location.href,isim)
  popup()
  console.log(`downloaded image: ${isim}`)


} else*/

if (static == "www.zerochan.net") {
  //console.log(window.location.href + " adresindesiniz.")
//let buton = document.querySelector(".download-button")

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

///


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


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

  setTimeout(() => {
  document.title = "Image downloaded."
    console.log("I changed title of page,will be revert in 10 scs.")
  },500)
  setTimeout(() => {
    document.title = titl[0] || "Refresh page to see original title"
    console.log("I've reverted 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)
 // console.log(`Like sayısı başarıyla ayarlandı.(${like_count}) like var gibii.`)


}
  setLikeCount();
}