Copy Leetcode Question

Copy question text from Leetcode

Version vom 01.12.2023. Aktuellste Version

  1. // ==UserScript==
  2. // @name Copy Leetcode Question
  3. // @namespace https://ding-project.web.app/
  4. // @version 0.2
  5. // @description Copy question text from Leetcode
  6. // @author DingWDev
  7. // @match *://leetcode.com/problems/*
  8. // @match *://leetcode.cn/problems/*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=leetcode.com
  10. // @grant none
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16. document.onkeydown = function (e) {
  17. if (e.ctrlKey && e.key == 'c') {
  18. e.preventDefault();
  19. var question = (document.querySelector('.elfjS')||document.querySelector('div[data-track-load="description_content"]')).innerText,
  20. languageEl = document.querySelector('.popover-wrapper button.whitespace-nowrap')||document.querySelector('.notranslate button div>div'),
  21. language = languageEl?languageEl.innerText:'';
  22. [].forEach.call(document.querySelectorAll('sup'), function(sup){
  23. var previousText = sup.previousSibling.textContent;
  24. question = question.replace(previousText + sup.innerText, previousText + '^' + sup.innerText);
  25. });
  26. navigator.clipboard.writeText(('Solve the following question'+ (language?' in '+ language :'') + ':\n\nQuestion:\n' + question));
  27. }
  28. }
  29. })();