Soundgasm Downloader

Adds a Download Audio button to Soundgasm.net audio posts.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Soundgasm Downloader
// @namespace    https://github.com/diggtrap
// @author       diggtrap
// @description  Adds a Download Audio button to Soundgasm.net audio posts.
// @include      https://soundgasm.net/*
// @icon         https://i.imgur.com/BwX91V0.png
// @version      0.401
// @license      GNU
// ==/UserScript==

// Main function to add download button
function addDownloadButton() {
    // Fetch the page content asynchronously
    fetch(window.location.href)
        .then(response => response.text())
        .then(html => {
            // Parse the HTML content to extract the M4A link
            const m4aLinkRegex = /m4a:\s*"(.*?)"/;
            const m4aMatch = html.match(m4aLinkRegex);
            const m4aUrl = m4aMatch ? m4aMatch[1] : null;

            if (m4aUrl) {
                // Find the title of the audio post
                const audioTitleElement = document.querySelector('div.jp-title');
                const audioTitleText = audioTitleElement ? audioTitleElement.textContent.trim() : "";

                // Extract the text before the second set of square brackets
                const match = audioTitleText.match(/\[.*?\](.*?)(?=\[|$)/);
                const audioTitle = match ? match[0] : audioTitleText;

                // Find the creator's username from the URL
                const audioCreatorMatch = window.location.href.match(/\/u\/([^\/]+)/);
                const audioCreator = audioCreatorMatch ? audioCreatorMatch[1] : "";

                // Create download link with post title, creator, and default text style
                const downloadButton = document.createElement('a');
                downloadButton.href = m4aUrl;
                downloadButton.target = "_blank";
                downloadButton.title = "Click to open in a New Tab; Right-click and 'Save link as' to Download";
                downloadButton.textContent = `Download ${audioTitle} by ${audioCreator}`;
                downloadButton.style.position = "fixed";
                downloadButton.style.bottom = "20px";
                downloadButton.style.right = "20px";
                downloadButton.style.padding = "10px";
                downloadButton.style.backgroundColor = "#444";
                downloadButton.style.color = "white";
                downloadButton.style.border = "none";
                downloadButton.style.borderRadius = "5px";
                downloadButton.style.cursor = "pointer";
                downloadButton.style.textDecoration = "none";
                downloadButton.style.fontWeight = "normal";
                downloadButton.style.fontSize = "14px";

                document.body.appendChild(downloadButton);
            }
        });
}

// Call the main function
addDownloadButton();