// ==UserScript== // @name Wiki LaTeX Copier // @namespace http://tampermonkey.net/ // @version 1.0 // @description Copy selected text from wiki with equations in LaTeX format // @author Jie-Qiao // @match *://*.wikipedia.org/* // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Create the button element const button = document.createElement('button'); button.textContent = 'Copy'; button.style.position = 'absolute'; button.style.display = 'none'; button.style.zIndex = '1000'; // Append the button to the body document.body.appendChild(button); // Function to handle button click button.addEventListener('click', function() { const selectedText = window.getSelection(); if (selectedText) { myfunction(selectedText); } button.style.display = 'none'; // Hide the button after click }); // Function to show the button when text is selected document.addEventListener('mouseup', function(event) { const selectedText = window.getSelection().toString().trim(); if (selectedText) { const x = event.pageX; const y = event.pageY; button.style.left = `${x}px`; button.style.top = `${y}px`; button.style.display = 'block'; } else { button.style.display = 'none'; } }); // Custom function to process the selected text function myfunction(selection) { let range = selection.getRangeAt(0); //console.log('Text selected:', selection.toString()); // Log selected text let c=range.cloneContents(); let text="" var node; for (var i=0;i