Advertisement
Guest User

Mlmym community bar customisation userscript

a guest
Sep 6th, 2023
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.34 KB | Source Code | 0 0
  1. // ==UserScript==
  2. // @name         Add links to old lemmy world community bar
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  Allows you to customise the community bar at the top of the old lemmy desktop client.
  6. // @author       You
  7. // @match        https://old.lemmy.world/*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=lemmy.world
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12.  
  13. (function() {
  14.     'use strict';
  15.  
  16.     const communitiesToAdd = [
  17.         'gunners',
  18.         'football',
  19.         'ukcasual',
  20.         'unitedkingdom@feddit.uk',
  21.         'uk_politics@feddit.uk',
  22.         'android@lemdro.id',
  23.     ];
  24.  
  25.     const addCommunityToBar = (name) => {
  26.         const shortName = name.split('@')[0];
  27.  
  28.         const a = document.createElement('a');
  29.         const link = document.createTextNode(shortName);
  30.         const separator = document.createTextNode(" - ");
  31.  
  32.         a.appendChild(link);
  33.         a.href = `/c/${name}`;
  34.         a.title = `Go to /c/${shortName}`;
  35.  
  36.  
  37.         const communities = document.querySelector('.communities')
  38.         const firstLink = document.querySelector('.communities a:nth-child(5)')
  39.  
  40.         communities.insertBefore(separator, firstLink);
  41.         communities.insertBefore(a, separator);
  42.     }
  43.  
  44.     communitiesToAdd.reverse().map(addCommunityToBar)
  45. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement