LeetCode solution article widener

Add a toggle to widen the solution articles to view long code easier.

目前为 2022-12-12 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name LeetCode solution article widener
  3. // @namespace https://github.com/zica87/self-made-userscipts
  4. // @version 1.0
  5. // @description Add a toggle to widen the solution articles to view long code easier.
  6. // @author zica
  7. // @match https://leetcode.com/problems/*/solutions/*/*/
  8. // @grant none
  9. // @license GPL-2.0
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. const toggle = document.createElement('button');
  16. toggle.innerText = '←→';
  17. Object.assign(toggle.style, {
  18. color: 'white',
  19. backgroundColor: 'rgb(40 40 40)',
  20. borderRadius: '0.75rem',
  21. padding: '1em',
  22. fontSize: '110%',
  23. fontWeight: 'bold',
  24. zIndex: '999',
  25. position: 'fixed',
  26. bottom: '5vh',
  27. right: '2vw',
  28. });
  29. toggle.onclick = ()=>{
  30. if (toggle.innerText === '←→'){
  31. document.getElementsByClassName('lc-lg:w-[250px]')[0].hidden = true;
  32. document.getElementsByClassName('max-w-[1020px]')[0].style.maxWidth = 'none';
  33. document.getElementsByClassName('lc-lg:max-w-[700px]')[0].style.maxWidth = 'none';
  34. toggle.innerText = 'Default';
  35. }
  36. else{
  37. document.getElementsByClassName('max-w-[1020px]')[0].style = '1020px';
  38. document.getElementsByClassName('lc-lg:max-w-[700px]')[0].style.maxWidth = '700px';
  39. document.getElementsByClassName('lc-lg:w-[250px]')[0].hidden = false;
  40. toggle.innerText = '←→';
  41. }
  42. };
  43. document.body.appendChild(toggle);
  44. })();