移除限制 - 通杀

用于移除网站限制的通杀解决方案

  1. // ==UserScript==
  2. // @name Remove Limits - ALL KILL
  3. // @name:zh-CN 移除限制 - 通杀
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.2.0
  6. // @description ALL-KILL solution for removing limits on the website
  7. // @description:zh-CN 用于移除网站限制的通杀解决方案
  8. // @match none
  9. // @author PRO
  10. // @run-at document-start
  11. // @license gpl-3.0
  12. // ==/UserScript==
  13.  
  14. (function () {
  15. "use strict";
  16. const debug = false;
  17. const log = debug ? console.log.bind(console, "[Remove Limits]") : () => { };
  18. // === JavaScript Part ===
  19. // Stop listeners that might hinder right-click menu, selection, etc.
  20. const events = ["contextmenu", "select", "selectstart", "copy", "cut", "dragstart"];
  21. events.forEach((event) => {
  22. document.addEventListener(event, (e) => {
  23. e.stopImmediatePropagation();
  24. }, { capture: true });
  25. });
  26. // === CSS Part ===
  27. const userSelectAliases = ["-webkit-touch-callout", "-webkit-user-select", "-moz-user-select", "-ms-user-select", "user-select"];
  28. // Remove CSS rules that might hinder user selection
  29. function removeUserSelect(styleSheet) {
  30. for (const rule of styleSheet.cssRules) { // Might encounter a SecurityError
  31. if (!rule instanceof CSSStyleRule || !rule.style) continue; // Not what we're looking for
  32. // Iterate over its styles
  33. for (const property of rule.style) {
  34. if (userSelectAliases.includes(property) && rule.style.getPropertyValue(property) === "none") {
  35. rule.style.removeProperty(property); // Remove the property
  36. log(`Removed "${property}" from rule:`, rule);
  37. }
  38. }
  39. }
  40. }
  41. document.addEventListener("DOMContentLoaded", () => {
  42. // Remove all `user-select: none` declarations
  43. for (const styleSheet of document.styleSheets) {
  44. try {
  45. removeUserSelect(styleSheet);
  46. } catch (e) {
  47. if (e instanceof DOMException && e.name === "SecurityError") {
  48. log("Caught a SecurityError while trying to read a CSS rule. This is expected if the CSS rule is from a different origin.");
  49. } else {
  50. log("An unexpected error occurred while trying to read a CSS rule:", e);
  51. }
  52. }
  53. }
  54. });
  55. // Allow selection using CSS (not needed anymore in most cases)
  56. const style = document.createElement("style");
  57. style.textContent = `* {
  58. ${userSelectAliases.map((alias) => `${alias}: unset !important;`).join("\n")}
  59. }`;
  60. document.head.appendChild(style);
  61. })();