Lemmy Plugins and Userscripts

2124 readers
1 users here now

A general repository for user scripts and plugins used to enhance the Lemmy browsing experience.

Post (or cross-post) your favorite Lemmy enhancements here!

General posting suggestions:

Thanks!

founded 1 year ago
MODERATORS
1
 
 

Table of Contents

  1. Introduction
  2. What is a UserScript?
  3. Installing a UserScript Manager
    • Installing Tampermonkey on Chrome
    • Installing Violentmonkey on Chrome
    • Installing Tampermonkey on Firefox
    • Installing Greasemonkey on Firefox
    • Installing Violentmonkey on Firefox
  4. Adding a UserScript
  5. Conclusion

Introduction

UserScripts are an incredible way to enhance and customize your browsing experience. They allow you to alter the functionality and layout of web pages, like Lemmy UI, by executing JavaScript codes on the client side. In this guide, we'll walk you through the process of installing UserScripts in your Chrome or Firefox browser.

What is a UserScript?

UserScripts are bits of code written in JavaScript that run in your web browser. They can modify the content, layout, and behavior of web pages. The true power of UserScripts lies in their ability to tailor your browsing experience to your needs.

Installing a UserScript Manager

To run UserScripts, you'll need to install a UserScript manager extension. Two popular ones are Tampermonkey and Greasemonkey.

Installing Tampermonkey on Chrome

  1. Open the Chrome web browser.
  2. Go to the Tampermonkey page on the Chrome Web Store.
  3. Click the "Add to Chrome" button.
  4. Confirm by clicking "Add extension" in the pop-up window.

Installing Violentmonkey on Chrome

  1. Open the Chrome web browser.
  2. Go to the Violentmonkey page on the Chrome Web Store.
  3. Click the "Add to Chrome" button.
  4. Confirm by clicking "Add extension" in the pop-up window.

Installing Tampermonkey on Firefox

  1. Open the Firefox web browser.
  2. Go to the Tampermonkey page on the Firefox Add-ons site.
  3. Click the "Add to Firefox" button.
  4. Confirm by clicking "Add" in the pop-up window.

Installing Greasemonkey on Firefox

  1. Open the Firefox web browser.
  2. Go to the Greasemonkey page on the Firefox Add-ons site.
  3. Click the "Add to Firefox" button.
  4. Confirm by clicking "Add" in the pop-up window.

Installing Violentmonkey on Firefox

  1. Open the Firefox web browser.
  2. Go to the Violentmonkey page on the Firefox Add-ons site.
  3. Click the "Add to Firefox" button.
  4. Confirm by clicking "Add" in the pop-up window.

Adding a UserScript

Now that you have a UserScript manager installed, you can add your own scripts. Here's how:

  1. Click on the Tampermonkey or Greasemonkey icon in your browser toolbar.
  2. Choose "Create a new script..." from the dropdown menu.
  3. You'll be taken to a new tab with a script template. Delete this template.
  4. Copy your UserScript and paste it into the empty field.
  5. Click "File" and then "Save" in the editor menu.

That's it! Your UserScript is now installed and will run on the sites specified in its metadata.

Conclusion

UserScripts offer an incredible way to customize your web browsing experience. Whether you're using Chrome or Firefox, Tampermonkey, Greasemonkey or Violentmonkey, you can create a browsing environment that's uniquely suited to your needs. Happy scripting!

Remember, while UserScripts are powerful tools, they should be used responsibly. Don't install scripts from sources you don't trust, as they can pose security risks. Always review the code of a UserScript before installing it to ensure it doesn't contain anything malicious.

2
 
 

Hi everyone, I'm excited to announce one more release before I take a short break. I have some other stuff starting up, so I won't be pushing out new features as fast, but I'll still be around to manage the project. (more at the end)

Links:


❓ What is Instance Assistant?

If you're new to Instance Assistant, it is a browser extension with a collection of tools and features to simplify your browsing experience on Lemmy and Kbin. It is available on Chrome, Firefox, and Edge; you can also install it from the releases page on GitHub.

For a full list of features, please see the GitHub homepage: https://github.com/cynber/lemmy-instance-assistant


