Directly download image from zerochan.net

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Directly download image from zerochan.net
// @namespace   https://myanimelist.net/profile/kyoyatempest
// @match       https://www.zerochan.net/*
// @version     4.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==

(function () {
  "use strict";


  const downloadBtn = document.querySelector(".download-button");
  if (!downloadBtn) return;

  const imageUrl = downloadBtn.href;
  const fileName = imageUrl.split("/")[3] || "zerochan.png";

  downloadBtn.addEventListener("click", async (e) => {
    e.preventDefault();

    const blob = await fetch(imageUrl).then((r) => r.blob());
    const objectUrl = URL.createObjectURL(blob);

    const a = Object.assign(document.createElement("a"), {
      href: objectUrl,
      download: fileName,
    });
    document.body.appendChild(a);
    a.click();
    a.remove();
    URL.revokeObjectURL(objectUrl);

    
  });
})();