Kleinanzeigen WASD Navigation Upgrade

Navigate Kleinanzeigen with arrow keys and click "Show More" button on main page, along with CSS modifications

  1. // ==UserScript==
  2. // @name Kleinanzeigen WASD Navigation Upgrade
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description Navigate Kleinanzeigen with arrow keys and click "Show More" button on main page, along with CSS modifications
  6. // @author moritz
  7. // @icon https://www.google.com/s2/favicons?sz=64&domain=kleinanzeigen.de
  8. // @match https://www.kleinanzeigen.de/*
  9. // @license MIT
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16.  
  17. // https://greasyfork.org/scripts/448672-ebay-kleinanzeigen-ad-blocker/code/Ebay-Kleinanzeigen%20Ad%20Blocker.user.js
  18. // j-liberty-wrapper are the two ads at the top,
  19. // ad-listitem without any other suffix are the ads mixed within the results
  20. var ads = document.querySelectorAll('[class="ad-listitem"],[class="j-liberty-wrapper "]')
  21. ads.forEach((ad) => {
  22. ad.style.display = "none"
  23. })
  24.  
  25.  
  26. document.addEventListener('keydown', function(e) {
  27. if (e.key === 'ArrowLeft' || e.key === 'a') {
  28. navigatePage('prev');
  29. } else if (e.key === 'ArrowRight' || e.key === 'd') {
  30. navigatePage('next');
  31. }
  32. });
  33.  
  34. function navigatePage(direction) {
  35. var currentPage = getCurrentPageNumber();
  36. var nextPage;
  37.  
  38. if (direction === 'prev' && currentPage > 1) {
  39. nextPage = currentPage - 1;
  40. } else if (direction === 'next') {
  41. nextPage = currentPage + 1;
  42. } else {
  43. return; // Do nothing for other keys
  44. }
  45.  
  46. var currentURL = window.location.href;
  47. var newURL;
  48.  
  49. if (currentPage === 1) {
  50. newURL = currentURL.replace(/(\/[^\/]+)(\/[^\/]+)$/, '$1/seite:' + nextPage + '$2');
  51. } else {
  52. newURL = currentURL.replace(/\/seite:\d+/, '/seite:' + nextPage);
  53. }
  54.  
  55. window.location.href = newURL;
  56. }
  57.  
  58. // Funktion für das Klicken auf den "Show More" Button auf der Hauptseite
  59. window.addEventListener('load', function() {
  60. var button = document.querySelector('.button-secondary.j-feed-show-more');
  61.  
  62. if (button && window.location.href === 'https://www.kleinanzeigen.de/') {
  63. // Klicken Sie auf den Button mehrmals
  64. button.click();
  65. button.click();
  66. button.click();
  67. button.click();
  68. button.click();
  69. button.click();
  70. }
  71. });
  72.  
  73. // CSS-Anpassungen
  74. var cssStyles = `
  75. #brws_banner-supersize { display: none !important; }
  76. #btf-billboard { display: none !important; }
  77. #home-billboard { display: none !important; }
  78. #home-gallery { display: none !important; }
  79. #srp-skyscraper-btf { display: none !important; }
  80. #store-gallery { display: none !important; }
  81. #viewad-sidebar-banner { display: none !important; }
  82. .ad-listitem.badge-topad.is-topad { display: none !important; }
  83. .site-base--left-banner { display: none !important; }
  84. .site-base--right-banner { display: none !important; }
  85. [id^="#home-"] { display: none !important; }
  86. [id^="srpb"] { display: none !important; }
  87. [id^="vip-"] { display: none !important; }
  88. #home-ads { display: none !important; }
  89. #my-msgbox-atf { display: none !important; }
  90. #my-watchlist-atf { display: none !important; }
  91. #my_ads-top-banner { display: none !important; }
  92. #site-content { padding-left: 30px; width: 2430px; }
  93. .l-splitpage-navigation { margin-right: 50px; width: 330px; }
  94. .l-splitpage-flex > .l-splitpage-content { width: 2200px; }
  95. .l-homepage-content-col { width: 2100px; float: left; }
  96. `;
  97.  
  98. var styleElement = document.createElement('style');
  99. styleElement.type = 'text/css';
  100. styleElement.appendChild(document.createTextNode(cssStyles));
  101. document.head.appendChild(styleElement);
  102.  
  103. function getCurrentPageNumber() {
  104. var currentPageElement = document.querySelector('.pagination-current');
  105. if (currentPageElement) {
  106. return parseInt(currentPageElement.textContent);
  107. } else {
  108. // If there is no pagination element, assume it's page 1
  109. return 1;
  110. }
  111. }
  112. })();