MyInstants Download Button

Adds a Download button to each instant sound on MyInstants website.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MyInstants Download Button
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Adds a Download button to each instant sound on MyInstants website.
// @author       Cryptophunk
// @match        https://www.myinstants.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Function to create and add the "Download" button
    function addDownloadButton(instantContainer) {
        const audioSrc = instantContainer.querySelector('button.small-button').getAttribute('onclick').match(/play\('([^']+)'/)[1];
        const audioTitle = instantContainer.querySelector('.instant-link').textContent;

        const downloadButton = document.createElement('a');
        downloadButton.setAttribute('class', 'instant-action-button');
        downloadButton.setAttribute('title', 'Download');
        downloadButton.setAttribute('href', audioSrc);
        downloadButton.setAttribute('download', `${audioTitle}.mp3`);

        const downloadIcon = document.createElement('img');
        downloadIcon.setAttribute('class', 'instant-action-button-icon');
        downloadIcon.setAttribute('src', '/media/images/icons/save.svg');
        downloadIcon.setAttribute('alt', 'Download icon');

        downloadButton.appendChild(downloadIcon);

        const shareBox = instantContainer.querySelector('.result-page-instant-sharebox');
        shareBox.insertBefore(downloadButton, shareBox.lastChild);
    }

    // Find all instant containers and add the "Download" button to each
    const instantContainers = document.querySelectorAll('.instant');
    instantContainers.forEach(addDownloadButton);
})();