diff --git a/lib/builtin-rules.js b/lib/builtin-rules.js index 7f7d068..bb038d1 100644 --- a/lib/builtin-rules.js +++ b/lib/builtin-rules.js @@ -33,7 +33,7 @@ d35aaqx5ub95lt.cloudfront.net/js/app-*.js$script ! -- github.com gist.github.com - std-PerformanceObserver,std-queueMicrotask,gh-compat,gh-turbo,gh-main-csp,sm-gh-extra,sm-cookie + std-PerformanceObserver,std-queueMicrotask,std-NavigatorClipboard,gh-compat,gh-turbo,gh-main-csp,sm-gh-extra,sm-cookie,gh-codeview github.com/socket-worker.js$script gist.github.com/socket-worker.js$script github.com/assets-cdn/worker/socket-worker-*.js$script diff --git a/lib/main.js b/lib/main.js index 345c1ad..5bc24c1 100644 --- a/lib/main.js +++ b/lib/main.js @@ -52,6 +52,11 @@ function evaluateFix(fix, script, csp, contentReplace) { case "std-IntlRelativeTimeFormat": script.push(pf.Intl_RelativeTimeFormat_dummy); break; + case "std-NavigatorClipboard": + csp["script-src"].push("unpkg.com"); + script.push({"src": "https://unpkg.com/clipboard-polyfill@4.0.0/dist/es5/overwrite-globals/clipboard-polyfill.overwrite-globals.promise.es5.js", + "integrity": "sha384-5y9EbzFitRF4XTU0L+uQoWKyIAIkbKb/RV6kSZRKvilNx83HCi9ig9LP7kJqNJHX"}); + break; case "std-PerformanceObserver": csp["script-src"].push("unpkg.com"); script.push({"src": "https://unpkg.com/@fastly/performance-observer-polyfill@2.0.0/polyfill/index.js", @@ -77,6 +82,9 @@ function evaluateFix(fix, script, csp, contentReplace) { case "duolingo-regexp": contentReplace.push([String.raw`/\p{Diacritic}/gu`, `/${pf.Regex_UnicodePropertyDiacritic}/gu`]); break; + case "gh-codeview": + script.push(pf.Github_restoreCodeMenu); + break; case "gh-compat": script.push(pf.Github_customElements); script.push(pf.Window_ShadowRoot); diff --git a/lib/polyfills.js b/lib/polyfills.js index 0197a08..5e22aaf 100644 --- a/lib/polyfills.js +++ b/lib/polyfills.js @@ -323,6 +323,17 @@ exports.Github_disableTurbo = jss` }); `; +exports.Github_restoreCodeMenu = jss` + // Don't pass event to mouseup handler on the textarea that disables the context menu + const handler = function (evt) { + if (evt.target && evt.target.tagName === "TEXTAREA" && + evt.target.id == "read-only-cursor-text-area" && evt.button == 2) { + evt.stopPropagation(); + } + }; + document.addEventListener("mouseup", handler, {capture: true}); +`; + // Flavor of CE that Github used to distribute as part of github-compat-838cedbb.js exports.Github_customElements = jss`(function(){var t=new Set("annotation-xml color-profile font-face font-face-src font-face-uri font-face-format font-face-name missing-glyph".split(" "));function e(e){var n=t.has(e);return e=/^[a-z][.0-9_a-z]*-[\-.0-9_a-z]*$/.test(e),!n&&e}function n(t){var e=t.isConnected;if(void 0!==e)return e;for(;t&&!(t.__CE_isImportDocument||t instanceof Document);)t=t.parentNode||(window.ShadowRoot&&t instanceof ShadowRoot?t.host:void 0);return!(!t||!(t.__CE_isImportDocument||t instanceof Document))}function o(t,e){for(;e&&e!==t&&!e.nextSibling;)e=e.parentNode;return e&&e!==t?e.nextSibling:null}function r(t,e,n){n=void 0===n?new Set:n;for(var i=t;i;){if(i.nodeType===Node.ELEMENT_NODE){var a=i;e(a);var c=a.localName;if("link"===c&&"import"===a.getAttribute("rel")){if((i=a.import)instanceof Node&&!n.has(i))for(n.add(i),i=i.firstChild;i;i=i.nextSibling)r(i,e,n);i=o(t,a);continue}if("template"===c){i=o(t,a);continue}if(a=a.__CE_shadowRoot)for(a=a.firstChild;a;a=a.nextSibling)r(a,e,n)}i=i.firstChild?i.firstChild:o(t,i)}}function i(t,e,n){t[e]=n}function a(){this.a=new Map,this.g=new Map,this.c=[],this.f=[],this.b=!1}function c(t,e){t.b&&r(e,(function(e){return l(t,e)}))}function l(t,e){if(t.b&&!e.__CE_patched){e.__CE_patched=!0;for(var n=0;n