CSDN Copyman

Press S and click to copy without login

As of 2023-08-26. See the latest version.

  1. // ==UserScript==
  2. // @name CSDN Copyman
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description Press S and click to copy without login
  6. // @author blvlight
  7. // @match https://*.csdn.net/*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. console.log('cm is working');
  16. const key = 's';
  17. window.addEventListener('keydown', handleKeydown);
  18. window.addEventListener('keyup', handleKeyUp);
  19.  
  20. function handleKeydown(e) {
  21. if (e.key === key) {
  22. window.addEventListener('click', handleClick);
  23. }
  24. }
  25.  
  26. function handleKeyUp(e) {
  27. if (e.key === key) window.removeEventListener('click', handleClick);
  28. }
  29.  
  30. /**
  31. *
  32. * @param {HTMLElement} e
  33. */
  34. function handleClick(e) {
  35. let str = '', q = [e];
  36. const texts = e.innerHTML.split(/<.*?>/);
  37. texts.reduce((text, cur) => cur + text, str);
  38. console.log(`from CSDNcopyman ${str}`);
  39. navigator.clipboard.writeText(str).then(() => alert(`复制内容\n${str}`));
  40. }
  41. })();