Instagram GraphQL

Adds a button to copy the contents of <pre> on the Instagram GraphQL page

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Instagram GraphQL
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds a button to copy the contents of <pre> on the Instagram GraphQL page
// @match        https://www.instagram.com/graphql/query/*
// @grant        GM_setClipboard
// @run-at       document-end
// @author       Aligator
// @license      GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    // Wait for the <pre> element to appear in the DOM
    function waitForPreAndInsertButton() {
        const pre = document.querySelector('pre');
        if (!pre) {
            setTimeout(waitForPreAndInsertButton, 300); // try again after 300ms
            return;
        }

        // Create the button
        const button = document.createElement('button');
        button.textContent = '📋 Copy Content';
        button.style.margin = '15px';
        button.style.fontSize = '20px';
        button.style.cursor = 'pointer';

        // Copy function
        button.addEventListener('click', () => {
            const text = pre.innerText;
            if (typeof GM_setClipboard !== 'undefined') {
                GM_setClipboard(text);
            } else {
                // fallback for browsers without GM_setClipboard
                navigator.clipboard.writeText(text).then(() => {
                    alert('Copied to clipboard!');
                }).catch(err => {
                    alert('Failed to copy: ' + err);
                });
            }
        });

        // Insert the button before <pre>
        pre.parentNode.insertBefore(button, pre);
    }

    waitForPreAndInsertButton();
})();