Newgrounds Open Audio and Copy URL

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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.');
        }
    });
})();