Don't speak German? Here's a userscript for you

3 years ago by trent to c/kbinMeta

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();
})();
10A 29 points 3 years ago

So disappointing. I clicked on this hoping your userscript would teach me German.

path: 0 413788, hotness: undefined, score: 29, children: 7
dreadgoat 7 points 3 years ago

If you use Chrome, the world is your oyster at this point. Translation tools are getting amazing.

Text post, or title? Highlight, right click, translate. Done.

Oh no, but it's a meme/image/screenshot. Guess you're screwed, right? Gotta pull out your phone and use google lens, way too annoying, right? Wrong! Go to chrome://flags and enable "Translate text in images with Google Lens". Now you can right click anywhere to translate the page to English, and then just right-click any image and get a translated version.

Now go meme on some Germans. It is Wednesday, after all.

path: 0 413788 417413, hotness: undefined, score: 7, children: 3
trent 2 points 3 years ago

This is great, and true too, but I hate google man. Gonna wait to see when translation tools like this become FOSS. I think AI might get us there. In the meantime, LibreTranslate does good for translation and Tesseract works for OCR.

path: 0 413788 417413 463972, hotness: undefined, score: 2, children: 0
pikameiser 2 points 3 years ago

I appreciate you!

path: 0 413788 417413 427373, hotness: undefined, score: 2, children: 0
Xeelee 1 point 3 years ago

Irgendwas irgendwas ... Mittwochsfrosch

path: 0 413788 417413 439098, hotness: undefined, score: 1, children: 0
DrNeurohax 5 points 3 years ago

Must be a bug. I tried it and now my dog speaks German, but I can only speak to bacteria. You wouldn't believe what assholes they are!

path: 0 413788 422178, hotness: undefined, score: 5, children: 0
Xeelee 1 point 3 years ago

Repeat after me:

"Bier her, aber zackig!"

"Wo gibt's hier die beste Schweinshaxe, Du Hurensohn?"

"Nein, ich habe keine Fahrkarte, Du Möchtegern-Blockwart!"

"Ich rede nicht mit Subalternen. Bringen Sie mir sofort den Geschäftsführer!"

You are now fully prepared for your holiday in Germany,

path: 0 413788 447119, hotness: undefined, score: 1, children: 1
aussiematt 1 point 3 years ago

"How to Win Friends and Influence People" in one short lesson :-)

path: 0 413788 447119 484500, hotness: undefined, score: 1, children: 0
BaroqueInMind 1 point 3 years ago

Thank you for developing this!

path: 0 414298, hotness: undefined, score: 1, children: 0
chibi-totoro 1 point 3 years ago

I assume a setting for this would already be in the dev backlog? Does anyone know if there is an issue logged for this?

path: 0 455451, hotness: undefined, score: 1, children: 1
trent 1 point 3 years ago

I didn't check and didn't make one, but there certainly should be I agree. Take this as a hotfix

path: 0 455451 456812, hotness: undefined, score: 1, children: 0
marcf 1 point 3 years ago

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

path: 0 412515, hotness: undefined, score: 1, children: 5
noughtnaut 1 point 3 years ago

Edit: Disregard this comment; I see you've solved your problem elsehow.

How did you modify your script?
const allowedLangs = ["de", "es"]; // This should work
or
const allowedLangs = ["de, es"]; // This will not work

Good luck friend.

path: 0 412515 438364, hotness: undefined, score: 1, children: 0
trent 1 point 3 years ago

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?
path: 0 412515 412575, hotness: undefined, score: 1, children: 3
marcf 2 points 3 years ago

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!

path: 0 412515 412575 412863, hotness: undefined, score: 2, children: 1
trent 1 point 3 years 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 /

path: 0 412515 412575 412863 413372, hotness: undefined, score: 1, children: 0
marcf 1 point 3 years ago

Aha! Does not appear to be running. Will investigate…

path: 0 412515 412575 412682, hotness: undefined, score: 1, children: 0
ImplyingImplications 1 point 3 years ago

I've just made it a fun game to read the post and try to guess what it could mean!

path: 0 412399, hotness: undefined, score: 1, children: 3
trent 4 points 3 years ago path: 0 412399 412400, hotness: undefined, score: 4, children: 2
ImplyingImplications 5 points 3 years ago

German is such a beautiful language

path: 0 412399 412400 413447, hotness: undefined, score: 5, children: 0
Setarkus 4 points 3 years ago

"Wtf is that title?!... Oh, it's 'Bild', makes sense."

path: 0 412399 412400 413590, hotness: undefined, score: 4, children: 0
kbinMeta

@kbin.social

login for more options
639
1280
1

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

go to feed...