MathML Copy Button

Adds a button that copies MathML code to the clipboard.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         MathML Copy Button
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Adds a button that copies MathML code to the clipboard.
// @author       Remakker
// @match        https://p2t.breezedeus.com/*
// @grant        GM_setClipboard
// @licence     MIT
// ==/UserScript==

(() => {
    'use strict';

    const copyMathML = () => {
        const inputElement = document.querySelector('mjx-assistive-mml');
        if (!inputElement) return console.error("Cannot find the element containing MathML code!");
        GM_setClipboard(inputElement.innerHTML);
    };

    const applyStylesFromCSSRule = (targetElem, selector) => {
        Array.from(document.styleSheets).forEach(sheet => {
            let rules;
            try {
                rules = sheet.cssRules;
            } catch (e) {
                return;
            }
            if (!rules) return;
            Array.from(rules).forEach(rule => {
                if (rule.type === CSSRule.STYLE_RULE && rule.selectorText === selector) {
                    for (let i = 0; i < rule.style.length; i++) {
                        const propertyName = rule.style[i];
                        const value = rule.style.getPropertyValue(propertyName);
                        const priority = rule.style.getPropertyPriority(propertyName);
                        targetElem.style.setProperty(propertyName, value, priority);
                    }
                }
            });
        });
    };

    const addCopyButton = () => {
        const originalButton = document.querySelector('#copyAsin');
        const newContainer = document.querySelector('#box');
        if (!originalButton || !newContainer) return console.error('Required element(s) not found');
        const newButton = originalButton.cloneNode(true);
        newButton.id = 'newButton';
        newButton.removeAttribute('data-clipboard-text');
        newButton.addEventListener("click", copyMathML);
        const specificSelector = ".Index_indexBox__s5lfQ .Index_index__GsKUn .Index_content__IDt4D > .Index_textAreaBox__ne32- .Index_copy__k5Mir";
        applyStylesFromCSSRule(newButton, specificSelector);
        newContainer.appendChild(newButton);
    };

    window.addEventListener('load', addCopyButton);
})();