PIN clans

Add a pin icon next to each clan allowing you to easily find your friends clans without having to scroll just by pinning it so when they make a clan again with the same name, its already at the top for you!

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         PIN clans
// @namespace    --
// @version      2
// @license      MIT
// @description  Add a pin icon next to each clan allowing you to easily find your friends clans without having to scroll just by pinning it so when they make a clan again with the same name, its already at the top for you!
// @author       lore
// @match       *://sploop.io/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  function apic() {
    let title = document.getElementById('clan-title');
    if (!title || title.textContent.trim() !== 'Clans') return;

    let items = document.querySelectorAll('.menu-item');

    items.forEach(item => {
      // Skip items inside the specified element
      if (item.closest('#hat-menu')) return;

      if (item.querySelector('.pin')) return;

      let nameElement = item.querySelector('.header');
      if (nameElement) {
        let pin = document.createElement('i');
        pin.className = 'fas fa-map-pin pin';
        pin.style.fontSize = '24px';
        pin.style.color = 'gray';

        if (isPinned(nameElement.textContent.trim())) {
          pin.className = 'fas fa-thumbtack pin';
          item.classList.add('pinned');
          item.parentNode.prepend(item);
        }

        pin.addEventListener('click', function() {
          togglePin(item, pin);
        });

        nameElement.parentNode.insertBefore(pin, nameElement);
      }
    });
  }

  function togglePin(item, pin) {
    let isPinned = item.classList.contains('pinned');

    if (!isPinned) {
      item.classList.add('pinned');
      pin.className = 'fas fa-thumbtack pin';
      item.parentNode.prepend(item);
    } else {
      item.classList.remove('pinned');
      pin.className = 'fas fa-map-pin pin';
    }

    savePins();
  }

  function isPinned(name) {
    let pinned = JSON.parse(localStorage.getItem('pins')) || [];
    return pinned.includes(name);
  }

  function savePins() {
    let pinned = [];

    let items = document.querySelectorAll('.menu-item');

    items.forEach(item => {
      if (item.classList.contains('pinned')) {
        pinned.push(item.querySelector('.header').textContent.trim());
      }
    });

    localStorage.setItem('pins', JSON.stringify(pinned));
    console.log('Pinned:', pinned);
  }

  function observeChanges() {
    let observer = new MutationObserver(function(mutationsList, observer) {
      for (let mutation of mutationsList) {
        if (mutation.type === 'childList' || mutation.type === 'subtree') {
          apic();
        }
      }
    });

    observer.observe(document.body, { childList: true, subtree: true });
  }

  apic();
  observeChanges();

  function loadPins() {
    let pinned = JSON.parse(localStorage.getItem('pins')) || [];

    let items = document.querySelectorAll('.menu-item');
    items.forEach(item => {
      let name = item.querySelector('.header').textContent.trim();
      if (pinned.includes(name)) {
        item.classList.add('pinned');
        let pin = item.querySelector('.pin');
        if (pin) {
          pin.className = 'fas fa-thumbtack pin';
        }
        item.parentNode.prepend(item);
      }
    });
  }

  loadPins();

})();