学习通复制题目

在学习通页面上添加一个按钮,用于复制题目文本到剪贴板。

  1. // ==UserScript==
  2. // @name 学习通复制题目
  3. // @version 1.1
  4. // @author BaiLu
  5. // @description 在学习通页面上添加一个按钮,用于复制题目文本到剪贴板。
  6. // @match https://i.chaoxing.com/*
  7. // @license MIT
  8. // @match https://mooc1.chaoxing.com/*
  9. // @grant none
  10. // @namespace https://gf.qytechs.cn/users/1411786
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16.  
  17. // 添加样式以显示按钮
  18. var style = document.createElement('style');
  19. style.type = 'text/css';
  20. style.innerHTML = `
  21. #copyTextBtn {
  22. position: fixed;
  23. bottom: 70px;
  24. right: 20px;
  25. padding: 10px 20px;
  26. font-size: 16px;
  27. color: #fff;
  28. background-color: #007bff;
  29. border: none;
  30. border-radius: 5px;
  31. cursor: pointer;
  32. z-index: 9999;
  33. box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  34. transition: background-color 0.3s ease;
  35. }
  36. #copyTextBtn:hover {
  37. background-color: #0056b3;
  38. }
  39. #copyTextBtn:active {
  40. background-color: #004494;
  41. }
  42. `;
  43. document.head.appendChild(style);
  44.  
  45.  
  46.  
  47. // 创建按钮并添加到页面,但只在特定域名下
  48. var btn = document.createElement('button');
  49. btn.id = 'copyTextBtn';
  50. btn.textContent = '学习通题目';
  51. document.body.appendChild(btn);
  52.  
  53. // 定义复制文本到剪贴板的函数
  54. function copyTextToClipboard(text) {
  55. if (navigator.clipboard && window.isSecureContext) {
  56. navigator.clipboard.writeText(text).then(function() {
  57. console.log('Text copied to clipboard');
  58. }).catch(function(error) {
  59. console.error('Could not copy text: ', error);
  60. });
  61. } else {
  62. var textArea = document.createElement("textarea");
  63. textArea.value = text;
  64. textArea.style.position = "fixed";
  65. document.body.appendChild(textArea);
  66. textArea.focus();
  67. textArea.select();
  68. try {
  69. var successful = document.execCommand('copy');
  70. var msg = successful ? 'Copied to clipboard' : 'Failed to copy';
  71. console.log(msg);
  72. } catch (err) {
  73. console.error('Could not copy text: ', err);
  74. }
  75. document.body.removeChild(textArea);
  76. }
  77. }
  78.  
  79. // 获取文本并存储到变量b
  80. var a = document.querySelectorAll("#fanyaMarking > div.marking_content.ans-cc > div");
  81. var b = "";
  82. a.forEach(e => {
  83. b += e.innerText + "\n"; // 添加换行符以分隔不同的文本块
  84. });
  85.  
  86. // 为按钮添加点击事件
  87. btn.addEventListener('click', function() {
  88. copyTextToClipboard(b);
  89. });
  90. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址