From 233b804f66fa8ab88d4ce8c2b9d466fbe8b9a7b8 Mon Sep 17 00:00:00 2001 From: Mayur Kumar <102611744+mayur-kumar1@users.noreply.github.com> Date: Tue, 20 Sep 2022 16:35:42 +0100 Subject: [PATCH] feat: Add support for iframes Also removed the annoying mcas iframe which gives a pop-up if you press command+c. --- README.md | 13 +++++++++++-- copy.js | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e2975bd..0b56799 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,21 @@ A small snippet to add your own copy method, in case the original one has been tampered with. ``` -document.onkeyup = function(e) { +var frames = document.getElementsByTagName("iframe"); +let copyFunction = function(e) { if (e.ctrlKey && e.which == 67) { - var text = window.getSelection().toString() + var text = this.window.getSelection().toString() navigator.clipboard.writeText(text) } } +document.onkeyup = copyFunction +for (let i = 0; i < frames.length; ++i) { + if (frames[i].id == 'mcas-presence-frame-do-not-remove') { + frames[i].parentNode.removeChild(frames[i]) + } else { + frames[i].contentWindow.onkeyup = copyFunction + } +} ``` 1. Copy the above snippet. diff --git a/copy.js b/copy.js index b404105..3ec7cbc 100644 --- a/copy.js +++ b/copy.js @@ -1,6 +1,15 @@ -document.onkeyup = function(e) { +var frames = document.getElementsByTagName("iframe"); +let copyFunction = function(e) { if (e.ctrlKey && e.which == 67) { - var text = window.getSelection().toString() + var text = this.window.getSelection().toString() navigator.clipboard.writeText(text) } } +document.onkeyup = copyFunction +for (let i = 0; i < frames.length; ++i) { + if (frames[i].id == 'mcas-presence-frame-do-not-remove') { + frames[i].parentNode.removeChild(frames[i]) + } else { + frames[i].contentWindow.onkeyup = copyFunction + } +}