this post was submitted on 21 Jun 2023
29 points (100.0% liked)

/kbin meta

200 readers
2 users here now

Magazine dedicated to discussions about the kbin itself. Provide feedback, ask questions, suggest improvements, and engage in conversations related to the platform organization, policies, features, and community dynamics. ---- * Roadmap 2023 * m/kbinDevlog * m/kbinDesign

founded 1 year ago
 

Recently, especially with feddit.de, there are a lot of posts in languages that are not English. This is great for adoption!, but unfortunately I have no idea what the posts are about because I don't speak German. I couldn't find a setting to hide posts in other languages either!

To make my feed better for myself, I wrote a simple user script which removes any posts that are tagged anything other than EN/ES (the two languages I can speak.

Update the script to your preferences (make sure to @match your instance), and load it up in TamperMonkey!

Here you go:

// ==UserScript==
// @name         Kbin: delete articles in other languages
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Auto-delete posts in languages you do not speak.
// @author       luphoria (https://kbin.social/u/trent)
// @match        https://kbin.social/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=kbin.social
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  const allowedLangs = ["en"]; // <-- Edit this to all of the languages you can speak / want to see in your feed. Format: ["lang", "lang", "lang"]

  let deleteUnwantedPosts = () => {
    const postTags = document.getElementsByClassName("kbin-bg");

    for (let i = 0; i < postTags.length; i++) {
      let postTag = postTags[i];
      if (postTag && postTag.textContent && postTag.textContent !== "OC" && !allowedLangs.includes(postTag.textContent)) { // OC tags are the only elements (i know of) with the same class.
        // Delete element's parent's parent's parent
        if (postTag.parentElement.children[0].textContent) {
          console.log(`Removing post labeled \`${postTag.textContent}\`: "${postTag.parentElement.children[0].textContent}"`);
          postTag.parentElement.parentElement.parentElement.remove();
        }
      }
    }
  }
  deleteUnwantedPosts(); // on load

  // for continuous feeds
  let observeDOMChanges = () => {
    const observer = new MutationObserver(function(mutationsList) {
      deleteUnwantedPosts();
    });
    observer.observe(document.body, { childList: true, subtree: true });
  }
  observeDOMChanges();
})();

you are viewing a single comment's thread
view the rest of the comments
[–] marcf@kbin.social 1 points 1 year ago (4 children)

Might be user error, but still seeing non-English articles (de, es). Script appears to be installed correctly.

[–] trent@kbin.social 1 points 1 year ago (3 children)

hmm

  • is it showing a red [1] in the extension list (to signify that it's running) on the homepage?
  • what device & window size are you using?
[–] marcf@kbin.social 2 points 1 year ago* (last edited 1 year ago) (1 children)

Wasn't running! Added an * to the @match url and that seems to have fixed it. I default to /sub as my home, so perhaps that was the problem?

Thanks for the script!

[–] trent@kbin.social 1 points 1 year ago

glad you got it working for you (and I should probably update it to wildcard kbin.social, with that in mind)! I think your observation is right on the mark because my homepage is all, or /

load more comments (1 replies)
load more comments (1 replies)