Newgrounds Open Audio and Copy URL

Opens audio link from og:audio meta tag and copies to clipboard

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Newgrounds Open Audio and Copy URL
// @namespace    http://tampermonkey.net/
// @version      2025-08-25
// @description  Opens audio link from og:audio meta tag and copies to clipboard
// @author       YouTubeDrawaria
// @match        https://www.newgrounds.com/audio/listen/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=newgrounds.com
// @grant        GM_setClipboard
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // Wait for the document to be fully loaded
    window.addEventListener('load', function() {
        const audioUrl = document.querySelector('meta[property="og:audio"]').getAttribute('content');

        if (audioUrl) {
            const button = document.createElement('button');
            button.textContent = 'Open Audio and Copy URL';
            button.style.position = 'fixed';
            button.style.bottom = '10px';
            button.style.left = '10px';
            button.style.zIndex = '10000';
            button.style.padding = '10px';
            button.style.backgroundColor = '#f0f0f0';
            button.style.border = '1px solid #ccc';
            button.style.cursor = 'pointer';

            button.addEventListener('click', async () => {
                // Open in new window
                window.open(audioUrl, '_blank');

                // Copy to clipboard using Tampermonkey's GM_setClipboard
                if (typeof GM_setClipboard !== 'undefined') {
                    GM_setClipboard(audioUrl);
                    console.log('Audio URL copied to clipboard using GM_setClipboard:', audioUrl);
                } else {
                    // Fallback for standard clipboard API if GM_setClipboard is not available
                    try {
                        await navigator.clipboard.writeText(audioUrl);
                        console.log('Audio URL copied to clipboard using navigator.clipboard:', audioUrl);
                    } catch (err) {
                        console.error('Failed to copy audio URL:', err);
                    }
                }
            });

            document.body.appendChild(button);
        } else {
            console.error('Could not find the audio URL in the meta tag.');
        }
    });
})();