CSDN Copyman

Press S and click to copy without login

Verze ze dne 26. 08. 2023. Zobrazit nejnovější verzi.

  1. // ==UserScript==
  2. // @name CSDN Copyman
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.0
  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. function handleClick(e) {
  31. let str = '';
  32.  
  33. function dfs(el) {
  34. str += el.innerText;
  35. for (const element of [...el.querySelectorAll('*')]) {
  36. dfs(element);
  37. }
  38. }
  39. dfs(e.target);
  40. console.log(`from${str}`);
  41. navigator.clipboard.writeText(str).then(() => alert(`复制内容\n${str}`));
  42. }
  43. })();