Skip to content

Instantly share code, notes, and snippets.

@RyadPasha
Last active January 24, 2025 17:15
Show Gist options
  • Save RyadPasha/c60ccdd4fd98d3cede9fc4231cfdbb5a to your computer and use it in GitHub Desktop.
Save RyadPasha/c60ccdd4fd98d3cede9fc4231cfdbb5a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Teams Copy Enabler
// @namespace http://tampermonkey.net/
// @version 2024-12-09
// @description Allow Copy and Right Click in Teams
// @author Mohamed Riyad
// @match https://teams.live.com/**
// @match https://teams.microsoft.com.mcas.ms/**
// @run-at document-start
// @icon https://statics.teams.cdn.live.net/evergreen-assets/icons/microsoft_teams_logo_refresh.ico
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Store the original methods
const originalAddEventListener = EventTarget.prototype.addEventListener;
const originalRemoveEventListener = EventTarget.prototype.removeEventListener;
// Override addEventListener
EventTarget.prototype.addEventListener = function (type, listener, options) {
if (type === 'copy' || type === 'contextmenu') {
console.log(`Blocked a '${type}' event listener:`, listener);
return; // Prevent adding listeners for restricted events
}
return originalAddEventListener.call(this, type, listener, options);
};
// Ensure removeEventListener works as expected
EventTarget.prototype.removeEventListener = function (type, listener, options) {
return originalRemoveEventListener.call(this, type, listener, options);
};
// Override `oncopy` and `oncontextmenu` for inline event handlers
const handlerProperties = ['oncopy', 'oncontextmenu'];
handlerProperties.forEach(prop => {
Object.defineProperty(document, prop, {
set: function (handler) {
console.log(`Blocked an inline handler for '${prop}':`, handler);
},
get: function () {
return null; // No inline handlers allowed
},
configurable: true,
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment