ar5iv tex copy

Click on any equation in ar5iv to copy the tex code to clipboard

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         ar5iv tex copy
// @namespace    http://tampermonkey.net/
// @version      2023-12-25
// @description  Click on any equation in ar5iv to copy the tex code to clipboard
// @author       joelsleeba
// @match        https://ar5iv.labs.arxiv.org/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=arxiv.org
// @license      GNU AGPLv3 
// ==/UserScript==

(function() {
    'use strict';

    function handleBlockEquationClick(event) {
  event.stopPropagation();
  const equation = event.target.closest(".ltx_equation")

  if (equation) {
    const mathElements = equation.querySelectorAll("math");
    const altTexts = Array.from(mathElements).map(element => {
      const altText = element.getAttribute("alttext");
      return altText.replace(/\\displaystyle/g, ""); // Remove '\displaystyle'
    });
    const joinedAltText = altTexts.join(" ");
    console.log(joinedAltText);

    // Do something with the joined alt text here, e.g., display it in an alert:
    navigator.clipboard.writeText(joinedAltText)
    .then(() => {
      // Copying succeeded
      console.log("Alt text copied to clipboard");
    })
    .catch(err => {
      // Copying failed, handle the error
      console.error("Failed to copy alt text:", err);
    });
  } else {
    console.log("Clicked element is not within an .ltx_equation");
  }
}

function handleInlineEquationClick(event) {
  event.stopPropagation();
  const equation = event.target.closest("math")

  if (equation) {
    const altText = equation.getAttribute("alttext");
    console.log(altText);

    // Do something with the joined alt text here, e.g., display it in an alert:
    navigator.clipboard.writeText(altText)
    .then(() => {
      // Copying succeeded
      console.log("Alt text copied to clipboard");
    })
    .catch(err => {
      // Copying failed, handle the error
      console.error("Failed to copy alt text:", err);
    });
  } else {
    console.log("Clicked element is not within an .ltx_equation");
  }
}

// Attach the event listener to all descendants of .ltx_equationgroup
document.querySelectorAll(".ltx_equation *").forEach(element => {
  element.addEventListener("click", handleBlockEquationClick);
});

// // Attach the event listener to all descendants of .ltx_Math which are not themselves descendants of .ltx_equation
document.querySelectorAll(".ltx_Math[display='inline']:not(.ltx_equationgroup *) *").forEach(element => {
  element.addEventListener("click", handleInlineEquationClick);
});

})();