Luogu-CopyMarkdown

获取洛谷部分页面源代码

当前为 2023-06-29 提交的版本,查看 最新版本

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

QingJ © 2025

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