Luogu Markdown Copier

以markdown复制洛谷blog

  1. // ==UserScript==
  2. // @name Luogu Markdown Copier
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 以markdown复制洛谷blog
  6. // @author hyj0824
  7. // @match https://www.luogu.com.cn/blog/*
  8. // @icon https://www.google.com/s2/favicons?domain=luogu.com.cn
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14.  
  15. "use strict";
  16.  
  17. // let $ = typeof window.$ == "function" ? window.$ : unsafeWindow.jQuery; // byd没有jquery!!!
  18. // 添加按钮
  19.  
  20. const $CSS = '.floating-button { position: fixed;bottom: 20px;left: 20px;z-index: 1000;border-radius: 50%;background: #f4524d;color: #fff;font-size: 15px;width: 50px;height: 50px;text-align: center;line-height: 0px;transition: all 0.2s ease;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);cursor: pointer;}.floating-button:hover { box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2); transform: translateY(-5px);}.floating-button:active { box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); transform: translateY(2px);}';
  21. const sheet = new CSSStyleSheet();
  22. sheet.replaceSync($CSS);
  23. document.adoptedStyleSheets = [sheet];
  24.  
  25. var son = document.createElement('button');
  26. son.setAttribute("class","floating-button");
  27. son.innerHTML = "复制";
  28.  
  29.  
  30. document.querySelector("body").appendChild(son);
  31.  
  32. // 绑定事件
  33.  
  34. document.querySelector("body > button").onclick = function () {
  35.  
  36. //var content = document.getElementById('textArea').innerHTML;
  37.  
  38. fetch('/api/blog/detail/' + BlogGlobals.blogID).then(res => res.json()).then(res => navigator.clipboard.writeText(res.data.Content));
  39. alert("markdown已复制!请确认是否开启剪切板权限!");
  40.  
  41. };
  42.  
  43. })();