Greasy Fork is available in English.

CSDN Copyman

Press S and click to copy without login

2023-08-27 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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