Better XDA

Hide bullshit articles on xda-dev home page.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
//

// @name         Better XDA
// @version      1.0
// @run-at       document-end
// @license      LGPLv3
// @homepage localhost
// @description  Hide bullshit articles on xda-dev home page.
// @match       https://www.xda-developers.com/*
// @icon https://www.xda-developers.com/public/build/images/favicon-48x48.8f822f21.png
// @author       Bahha
// @namespace https://greasyfork.org/users/186498
// ==/UserScript==

//wait for page to load
const delay = ms => new Promise(res => setTimeout(res, ms));

// specify authors to remove
var removedAuthors = ["Mahmoud Itani", "Adam Conway", "Timi Cantisano", "Rich Woods","João Carrasqueira"]; //add your authors here

// get list of authors.
const waitAndGetData = async () => {

  //trigger infinitescroll, because it doesn't work when aritcles are removed the first time. taken from xda js file.
  (r = document.getElementById("home-waypoint")) &&
          null != window.infiniteScrollUrl &&
          null != window.infiniteScrollMax &&
          null != window.infiniteScrollArticlesRequested &&
          (console.log("home infinite scroll"),
          new LatestBrowseClip({
            ajaxUrl: window.infiniteScrollUrl,
            waypointElement: r,
            divSection: document.getElementsByClassName(
              window.infiniteScrollDivSectionClass
            )[0],
            totalNumClips: window.infiniteScrollMax,
            numClipsRequested: window.infiniteScrollArticlesRequested,
            animLoadinId: "infinite-loader",
            archivePath: window.infiniteScrollArchivePathUrl,
            excludedIds: window.infiniteScrollExcludedIds,
            divClassName: window.infiniteScrollListingClass,
            showMoreButton: !0,
          }).wayPointTrigger());

  //wait 2 sec for page to load
  await delay(2000);
  // get athors
  var authors = document.getElementsByClassName("bc-author");
  // counter for removed articles
  var removed = 0 ;
  // cycle through authors and remove matched ones or rather hide them, you can use remove() instead of display:none
  for(var i = 0 ; i < authors.length ; i++){

    // check for an author match
    if(removedAuthors.includes(authors[i].text)){
        //console.log(authors[i].text);
        // hide articles
        authors[i].closest("article").style.display = "none";
        console.log(authors[i].text + " " +i + " removed");
        removed++;
    }
  }

  console.log("removed " + removed);
};


// throtlle sroll event for performance
var throttleTimer;

const throttle = (callback, time) => {

  if (throttleTimer) return;

  throttleTimer = true;

  setTimeout(() => {

    callback();

    throttleTimer = false;

  }, time);

};

// re-run code on scroll
const handleInfiniteScroll = () => {

  throttle(() => {

      console.log("you scrolled")
      waitAndGetData();

    // wait for 6 seconds. change it to your preference.
  },6000);

};
//call function when page loads the first time
waitAndGetData();
// call function on scroll event detection.
window.addEventListener("scroll", handleInfiniteScroll);