12 votes

Extended Scripts for Tildes Alpha

So, after a rather clunky script to open comment's link in a new tab with the left click, I got inspired by the idea of @kalebo and wrote also a script to quickly jump to new comments in a topic.

I thought about writing a dedicated script but felt like it was going to become overly complicated for a user to import different script.

These script are all meant to give the community some QoL while lightening the pressure on @deimos so he can work without too much stress from all the requests. As soon as the feature are implemented you should get rid of those script that in some parts felt like bad hacks to me that I was writing it.

I know the button to scroll to new messages is in a quite bad position (top center of your browser page) but I couldn't bear to deal with tampermonkey issue and its GM_AddStyle meta not working properly so I had to use the basic CSS provided by spectre already loaded in tildes.net.

If someone knows how to figure out that goddamn meta, let me know.

========= UPDATE ============

Edit: So apparently tampermonkey has issues with styles that are not yet fixed and firefox has some issue in general with script that inject stuff in the page (understandably).

For tampermonkey the solution is simple. Use violentmonkey instead. you can just copy the script and it will work.

For Firefox it's a little more dirty unfortunately but I cannot find other solutions. You need to open the internal URL about:config. Then search security.csp.enable and double click to disable it. After this the script will work.
Firefox has a very strict policy and the only real solution would be to write an extension and I don't think it's worth the effort in the current state of development.
For full description of what that policy does, check the official doc from mozilla: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#Threats

10 comments

  1. [2]
    Fantastitech
    Link
    Modern browser extensions are just javascript. No need for things like tampermonkey or even jQuery anymore. This could be rewritten in a few lines of vanilla js, packaged, and be on the Chrome and...

    Modern browser extensions are just javascript. No need for things like tampermonkey or even jQuery anymore. This could be rewritten in a few lines of vanilla js, packaged, and be on the Chrome and Firefox extension markets in a couple hours.

    The new tab functionality could be rewritten without the jQuery overhead. Something like this would do it:

    var a = document.getElementsByTagName("a");
    Array.from(a).forEach(function(i) {
        var parent = i.parentElement.nodeName;
        if (parent == "H1") {
            i.setAttribute("target", "_blank");
        }
    });
    

    Scrolling to new comments would take a bit more work, but there's really no need for jQuery these days. Those five lines do it.

    4 votes
    1. crius
      (edited )
      Link Parent
      Yep I agree, it's just that tildes is written on top of jQuery and intercooler and I wanted to try my hand at some jQuery that I don't use since... Forever? I thought about an extension but in...

      Yep I agree, it's just that tildes is written on top of jQuery and intercooler and I wanted to try my hand at some jQuery that I don't use since... Forever?

      I thought about an extension but in alpha with the source code going to be released soon it wasn't worth it to go through the Chrome and Firefox market imho.

      Edit: I also decided to use jquery to allow non-tech to understand the gist of it and decide to trust the script or not. Most of the time JS have really convoluted way to do simple things (see when you need to remove an element from the DOM) while jquery simply does $('#this-guys').delete() that everyone really can undersand what it does.

      4 votes
  2. [2]
    Comment deleted by author
    Link
    1. crius
      Link Parent
      I thought about this (and honestly your current project is quite interesting from the technical standpoint already) but I just don't know how it will sit well with @Deimos intention of having this...

      I thought about this (and honestly your current project is quite interesting from the technical standpoint already) but I just don't know how it will sit well with @Deimos intention of having this website being the "front face" of the platform. At least if I remember correctly how it was worded in the announcement or one of the documents.

      I was even feeling kind of guilty in thinking about building a mobile app as soon as the APIs comes out just because I always wanted to try my hand at native mobile apps but hey, I say that until we respect the license that Deimos choose, every initiative is a good initiative :)

      4 votes
  3. [2]
    cfabbro
    Link
    This is a lifesaver! I have been monitoring the comments sections on the site to ensure there is no abusive behavior and with some of the larger ones it was getting incredibly painful to identify...

    This is a lifesaver! I have been monitoring the comments sections on the site to ensure there is no abusive behavior and with some of the larger ones it was getting incredibly painful to identify the new comment locations. This has made my life a lot easier... so thank you.

    2 votes
    1. crius
      Link Parent
      Hey, thanks @cfabbro, you're too kind as usual :) Please note that you can get rid of the script that opens comments link in new tab by default as it's included in this one. Also this works on any...

      Hey, thanks @cfabbro, you're too kind as usual :)

      Please note that you can get rid of the script that opens comments link in new tab by default as it's included in this one.

      Also this works on any fork of grease monkey as far as I've seen. There is a stricter security restriction on Firefox that prevent it from running, I'll try and identify and fix it by the end of today.

      1 vote
  4. crius
    Link
    ==== UPDATE ==== So apparently tampermonkey has issues with styles that are not yet fixed and firefox has some issue in general with script that inject stuff in the page (understandably). For...

    ==== UPDATE ====

    So apparently tampermonkey has issues with styles that are not yet fixed and firefox has some issue in general with script that inject stuff in the page (understandably).

    For tampermonkey the solution is simple. Use ViolentMonkey instead. you can just copy the script and it will work. They're both forks of GreaseMonkey and follow the same standards.

    For Firefox it's a little more dirty unfortunately but I cannot find other solutions. You need to open the internal URL about:config. Then search security.csp.enable and double click to disable it. After this the script will work.
    For full description of what that policy does, check the official doc from mozilla: https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP#Threats
    Firefox has a very strict policy and the only real solution would be to write an extension and I don't think it's worth the effort in the current state of development.

    I also just updated the script to put the button in a more natural position (on the right side where there is plenty of free space) and thanks to ViolentMonkey supporting add styles properly I managed to make it not create an invisible overlay on the line it appears that make impossible clicking on elements on the same Y-axis of the button in the current version.

    2 votes
  5. cfabbro
    Link
    Bumping this post so people are aware of this script... it's been a lifesaver for me. ;)

    Bumping this post so people are aware of this script... it's been a lifesaver for me. ;)

    2 votes
  6. [3]
    kalebo
    Link
    This looks like it would be an improvement over my snippet, but the button to jump to new is not showing up with Violentmonkey (I'm not a fan of tampermonkey's licence) on Firefox. In short CSP...

    This looks like it would be an improvement over my snippet, but the button to jump to new is not showing up with Violentmonkey (I'm not a fan of tampermonkey's licence) on Firefox. In short CSP strikes again. I'm assuming it has something to do with this issue. I'll have to see if there is a work around when I have more time.

    1 vote
    1. crius
      (edited )
      Link Parent
      Hey I didn't check violentMonkey and choose tamperMonkey just because someone else suggested it. If you think you can port it for ViolentMonkey just share the code! It's always JS I mean, it's...

      Hey I didn't check violentMonkey and choose tamperMonkey just because someone else suggested it. If you think you can port it for ViolentMonkey just share the code!

      It's always JS I mean, it's probably different only in the metadata of the header?

      Edit: It could be something with specific on firefox. I tested only on chrome, I'll give it a look tomorrow :)

      3 votes
    2. crius
      Link Parent
      Yep, just loaded violentmonkey on chrome and it works. Definitely something with firefox. Weird :-/

      Yep, just loaded violentmonkey on chrome and it works. Definitely something with firefox. Weird :-/

      1 vote