Please excuse my sub-par JavaScript, I am a backend dev.

All you need to do is paste this into Tampermonkey and enter your username and your instance url (on two locations).

This is not showing other users’ scores and it doesn’t make your score visible to anyone else than yourself.

So no need for karma farming. This is just for fun.

// ==UserScript==
// @name         Lemmy score
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Shows your total post/comment score at the top right.
// @author       You
// @match        ENTER INSTANCE URL HERE (leave the asterisk after the URL)*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=feddit.de
// @grant        none
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    var USERNAME = "ENTER USERNAME HERE";
    var INSTANCE_URL = "ENTER INSTANCE URL HERE";

    var totalScore = 0;
    var currentPage = 1;

    function postResult() {
        var navbar = document.getElementsByClassName("collapse navbar-collapse")[0];
        console.log(navbar);
        var ul = document.createElement("ul");
        ul.className = "navbar-nav";
        ul.id = "karma-ul";
        var li = document.createElement("li");
        li.id = "karma-li";
        li.className = "nav-item";
        li.innerHTML = '<div id="karma-div">' + totalScore + '</div>'
        navbar.appendChild(ul);
        ul.appendChild(li);
    }
    function callPage() {
        var userRequest = new XMLHttpRequest();
        userRequest.onreadystatechange = function () {
            if (this.readyState == 4) {
                if (this.status == 200 ) {
                    var res = JSON.parse(this.responseText);
                    if (res.posts.length==0 && res.comments.length==0) {
                        postResult();
                    } else {
                        totalScore += res.posts.map(x => x.counts.score).reduce((partialSum, a) => partialSum + a, 0);
                        totalScore += res.comments.map(x => x.counts.score).reduce((partialSum, a) => partialSum + a, 0);
                        currentPage++;
                        callPage();
                    }
                }
            }
        }
        userRequest.open("GET", INSTANCE_URL + "/api/v3/user?username=" + USERNAME + "&limit=50&page=" + currentPage, true);
        userRequest.send();
    }

    setTimeout(callPage, 200);


    /*var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4) {
          if (this.status == 200 ) {
            var obj = JSON.parse(this.responseText);
            var simple = document.getElementById("simple");
            if (obj.response == 200) {
              simple.style = "color:green";
            }
            else {
              simple.style = "color:red";
            }
          }
        }
      };
      //make call to Google App Engine
      xhttp.open("GET", "https://simplewikiexists.appspot.com/?q=" + article, true);
      xhttp.send();*/
})();
      • borlax@lemmy.borlax.com
        link
        fedilink
        arrow-up
        4
        ·
        1 year ago

        Fair… My concern is people starting to engage with content here only for the promise of fake internet points.

        To each their own tho.

        • Square Singer@feddit.deOP
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          I see your point. On the other hand, my script doesn’t allow showing off these fake internet points.

          I could have made a script that edits the score into your profile, but I didn’t want to do that since it would allow showing off. And that could be problematic, because then people would do what you fear.

          But I don’t quite see why anyone would farm score just so that they themselves can see a higher number that has no actual value at all.

        • fidodo@beehaw.org
          link
          fedilink
          arrow-up
          1
          ·
          1 year ago

          Isn’t the actual point that other people can see your karma? That’s not a risk with this script. I mean you could go around telling people your karma but that’d be super lame.

        • Storksforlegs@beehaw.org
          link
          fedilink
          arrow-up
          1
          ·
          edit-2
          1 year ago

          I agree, I don’t think I’ll be using it. But I don’t see the harm in people wanting to keep track if they have the option. :)

    • Square Singer@feddit.deOP
      link
      fedilink
      arrow-up
      2
      ·
      1 year ago

      Apparently not, since it’s two quite different things. The first one was a Python script that you can run from the console and every time you want to know the value, you need to re-run it.

      This here is a Tampermonkey script which you can just add once and it’s working all the time.

      I would have edited it into the other post, but there was some discussion on the other post that edits to posts don’t seem to work on federated instances right now. So apparently a second post was necessary.