Better XDA

Hide bullshit articles on xda-dev home page.

  1. // ==UserScript==
  2. //
  3.  
  4. // @name Better XDA
  5. // @version 1.0
  6. // @run-at document-end
  7. // @license LGPLv3
  8. // @homepage localhost
  9. // @description Hide bullshit articles on xda-dev home page.
  10. // @match https://www.xda-developers.com/*
  11. // @icon https://www.xda-developers.com/public/build/images/favicon-48x48.8f822f21.png
  12. // @author Bahha
  13. // @namespace https://greasyfork.org/users/186498
  14. // ==/UserScript==
  15.  
  16. //wait for page to load
  17. const delay = ms => new Promise(res => setTimeout(res, ms));
  18.  
  19. // specify authors to remove
  20. var removedAuthors = ["Mahmoud Itani", "Adam Conway", "Timi Cantisano", "Rich Woods","João Carrasqueira"]; //add your authors here
  21.  
  22. // get list of authors.
  23. const waitAndGetData = async () => {
  24.  
  25. //trigger infinitescroll, because it doesn't work when aritcles are removed the first time. taken from xda js file.
  26. (r = document.getElementById("home-waypoint")) &&
  27. null != window.infiniteScrollUrl &&
  28. null != window.infiniteScrollMax &&
  29. null != window.infiniteScrollArticlesRequested &&
  30. (console.log("home infinite scroll"),
  31. new LatestBrowseClip({
  32. ajaxUrl: window.infiniteScrollUrl,
  33. waypointElement: r,
  34. divSection: document.getElementsByClassName(
  35. window.infiniteScrollDivSectionClass
  36. )[0],
  37. totalNumClips: window.infiniteScrollMax,
  38. numClipsRequested: window.infiniteScrollArticlesRequested,
  39. animLoadinId: "infinite-loader",
  40. archivePath: window.infiniteScrollArchivePathUrl,
  41. excludedIds: window.infiniteScrollExcludedIds,
  42. divClassName: window.infiniteScrollListingClass,
  43. showMoreButton: !0,
  44. }).wayPointTrigger());
  45.  
  46. //wait 2 sec for page to load
  47. await delay(2000);
  48. // get athors
  49. var authors = document.getElementsByClassName("bc-author");
  50. // counter for removed articles
  51. var removed = 0 ;
  52. // cycle through authors and remove matched ones or rather hide them, you can use remove() instead of display:none
  53. for(var i = 0 ; i < authors.length ; i++){
  54.  
  55. // check for an author match
  56. if(removedAuthors.includes(authors[i].text)){
  57. //console.log(authors[i].text);
  58. // hide articles
  59. authors[i].closest("article").style.display = "none";
  60. console.log(authors[i].text + " " +i + " removed");
  61. removed++;
  62. }
  63. }
  64.  
  65. console.log("removed " + removed);
  66. };
  67.  
  68.  
  69. // throtlle sroll event for performance
  70. var throttleTimer;
  71.  
  72. const throttle = (callback, time) => {
  73.  
  74. if (throttleTimer) return;
  75.  
  76. throttleTimer = true;
  77.  
  78. setTimeout(() => {
  79.  
  80. callback();
  81.  
  82. throttleTimer = false;
  83.  
  84. }, time);
  85.  
  86. };
  87.  
  88. // re-run code on scroll
  89. const handleInfiniteScroll = () => {
  90.  
  91. throttle(() => {
  92.  
  93. console.log("you scrolled")
  94. waitAndGetData();
  95.  
  96. // wait for 6 seconds. change it to your preference.
  97. },6000);
  98.  
  99. };
  100. //call function when page loads the first time
  101. waitAndGetData();
  102. // call function on scroll event detection.
  103. window.addEventListener("scroll", handleInfiniteScroll);