CSDN Copyman

Press S and click to copy without login

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

  1. // ==UserScript==
  2. // @name CSDN Copyman
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.3
  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.  
  16. const key = 's';
  17. window.addEventListener('keydown', handleKeydown);
  18. window.addEventListener('keyup', handleKeyUp);
  19.  
  20. function handleKeydown(e) {
  21. if (e.key === key) window.addEventListener('click', handleClick);
  22. }
  23.  
  24. function handleKeyUp(e) {
  25. if (e.key === key) window.removeEventListener('click', handleClick);
  26. }
  27.  
  28. /**
  29. *
  30. * @param {PointerEvent} e
  31. */
  32. function handleClick(e) {
  33. const text = e.target?.innerHTML.replace(/<.*?>/, '');
  34. if (text) {
  35. console.log(`from CSDNcopyman - You can check your copy text in '[]':\n[\n${text}\n]\n----${new Date().toLocaleString()}`);
  36. navigator.clipboard.writeText(text).then(() => alert(`复制内容:\n${text}`));
  37. } else {
  38. console.log(`from CSDNcopyman - It seems like click on void.----${new Date().toLocaleString()}`)
  39. }
  40. }
  41. })();