Spyke

Posts

lemmy·LemmybyAlex

A Tampermonkey script that displays your “karma” score next to your user name

Crossgeposted from: https://feddit.de/post/1185964

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);
})();
View original on geddit.social
1
lemmy·LemmybyAlex

LemmyTools - Userscript - 0.1.2 - Released!

Cross-posted from: https://sh.itjust.works/post/582598

LemmyTools 0.1.2

New for 0.1.2:

  • Auto-Expand and Click&Drag to expand lemmy images!
  • Hide Lemmy Sidebars - More space for images on feed
  • Auto unblur NSFW images option
  • Option to enable old.Reddit (from https://github.com/soundjester/lemmy_monkey) - Thank you!
  • Hover to activate lemmy Toolbar
  • Significant UI changes
  • Reworked easy button for offsite

Fixes

  • Fix for '#' breaking easy subscribe button
  • Fix for script breaking other sites due to poor isLemmy implementation.
  • Fixed memory allocation issue with eventHandlers
  • Various UI bug fixes (not showing all communities, settings menu display, etc...)

Script Features:

  • Adds “Easy Subscribe” button to remote instance communities.
  • Adds a collapsible sidebar on the side of screen that shows a searchable list of your subscribed communities.
  • Adds link back to home instance and a community browser.
  • Adds an options menu to configure LemmyTools settings.

Feature for future releases:

  • When off site collect a list of communities and display in sidebar for easy subscription. (beginning implementation 0.1.2)
  • Create communities grouping function.
  • Sort sub list by recently visited
  • Create addon for firefox/chrome.

Installation and Configuration:

1 - Browser must have a Userscript addon (Tampermonkey, Greasemonkey, Etc...). Tested with Greasemonkey.

2 - Download either the .JS file or install from greasyfork.

3 - Set home lemmy instance via options page once script is loaded (and manually edit the homeInstance variable for the offsite home instance fix.

This script is all done by a complete amateur for fun. Enjoy and feel free to fork it!

Get it here: Github or GreasyFork

Please submit issues to the github for feature requests and problems: Github LemmyTools Issues

https://greasyfork.org/en/scripts/469169-lemmytoolsOpen linkView original on geddit.social
1