Chin Fast Image Downloader

One click to download current hovered image/webmeme

目前為 2021-06-17 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Chin Fast Image Downloader
// @namespace    https://greasyfork.org/en/users/86284-benjababe
// @version      1.02
// @description  One click to download current hovered image/webmeme
// @author       Benjababe

// @match        https://boards.4channel.org/*
// @match        https://arch.b4k.co/*
// @match        https://archived.moe/*
// @match        https://archive.nyafuu.org/*
// @match        https://archive.wakarimasen.moe/*
// @match        https://desuarchive.org/*
// @match        https://warosu.org/*

// @grant        GM_download
// ==/UserScript==

// jshint esversion: 6

(function() {
    'use strict';

    const HOTKEY = "Pause";

    document.onkeydown = (e) => {
        // key can be whatever you want, I choose pause as it's what I bound my mouse side keys to
        if (e.code === HOTKEY) {
            // get all elements hovered
            let els = document.querySelectorAll( ":hover" );
            els.forEach((el) => {
                // only download for images
                if (el.tagName.toLowerCase() === "img") {
                    // link to original image/webmeme usually is the parent <a> element
                    let parent = el.parentNode,
                        url = parent.href,
                        filename = HDFilenameFromURL(url);
                    GM_download(url, filename);
                }
            });
        }
    }

    // eg. ".../1622014662736s.jpg -> 1622014662736.jpg"
    let HDFilenameFromURL = (url) => {
        let SDFilename = url.split("/").pop();
        SDFilename = SDFilename.split(".");
        SDFilename[0] = SDFilename[0].slice(0, -1);
        return SDFilename.join(".");
    }
})();