Luogu-CopyMarkdown

获取洛谷部分页面源代码

  1. // ==UserScript==
  2. // @name Luogu-CopyMarkdown
  3. // @namespace https://github.com/Luogu-Extended-Org/Luogu-CopyMarkdown
  4. // @description 获取洛谷部分页面源代码
  5. // @author BlackPanda
  6. // @license MIT
  7. // @version 1.4.2
  8. // @match https://*.luogu.com.cn/*
  9. // @match https://*.luogu.org/*
  10. // @grant none
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14. var url = window.location.href;
  15. async function user_detail(){
  16. var button = document.createElement('button');
  17. button.textContent = '复制Md';
  18. button.style.position = "absolute";
  19. button.style.top = "100px";button.style.right = "100px";
  20. window.addEventListener('scroll', function() {
  21. var scrollY = window.scrollY;
  22. button.style.top = (100 + scrollY) + 'px';
  23. });
  24. button.classList.add('button-lgcm');
  25. button.addEventListener('click', async function() {
  26. var introduction = _feInstance.currentData.user.introduction;
  27. await navigator.clipboard.writeText(introduction);
  28. alert('复制成功');
  29. });
  30. document.body.appendChild(button);
  31. }
  32. async function blog(){
  33. var button = document.createElement('button');
  34. button.textContent = '复制Md';
  35. button.style.position = "absolute";
  36. button.style.top = "100px";button.style.right = "100px";
  37. window.addEventListener('scroll', function() {
  38. var scrollY = window.scrollY;
  39. button.style.top = (100 + scrollY) + 'px';
  40. });
  41. button.classList.add('button-lgcm');
  42. button.addEventListener('click', async function() {
  43. fetch('/api/blog/detail/' + BlogGlobals.blogID).then(res => res.json()).then(res => navigator.clipboard.writeText(res.data.Content));
  44. alert('复制成功');
  45. });
  46. document.body.appendChild(button);
  47. };
  48. async function contest_detail(){
  49. var button = document.createElement('button');
  50. button.textContent = '复制Md';
  51. button.style.position = "absolute";
  52. button.style.top = "100px";button.style.right = "100px";
  53. window.addEventListener('scroll', function() {
  54. var scrollY = window.scrollY;
  55. button.style.top = (100 + scrollY) + 'px';
  56. });
  57. button.classList.add('button-lgcm');
  58. button.addEventListener('click', async function() {
  59. var introduction = _feInstance.currentData.contest.description;
  60. await navigator.clipboard.writeText(introduction);
  61. alert('复制成功');
  62. });
  63. document.body.appendChild(button);
  64. };
  65. async function training_detail(){
  66. var button = document.createElement('button');
  67. button.textContent = '复制Md';
  68. button.style.position = "absolute";
  69. button.style.top = "100px";button.style.right = "100px";
  70. window.addEventListener('scroll', function() {
  71. var scrollY = window.scrollY;
  72. button.style.top = (100 + scrollY) + 'px';
  73. });
  74. button.classList.add('button-lgcm');
  75. button.addEventListener('click', async function() {
  76. var introduction = _feInstance.currentData.training.description;
  77. await navigator.clipboard.writeText(introduction);
  78. alert('复制成功');
  79. });
  80. document.body.appendChild(button);
  81. };
  82. var style = document.createElement('style');
  83. style.textContent = `
  84. .button-lgcm {
  85. outline:none !important;
  86. cursor: pointer;
  87. line-height: 1.25;
  88. position: relative;
  89. display: block;
  90. margin-left: -.0625rem;
  91. padding: .5rem .75rem;
  92. color: #fff !important;
  93. border: .0625rem solid #dee2e6;
  94. font-size: 15px;
  95. font-weight: unset;
  96. display: flex;
  97. min-width: 36px;
  98. height: 36px;
  99. margin: 0 3px;
  100. border-radius: 100px!important;
  101. align-items: center;
  102. justify-content: center;
  103. transition:all .3s;
  104. background-color: #5e72e4;
  105. }
  106. .button-lgcm:hover {
  107. box-shadow: 0 7px 14px rgba(50,50,93,.1), 0 3px 6px rgba(0,0,0,.08);
  108. transform: translateY(-1px);
  109. }
  110. `;
  111. document.head.appendChild(style);
  112. if (url.includes('blog') && !url.includes('Admin') && !url.includes('admin')) {
  113. var parsedUrl = new URL(url);
  114. if (url.includes('org')) {
  115. var path = parsedUrl.pathname.split('/');
  116. if (path.length >= 2 && path[1] != '') {
  117. window.addEventListener('load', blog);
  118. }
  119. } else {
  120. var path = parsedUrl.pathname.split('/');
  121. if (path.length >= 4) {
  122. console.log('a');
  123. window.addEventListener('load', blog);
  124. }
  125. }
  126. }
  127. if (url.includes('user') && !url.includes('notification')) {
  128. window.addEventListener('load', user_detail);
  129. }
  130. if (url.includes('contest') && !url.includes('list') && !url.includes('edit') && !url.includes('contestId')) {
  131. window.addEventListener('load', contest_detail);
  132. }
  133. if (url.includes('training') && !url.includes('edit') && !url.includes('list')) {
  134. window.addEventListener('load', training_detail);
  135. }
  136. })();

QingJ © 2025

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