1

I want to copy some content from a website that has copy disabled by this part

$(document).bind('copy', function(e){
      return false;
});

I tried to unbind the function with $(document).off('copy'), and it works flawlessly in the console, but when in userscript it does not work.

I used Tampermonkey userscript to create a button to copy all content from a class with these lines

// Everything in this code block works in the console...
$(document).off('copy');
range.selectNode(document.getElementsByClassName('bbWrapper')[0]);
window.getSelection().removeAllRanges();
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();

Already have this in header // @require https://code.jquery.com/jquery-3.6.0.min.js

Also done this var $ = window.jQuery;

7
  • 1
    Remove @require and add // @grant none so the script will use jquery of the site. Commented Dec 12, 2022 at 12:52
  • @wOxxOm // @grant none has been there the whole time. I didn't delete it. I managed to get it right by using https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js instead of https://code.jquery.com/jquery-3.6.0.min.js. Thanks to this answer here Commented Dec 13, 2022 at 11:54
  • Note that @grant none is ignored if you have other @grant values. Commented Dec 13, 2022 at 12:18
  • There are no other grant values. I didn't add anything other than the require line. Commented Dec 13, 2022 at 12:45
  • In that case there should be no need to require jquery. Commented Dec 13, 2022 at 13:06

1 Answer 1

0

For some reason I can't use https://code.jquery.com/jquery-3.6.0.min.js. But thanks to this answer here, I changed the link to https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js. And it worked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.