CopyWebContent

This script adds a short-cut (Ctrl+Shift+C) to the browser which will copy the rich text version of webpage's main contents (directly pastable to a rich text editor with the format, e.g. MS word) to the system clipboard.

  1. // ==UserScript==
  2. // @name CopyWebContent
  3. // @namespace https://github.com/sowrov/CopyWebContent
  4. // @version 0.2
  5. // @description This script adds a short-cut (Ctrl+Shift+C) to the browser which will copy the rich text version of webpage's main contents (directly pastable to a rich text editor with the format, e.g. MS word) to the system clipboard.
  6. // @author Sowrov
  7. // @copyright 2020+, Sowrov
  8. // @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
  9. // @homepage https://github.com/sowrov/CopyWebContent
  10. // @supportURL https://github.com/sowrov/CopyWebContent/issues
  11. // @icon https://raw.githubusercontent.com/sowrov/CopyWebContent/master/icon/copy32x32.png
  12. // @include *
  13. // @require https://code.jquery.com/jquery-3.4.1.min.js
  14. // ==/UserScript==
  15.  
  16. function executeCopyRich (text) {
  17. function listener(e) {
  18. e.clipboardData.setData("text/html", text);
  19. e.clipboardData.setData("text/plain", text);
  20. e.preventDefault();
  21. }
  22. document.addEventListener("copy", listener);
  23. document.execCommand("copy");
  24. document.removeEventListener("copy", listener);
  25. }
  26. function process() {
  27. console.log("process: Ctrl+Shift+c");
  28. var str = "";
  29. $( "[class*='content']" ).each(function(i,ele) {
  30. console.log(ele.className);
  31. var text = ele.innerHTML;
  32. str += text;
  33. });
  34. executeCopyRich(str);
  35. }
  36. (function() {
  37. 'use strict';
  38. let keysPressed = {};
  39. document.addEventListener('keydown', (event) => {
  40. switch(event.key) {
  41. case "Control":
  42. case "Shift":
  43. console.log("down "+event.key);
  44. keysPressed[event.key] = true;
  45. break;
  46. }
  47. });
  48. document.addEventListener('keyup', (event) => {
  49. switch(event.key) {
  50. case "Control":
  51. case "Shift":
  52. console.log("up "+event.key);
  53. keysPressed[event.key]=false;
  54. break;
  55. }
  56. switch(event.code) {
  57. case "KeyC":
  58. if(keysPressed["Control"] && keysPressed["Shift"]) {
  59. process();
  60. }
  61. break;
  62. }
  63. });
  64. })();