Disable Site Restriction On Page Operations

Disable site restrictions which prevent users on performing clipboard operations, text selection, page printing (experimental), and opening the Right-Click context menu. To open the Right-Click context menu use SHIFT+RightClick (the default; configurable in the script code).

  1. // ==UserScript==
  2. // @name Disable Site Restriction On Page Operations
  3. // @namespace https://greasyfork.org/en/users/85671-jcunews
  4. // @version 1.1.5
  5. // @license AGPLv3
  6. // @author jcunews
  7. // @description Disable site restrictions which prevent users on performing clipboard operations, text selection, page printing (experimental), and opening the Right-Click context menu. To open the Right-Click context menu use SHIFT+RightClick (the default; configurable in the script code).
  8. // @match *://*/*
  9. // @inject-into page
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. (() => {
  15. //=== CONFIGURATION BEGIN ===
  16.  
  17. //Setting for Right-Click. At least either SHIFT or CTRL should be set to true.
  18. let useShift = true;
  19. let useCtrl = false;
  20.  
  21. //=== CONFIGURATION END ===
  22.  
  23. if (document.contentType !== "text/html") return;
  24. let epd = Event.prototype.preventDefault;
  25. Event.prototype.preventDefault = function() {
  26. let a;
  27. switch (this.type) {
  28. case "cut":
  29. case "copy":
  30. case "selectstart":
  31. return;
  32. case "paste":
  33. if (a = document.activeElement) {
  34. while (a && a.classList && !a.classList.contains("CodeMirror")) a = a.parentNode;
  35. if (a) break;
  36. }
  37. return;
  38. case "contextmenu":
  39. if ((this.shiftKey === useShift) && (this.ctrlKey === useCtrl)) return;
  40. }
  41. return epd.apply(this, arguments);
  42. };
  43. var to = {createHTML: s => s}, tp = window.trustedTypes?.createPolicy ? trustedTypes.createPolicy("", to) : to, html = s => tp.createHTML(s);
  44. addEventListener("load", () => {
  45. document.documentElement.appendChild(document.createElement("STYLE")).innerHTML = html(`
  46. @media print {
  47. html, body { opacity: 1 !important; visibility: visible !important }
  48. html { display: ${getComputedStyle(document.documentElement).display} !important }
  49. body { display: ${getComputedStyle(document.body).display} !important }
  50. }
  51. * {
  52. user-select: auto !important; -moz-user-select: auto !important; -webkit-user-select: auto !important; -ms-user-select: auto !important;
  53. }
  54. `);
  55. });
  56. })();