Redgifs download button

2/2/2026, 7:08:27 PM

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Redgifs download button
// @namespace   Violentmonkey Scripts
// @match       https://www.redgifs.com/*
// @license       GPL-3.0-or-later
// @version     1.0
// @author      pr0nusr
// @description 2/2/2026, 7:08:27 PM
// ==/UserScript==
async function dl({src}, title) {
    const extension = (document.querySelector("video").src.substring(0, 4) == "blob") ? 'm4s' : 'mp4';
    const u = `${src.substring(0, src.length - 11)}.${extension}`;

    const response = await fetch(u);
    const blob = await response.blob();

    const url = URL.createObjectURL(blob);
    const a = document.createElement("a");

    a.href = url;
    a.download = u;
    document.body.appendChild(a);
    a.click();

    document.body.removeChild(a);
    URL.revokeObjectURL(url);
}

const createButton = (parent) => {
    if (parent.className.includes('StreamateCameraDispatch')) {
      parent.parentNode.remove();
      return;
    }
    if (parent.children.length === 0) {
      parent.dataset.buttonadded = false;
      return
    }
    if (parent.dataset.buttonadded === 'true' && ( parent.className.includes('GifPreview_isVideo') ||  parent.className.includes('GifPreview_isActive'))) {
      return;
    }
    if (parent.dataset.buttonadded === 'true' && !parent.className.includes('GifPreview_isVideo')) {
      parent.dataset.buttonadded = false;
    }

    const dlProps = {
      id: 'redgifs_dl_button',
      className: 'LikeButton',
      style: 'margin-bottom: 20px',
      onclick: () => dl(parent.querySelector('img.Player-Poster'))
    };

    const dl_button = Object.assign(document.createElement("button"), dlProps);
    dl_button.dataset.itemId= parent.dataset.feedItemId;

    const svgElement = document.createElement('svg');
    svgElement.innerHTML = `
        <svg
        width="30"
        height="20"
        viewBox="0 0 24 24"
        fill="none"
        xmlns="http://www.w3.org/2000/svg"
        >
        <path
            d="M5 3h11l3 3v15a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1Z"
            stroke="white"
            stroke-width="1"
            stroke-linejoin="round"
        />
        <path
            d="M7 3v6h8V3"
            stroke="white"
            stroke-width="1"
            stroke-linejoin="round"
        />
        <rect
            x="7"
            y="14"
            width="10"
            height="6"
            stroke="white"
            stroke-width="1"
            rx="1"
        />
        </svg>
    `;
    dl_button.appendChild(svgElement);
    const sidebarChildren = parent.getElementsByClassName('sideBar')[0]?.children;
    if (sidebarChildren) {
        const childrenLength = Object.keys(sidebarChildren).length
        const insertTarget = sidebarChildren.item(childrenLength -1)
        insertTarget.parentNode.insertBefore(dl_button, insertTarget);
        parent.dataset.buttonadded = 'true';
    }
}

let append_dl_button_interval = setInterval(() => {
    const nodes = document.querySelectorAll('.GifPreview')
    nodes.forEach(createButton)
}, 500);