Luogu-CopyMarkdown

获取洛谷部分页面源代码

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

  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 0.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 = url = window.location.href;
  16. async function user_detail(){
  17. var button = document.createElement('button');
  18. button.textContent = 'Copy';
  19. button.classList.add('button', 'button-size');
  20. button.addEventListener('click', async function() {
  21. var introduction = _feInstance.currentData.user.introduction;
  22. await navigator.clipboard.writeText(introduction);
  23. alert('复制成功');
  24. });
  25. var tmp = document.getElementsByClassName('card padding-default');
  26. var pos = tmp[0];
  27. pos.appendChild(button);
  28. };
  29. //To do
  30. async function blog(){
  31. var button = document.createElement('button');
  32. button.textContent = 'Copy';
  33. button.classList.add('button-blog', 'button-size-blog');
  34. button.addEventListener('click', async function() {
  35. fetch('/api/blog/detail/' + BlogGlobals.blogID).then(res => res.json()).then(res => navigator.clipboard.writeText(res.data.Content));
  36. alert('复制成功');
  37. });
  38. var pos = document.querySelector('div>h2');
  39. pos.insertBefore(button, pos.children[0]);
  40. };
  41. async function contest_detail(){
  42. var button = document.createElement('button');
  43. button.textContent = 'Copy';
  44. button.classList.add('button', 'button-size');
  45. button.addEventListener('click', async function() {
  46. var introduction = _feInstance.currentData.contest.description;
  47. await navigator.clipboard.writeText(introduction);
  48. alert('复制成功');
  49. });
  50. var tmp = document.getElementsByClassName('card padding-default');
  51. var pos = tmp[0];
  52. pos.appendChild(button);
  53. };
  54. async function training_detail(){
  55. var button = document.createElement('button');
  56. button.textContent = 'Copy';
  57. button.classList.add('button', 'button-size');
  58. button.addEventListener('click', async function() {
  59. var introduction = _feInstance.currentData.training.description;
  60. await navigator.clipboard.writeText(introduction);
  61. alert('复制成功');
  62. });
  63. var tmp = document.getElementsByClassName('card padding-default');
  64. var pos = tmp[0];
  65. pos.appendChild(button);
  66. };
  67. var style = document.createElement('style');
  68. style.textContent = `
  69. .button {
  70. background-color: #6495ed;
  71. color: #fff;
  72. border-radius: 6px;
  73. }
  74. .button-blog {
  75. background-color: #6495ed;
  76. color: #fff;
  77. border-radius: 6px;
  78. font-size: 15px;
  79. }
  80. .button-size {
  81. width: 50px;
  82. height: 25px;
  83. }
  84. .button-size-blog {
  85. width: 40px;
  86. height: 25px;
  87. }
  88. * {
  89. margin: 0;
  90. padding: 0;
  91. border: none;
  92. }
  93. `;
  94. if (url.includes('blog')) {
  95. //To do
  96. //document.head.appendChild(style);
  97. //window.addEventListener('load', blog);
  98. } else if (url.includes('user')) {
  99. document.head.appendChild(style);
  100. window.addEventListener('load', user_detail);
  101. } else if (url.includes('contest')) {
  102. document.head.appendChild(style);
  103. window.addEventListener('load', contest_detail);
  104. } else if (url.includes('training')) {
  105. document.head.appendChild(style);
  106. window.addEventListener('load', training_detail);
  107. }
  108. })();

QingJ © 2025

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