🏠 Home 

向 latexlive.com 添加复制按钮

向 latexlive.com 添加复制按钮,方便快速复制 latex


Install this script?
  1. // ==UserScript==
  2. // @name 向 latexlive.com 添加复制按钮
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description 向 latexlive.com 添加复制按钮,方便快速复制 latex
  6. // @author Cesaryuan
  7. // @match https://*.latexlive.com/*
  8. // @icon https://www.google.com/s2/favicons?domain=latexlive.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12. (function () {
  13. 'use strict';
  14. // create a new button
  15. var btn = document.createElement('button');
  16. btn.innerHTML = '复制';
  17. // add class to btn
  18. btn.className = 'btn btn-light theme-fill';
  19. // set id
  20. btn.id = 'copy-btn';
  21. // add click handler
  22. btn.onclick = function () {
  23. // get the selected element
  24. var selected = document.querySelector('#txta_input');
  25. // copy the text
  26. navigator.clipboard.writeText(selected.value);
  27. toast('复制成功');
  28. };
  29. var CONTAINER = "#wrap_immediate > row > div.col-5.col-sm-5.col-md-5.col-lg-5.col-xl-5";
  30. // wait container appear and add btn
  31. var interval = setInterval(function () {
  32. var wrap = document.querySelector(CONTAINER);
  33. if (wrap) {
  34. wrap.appendChild(btn);
  35. clearInterval(interval);
  36. }
  37. }, 100);
  38. function toast(msg) {
  39. var toast = document.createElement('div');
  40. toast.className = 'toast';
  41. toast.innerHTML = msg;
  42. toast.style.position = 'fixed';
  43. toast.style.bottom = '10px';
  44. toast.style.right = '10px';
  45. toast.style.zIndex = '9999';
  46. toast.style.backgroundColor = '#fff';
  47. toast.style.color = '#000';
  48. toast.style.padding = '10px';
  49. toast.style.borderRadius = '5px';
  50. toast.style.boxShadow = '0 0 5px #000';
  51. toast.style.fontSize = '16px';
  52. toast.style.fontWeight = 'bold';
  53. toast.style.opacity = '0';
  54. toast.style.transition = 'opacity 0.5s';
  55. document.body.appendChild(toast);
  56. setTimeout(function () {
  57. toast.style.opacity = '1';
  58. }, 100);
  59. setTimeout(function () {
  60. toast.style.opacity = '0';
  61. }, 2000);
  62. setTimeout(function () {
  63. toast.remove();
  64. }, 3000);
  65. }
  66. })();