12

I can't seem to figure this out. I've been trying out different news aggregator sites to use as a home page. Right now I'm using skimfeed. I like it, but the links all have skimfeed baggage tacked on. Like this: https://skimfeed.com/r.php?q=1148&l=15649995&u=https%3A%2F%2Fxkcd.com%2F3006%2F

Well, the source looks like this:

<span class='boxtitles'><h2><a class='siteurls ts33' href='/news/xkcd.html'>XKCD</a> <a class='siteurls atat' href='http://xkcd.com' rel='nofollow' target='_blank'>+</a></h2></span>

<ul><li class='nl1 bd33'><a href='r.php?q=1148&l=15649995&u=https%3A%2F%2Fxkcd.com%2F3006%2F' target='_blank' rel='nofollow' title='Demons'>Demons</a> </li><li class='nl2 bd75'><a href='r.php?q=1148&l=15642742&u=https%3A%2F%2Fxkcd.com%2F3005%2F' target='_blank' rel='nofollow' </li></ul></div>

Which, to be honest, is Greek to me. I'd like to rewrite the links so that they just look like https://xkcd.com/3006/ I don't really care what the link looks like, per se, the encoded bits. I just don't like the extra skimfeed stuff. Aesthetically.

Is there an extension or something that will help me with this? The couple I've looked at are either too complicated for my caveman brain, or site specific (i.e., remove google tracking). If I'm just being a little too retentive, feel free to let me know that too.

you are viewing a single comment's thread
view the rest of the comments
[-] e0qdk@reddthat.com 5 points 1 week ago* (last edited 1 week ago)

I'm not sure what the best way to make using it convenient is, but you could paste something like this into the JS console to rewrite all the r.php links:

(function() {
  let links = [...document.getElementsByTagName("a")];
  links.forEach(link => {
    if(link.href.startsWith("https://skimfeed.com/r.php"))
    {
      let url = new URL(link.href);
      let clean_link = url.searchParams.get("u");
      link.href = clean_link;
    }
  });
})();

The basic idea of my JS snippet is that it looks for all the anchor tags (i.e. <a href='...'>), finds the ones that link to r.php, extracts the u query parameter which appears to contain the actual URL of interest, and then replaces the href attribute of the anchor (i.e. the part of the HTML that contains the destination URL) with the clean URL. That entire snippet of logic is wrapped in an anonymous function which is then immediately called so that you can just paste the snippet in more or less wherever it makes sense to trigger the logic.

Way back in the day I would've stuck snippets like that into GreaseMonkey scripts, but I haven't messed with that stuff in a long time and I'm not sure which extensions are still good to use for doing that kind of thing.

Apologies in advance if my snippet is not perfectly correct; I'm not familiar with that site and wrote this off the cuff when I saw your post. Hopefully it's helpful though.

[-] sin_free_for_00_days@sopuli.xyz 6 points 1 week ago* (last edited 1 week ago)

Thank you so much. I didn't even think about Greasemonkey. I went to make a script using your code and it said there was already one available. That script looks like this:

Edit: Updated script

(function() {
    'use strict';

    var links = document.links;
    for (var i = 0; i < links.length; i++) {
        var referer = links[i].href.indexOf('&u=');
        links[i].href = decodeURIComponent(links[i].href.substr(referer + 3));
    }

})();

and it worked fine. Then I replaced that code with yours, and it worked just as well. Thanks again.

[-] e0qdk@reddthat.com 3 points 1 week ago

I think you copied my snippet into your comment by mistake rather than whatever you found elsewhere, but regardless, happy I could help!

[-] sin_free_for_00_days@sopuli.xyz 3 points 1 week ago

You're right. I updated my response.

this post was submitted on 03 Nov 2024
12 points (100.0% liked)

Firefox

4015 readers
1 users here now

A community for discussion about Mozilla Firefox.

founded 1 year ago
MODERATORS