Hide Promotion Advertisement at Codewars Site

Remove certain elements from the page

目前为 2024-08-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Hide Promotion Advertisement at Codewars Site
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Remove certain elements from the page
  6. // @author aspen138
  7. // @match *://*.codewars.com/kata/*
  8. // @icon https://www.google.com/s2/favicons?domain=codewars.com
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13.  
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Function to remove elements and adjust styles
  19. function adjustElements() {
  20. const descriptionFooter = document.querySelector('.description-footer');
  21. const partnerDisplay = document.getElementById('partner-display');
  22. const textCenter = document.querySelector('.text-center');
  23. const bonusPointsHeader = document.getElementById('bonus-points-not-really-but-just-for-fun');
  24. const descriptionFullHeight = document.querySelector('.description.h-full');
  25. const descriptionContent = descriptionFullHeight ? descriptionFullHeight.querySelector('.description-content') : null;
  26.  
  27. if (descriptionFooter) {
  28. descriptionFooter.remove();
  29. }
  30.  
  31. if (partnerDisplay) {
  32. partnerDisplay.remove();
  33. }
  34.  
  35. if (textCenter) {
  36. textCenter.remove();
  37. }
  38.  
  39. if (bonusPointsHeader) {
  40. bonusPointsHeader.remove();
  41. }
  42.  
  43. if (descriptionContent) {
  44. descriptionContent.style.height = '100%';
  45. descriptionContent.style.display = 'flex';
  46. descriptionContent.style.flexDirection = 'column';
  47. }
  48. }
  49.  
  50. // Initial adjustment
  51. adjustElements();
  52.  
  53. // Listen for URL changes
  54. window.addEventListener('popstate', adjustElements);
  55. window.addEventListener('hashchange', adjustElements);
  56.  
  57. // Observe DOM changes
  58. const observer = new MutationObserver(() => {
  59. adjustElements();
  60. });
  61.  
  62. observer.observe(document.body, { childList: true, subtree: true });
  63.  
  64. // Reapply adjustments every 5 seconds
  65. setInterval(adjustElements, 5000);
  66.  
  67. })();
  68.  
  69.