Lemmy UX Improvements

This script does two things: 1)Thumbnail links open in new tab. 2)If the user is a mod of some communities, the communities links appear below the profile link in the top-right menu.

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

You will need to install an extension such as Tampermonkey to install this script.

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Lemmy UX Improvements
// @namespace   lemmy-ux-improvements
// @match       https://lemmy.world/*
// @match       https://lemmy.ml/*
// @grant       none
// @version     1.0
// @license     MIT
// @author      https://lemmy.world/u/lawrence
// @description This script does two things: 1)Thumbnail links open in new tab. 2)If the user is a mod of some communities, the communities links appear below the profile link in the top-right menu.
// ==/UserScript==

// Source code: https://github.com/lawrence-lemmy/lemmy-ux-improvements

window.onload = function () {
  setTimeout(function () {

    // Thumbnail external links open in new tab
    const thumbnails = document.querySelectorAll('a.thumbnail, a.text-body');
    thumbnails.forEach(function (e) {
      e.setAttribute('target', '_blank');
    });

    // Communities that the user moderates appear inside the top-right menu
    if (
      window.isoData &&
      window.isoData.site_res &&
      window.isoData.site_res.my_user &&
      window.isoData.site_res.my_user.moderates
    ) {
      const moderates = window.isoData.site_res.my_user.moderates;
      moderates.forEach(function (e) {
        const profile_element = document.querySelector('ul.dropdown-menu > li');
        if (!profile_element) return;
        const new_item = profile_element.cloneNode(true);
        const link = new_item.querySelector('a');
        if (!link) return;
        link.setAttribute('title', e.community.name);
        link.setAttribute('href', '/c/' + e.community.name);
        link.innerText = e.community.name;
        profile_element.insertAdjacentElement('afterend', new_item);
      });
    }
  }, 1000); // Delay execution for 1 second after loading all assets
}