Lemmy Custom Navbar Links

Adds a custom navbar to Lemmy with links to custom pages.

当前为 2023-06-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Lemmy Custom Navbar Links
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.5
  5. // @author https://lemmy.world/u/0485919158191
  6. // @description Adds a custom navbar to Lemmy with links to custom pages.
  7. // @match *://*/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14. const isLemmy = document.head.querySelector("[name~=Description][content]").content === "Lemmy";
  15. if (!isLemmy) return;
  16.  
  17. // Create the navbar element
  18. const navbar = document.createElement('div');
  19. navbar.style.backgroundColor = '#EFF3F5';
  20. navbar.style.color = '#000000';
  21. navbar.style.padding = '2.5px';
  22. navbar.style.textAlign = 'center';
  23. navbar.style.position = "sticky";
  24. navbar.style.top = "0";
  25. navbar.style.width = "100%";
  26. navbar.style.zIndex = "100";
  27.  
  28. // Define the custom pages
  29. const customPages = [
  30. { title: 'My Posts', url: 'https://lemmy.world/u/0485919158191/view/Posts/sort/New/page/1', textColor: "#00C853" },
  31. { title: 'My Comments', url: 'https://lemmy.world/u/0485919158191/view/Comments/sort/New/page/1', textColor: "#00C853" },
  32. { title: '|', url: '#', textColor: "#000000" },
  33. { title: 'Sweden', url: 'https://lemmy.world/c/sweden', textColor: "#F1641E" },
  34. { title: 'DCSS', url: 'https://lemmy.world/c/dcss', textColor: "#F1641E" },
  35. { title: '|', url: '#', textColor: "#000000" },
  36. { title: 'Plugins', url: 'https://lemmy.world/c/plugins@sh.itjust.works', textColor: "#000000" },
  37. ];
  38.  
  39. // Create links for each custom page
  40. customPages.forEach((page) => {
  41. const link = document.createElement('a');
  42. link.textContent = page.title;
  43. link.href = page.url;
  44. link.style.fontWeight = ""
  45. link.style.color = page.textColor;
  46. link.style.marginRight = '10px';
  47. navbar.appendChild(link);
  48. });
  49.  
  50. // Insert the navbar at the top of the document body
  51. document.body.insertBefore(navbar, document.body.firstChild);
  52. })();