⭐ What's new in v1.2.5?

  • Redirect posts to your home instance!: Post pages now have a redirect button that will find the same post on your home instance(1). You don't have to hunt it down yourself anymore.
  • Posts related to this webpage buttons in popup & sidebar
    • Make a post: You can now create a post from any webpage! Click the 'Make a Post' button in the extension popup or sidebar to generate a draft post with autofilled title, URL, and body contents. Afterwards, just select a community and hit post. (This currently works for both Lemmy & Kbin, but custom frontends are untested while they develop). Try it here: https://lemmy.ca/post/4478560
    • Open Posts: This will find any posts about the webpage/article/video that you are looking at. Use it to see if something has already been posted, or to find related discussions about it. When there are multiple posts, it will ask before opening them all. (see note on risks and why it doesn't count automatically)
  • Post an image: You can now right-click on an image, anywhere on the web, and hit "Post this image". It will open a new tab and autofill the title, image link, and add the page URL to the body as "Source: URL". Try it here: https://lemmy.ca/post/1282303
  • Reorganizing popup:
    • I fixed the issue where the popup would still display a button after removing all instances from the list.
    • The number of default instances in the popup was reduced to 4
  • Added settings:
    • You can now hide onboardining guides to make the interfaces less wordy
  • General styling changes, wording improvements, and bugfixes

(1) This is an important feature to me because this little annoyance was part of why I set out to create the extension in the first place. Thanks to some help from @zero_gravitas, I was able to use the Lemmy API to grab the post details, and then run a search for it on your home instance. While most posts should only bring one result, there is a chance that there are multiple posts by the same user, in the same community, with the same title. If this is an issue, I'll make this search more specific.


🗣️ My questions for you:

Improving 'post to Lemmy'

  • Right now the 'Post to Lemmy' button does a very basic search in the page meta tags for information. This works for most websites, but it is not perfect. What websites do you usually post from, and is the extension doing a good job of replicating how you format the post? Please share both good and bad examples, so we can fix what isn't working and keep what is.

Improving Post search

  • Having the extension automatically count the number of posts and display it in the icon would be pretty nice, since then you would know about any posts for the news article / blog / video that you are looking at. However, there are privacy implications with this since it needs to send the URL to your home instance to do the search.
  • I would like to add the option to whitelist specific websites, so the user can choose what browsing data they want to find posts for. Is this something you would list to use? What websites would you whitelist?

Anything else?

Please share any issues that you find. Lemmy and Kbin instances have a lot of variation in how things are structured, so there are bound to be some bugs that I haven't found yet. If you have any ideas for new features, please share them too! I'm always looking for new ideas to add to the project.


🔮 Cool ideas being discussed for the future

  • Account switcher & ability to save login info to extension
  • Reddit migrator tools
    • multireddit input should convert subscriptions to official Threadiverse replacements, or large related communities
    • embeds on Subreddit sidebars to search for similar community
    • button on post pages to cross-post to home instance
  • Prepping for Firefox Mobile app, now that they are opening mobile up to all extensions!
  • Keyboard hotkeys, possibly collaborating with someone that already implemented something similar

For the most up to date information, see the issues or the project road map


💛 Finally

Thank you for all the suggestions and feedback so far! I'm really happy to see that people are using the extension and finding it useful. I'm looking forward to seeing what we can do with it in the future.

Like I said above, I won't be as active over the next few months in terms of getting new features out. The extension is now in good shape, and it covers most of the important use cases. There's still lots of cool stuff we can do with it, so please contribute ideas and expertise! When I get a chance, I'll pop in and grab a few more issues.

Cheers :)

3
 
 

cross-posted from: https://lemmy.blahaj.zone/post/1312795

[Image description: A screenshot of the lemmy.blahaj.zone front page with a custom userstyle applied. The userstyle features a dark gray background with medium gray text and brightly-colored accents of purple, pink, orange, and cyan. The right sidebar cards are a light shade of gray with lighter gray text, pink buttons, and orange links]

A few weeks ago I decided to try my hand at bringing my favorite theme to Lemmy and this userscript was born. It's still in the early stages so there are some wrinkles to iron out, but I just pushed a big update with better contrast, style fixes, and streamlined code.

I've received several requests to turn it into a native Lemmy theme but have no idea how to do that. If anyone has any tips on theming, interest in collaborating, or a Lemmy instance where I could test a native theme, hit me up! You can find all the code here on Codeberg.

4
 
 

Crossgeposted von: 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);
})();

5
 
 

Just an FYI post for folks who are new or recently returning to Lemmy, I have updated the linked grease/tamper/violentmonkey script for Lemmvy v0.18.

These two scripts (a compact version and a large thumbnail version) substantially rearrange the default Lemmy format.

These are (finally) relatively stable for desktop/widescreen. Future versions will focus a little more on the mobile/handheld experience.

These are theme agnostic and should work with darkly and litely (and variants) themes.

Screenshot of "Compact" version

main page

-

comments page

As always, feedback is appreciated!

6
 
 

Description

Lemmy Universal Link Switcher, or LULs for short, scans all links on all websites, and if any link points to a Lemmy instance that is not your main/home instance, it rewrites the link so that it instead points to your main instance. Currently only works for community/user links.

Home Instance Setup

Simply visit the Lemmy instance you want to set as your home while the script is active. You will be asked if you want to set this instance to your home instance:
home

If you initially set your home instance wrong or just want to change it, no worries - simply go to your settings on your new home instance and press the button for it!
settings

Features

  • Rewrite all links of communities or users on all websites everywhere to your new instance! The rewritten links will have an icon next to it, and hovering/touching the icon will show you the original link, allowing you to go there if you want to.
    rewrite

  • If you are already on a page that has a corresponding page on your home instance, a link will automatically be added to the page header.
    redirect

Coming soon

  • Post & comment links. Those are a bit harder because the URL has to be requested from the instances.

Repository & Issues

7
 
 

Target Instance should be adjusted as needed.

Similar to this one: https://feddit.de/post/822722 which I didn't know about 20 minutes ago before being linked to this community.

Additional support for the Community Browser of feddit.de to make the process easier

8
 
 

I came across this one on userstyles.world and didn't see it referenced here. It's probably the most 'old reddit' looking of all of the one's I've seen so far.

9
10
 
 

userscript called "old.reddit" found here: https://github.com/soundjester/lemmy_monkey

  • (recently updated for Lemmy v0.18)

  • original thread link here

  • This is primarily for desktop clients. At the moment, formatting get a little crazy below 1280 px wide. There are ways to address this, but I have not at this time.

  • script will be updated as suggested

    • significant changes have been made to address alignment, spacing, and other format issues. v1.1 will be where I stop for a while.
  • there are two script versions: old.reddit and old.reddit.compact. The primary difference is that the "compact" version greatly reduces thumbnail size and padding space.

  • notice: current script unblurs NSFW

(linked thumbnail shows old.reddit.compact version of the script)

Screenshot of old.reddit script results:

11
 
 

Original post, containing the original code @soy@lemmy.world made: https://sh.itjust.works/post/33762

his original message:

For those that use Tampermonkey or GreaseMonkey, here’s a quick script I whipped up that creates a button that redirects communities from other instances to your local instance. If your instance isn’t lemmy.world, then change the localLemmy var at the top. Enjoy!

My small fix:

For personal use, I changed localLemmy to sh.itjust.works because that's my instance. I also embedded some styles and made it so it's top right instead of bottom left, and so that it's red and works better for me. Soy's original code didn't work for me so I had to make these small alterations to get it working.

// ==UserScript==
// @name         Lemmings Fix
// @version      1.0
// @description  Redirect to your local Lemmy instance
// @author       @lemmy.world/u/soy
// @match        https://*/c/*
// @icon         https://join-lemmy.org/static/assets/icons/favicon.svg
// ==/UserScript==

const localLemmy = "sh.itjust.works";
var isLemmy =
  document.head.querySelector("[name~=Description][content]").content ===
  "Lemmy";

if (isLemmy) {
  // Get URL info
  var splitUrl = location.href.split("/");
  var instanceUrl = splitUrl[2];
  var community = splitUrl[4];
  var localizedUrl =
    "https://" + localLemmy + "/c/" + community + "@" + instanceUrl;

  // Create redirect button if not on local
  if (instanceUrl !== localLemmy) {
    var zNode = document.createElement("div");
    zNode.innerHTML = "Open in local instance";
    zNode.setAttribute("id", "localizeContainer");
    // add styles to the button embedded
    zNode.setAttribute(
      "style",
      "cursor: pointer; padding: 16px; background-color: red; border-radius: 10%; border-width: 3px; border-style: solid; padding: 3px; z-index: 10;max-width:200px;position:fixed;top:0;right:0;"
    );
    zNode.addEventListener("click", onLocalize);
    document.body.appendChild(zNode);
  }
}

function onLocalize() {
  window.location.replace(localizedUrl);
}