Lemmy Custom Navbar Links

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Lemmy Custom Navbar Links
// @namespace    http://tampermonkey.net/
// @version      0.5
// @author       https://lemmy.world/u/0485919158191
// @description  Adds a custom navbar to Lemmy with links to custom pages.
// @match        *://*/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';
   const isLemmy = document.head.querySelector("[name~=Description][content]").content === "Lemmy";
   if (!isLemmy) return;

  // Create the navbar element
  const navbar = document.createElement('div');
  navbar.style.backgroundColor = '#EFF3F5';
  navbar.style.color = '#000000';
  navbar.style.padding = '2.5px';
  navbar.style.textAlign = 'center';
  navbar.style.position = "sticky";
  navbar.style.top = "0";
  navbar.style.width = "100%";
  navbar.style.zIndex = "100";

  // Define the custom pages
  const customPages = [
    { title: 'My Posts', url: 'https://lemmy.world/u/0485919158191/view/Posts/sort/New/page/1', textColor: "#00C853" },
    { title: 'My Comments', url: 'https://lemmy.world/u/0485919158191/view/Comments/sort/New/page/1', textColor: "#00C853" },
    { title: '|', url: '#', textColor: "#000000" },
    { title: 'Sweden', url: 'https://lemmy.world/c/sweden', textColor: "#F1641E" },
    { title: 'DCSS', url: 'https://lemmy.world/c/dcss', textColor: "#F1641E" },
    { title: '|', url: '#', textColor: "#000000" },
    { title: 'Plugins', url: 'https://lemmy.world/c/[email protected]', textColor: "#000000" },
  ];

  // Create links for each custom page
  customPages.forEach((page) => {
    const link = document.createElement('a');
    link.textContent = page.title;
    link.href = page.url;
    link.style.fontWeight = ""
    link.style.color = page.textColor;
    link.style.marginRight = '10px';
    navbar.appendChild(link);
  });

  // Insert the navbar at the top of the document body
  document.body.insertBefore(navbar, document.body.firstChild);
})();