PixelPlanet Old Chat UI

Restores compact chat: removes avatars, hides images, image toggle

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         PixelPlanet Old Chat UI
// @namespace    https://pixelplanet.fun/
// @version      1.0
// @description  Restores compact chat: removes avatars, hides images, image toggle
// @author       Able
// @match        https://pixelplanet.fun/*
// @match        https://www.pixelplanet.fun/
// @grant        GM_addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @license MIT
// @run-at       document-start
// ==/UserScript==

(function () {
  'use strict';

  let imagesHidden = GM_getValue('ppoc_images_hidden', true);

  GM_addStyle(`
    div.avatar {
      display: none !important;
    }

    li.chatmsg {
      display: block !important;
      padding: 1px 4px !important;
      min-height: unset !important;
    }

    div.msgcontent {
      display: block !important;
      width: 100% !important;
      padding: 0 !important;
      margin: 0 !important;
    }

    .ppoc-images-off div.attcontainer,
    .ppoc-images-off img.attachment {
      display: none !important;
    }
    .ppoc-images-on div.attcontainer { display: block !important; }
    .ppoc-images-on img.attachment   { display: block !important; }

    #ppoc-toggle {
      position: fixed !important;
      top: 6px !important;
      right: 48px !important;
      z-index: 99999 !important;
      background: #2a2a2a !important;
      color: #fff !important;
      border: 1px solid #555 !important;
      border-radius: 4px !important;
      padding: 3px 7px !important;
      font-size: 11px !important;
      cursor: pointer !important;
      user-select: none !important;
      opacity: 0.85 !important;
      line-height: 1.4 !important;
    }
    #ppoc-toggle:hover { opacity: 1 !important; background: #444 !important; }
    #ppoc-toggle.off   { border-color: #f66 !important; color: #f99 !important; }
    #ppoc-toggle.on    { border-color: #6a6 !important; color: #9d9 !important; }
  `);

  function removeAvatars(root) {
    (root.querySelectorAll ? root : document)
      .querySelectorAll('div.avatar')
      .forEach(el => el.remove());
  }

  function applyImageState() {
    document.body.classList.toggle('ppoc-images-off', imagesHidden);
    document.body.classList.toggle('ppoc-images-on',  !imagesHidden);
    const btn = document.getElementById('ppoc-toggle');
    if (btn) {
      btn.textContent = imagesHidden ? '🖼 Images: OFF' : '🖼 Images: ON';
      btn.className   = imagesHidden ? 'off' : 'on';
    }
  }

  function injectButton() {
    if (document.getElementById('ppoc-toggle')) return;
    const btn = document.createElement('button');
    btn.id = 'ppoc-toggle';
    btn.addEventListener('click', () => {
      imagesHidden = !imagesHidden;
      GM_setValue('ppoc_images_hidden', imagesHidden);
      applyImageState();
    });
    document.body.appendChild(btn);
    applyImageState();
  }

  function startObserver() {
    new MutationObserver((mutations) => {
      for (const m of mutations) {
        for (const node of m.addedNodes) {
          if (node.nodeType !== 1) continue;
          if (node.classList && node.classList.contains('avatar')) {
            node.remove();
            continue;
          }
          removeAvatars(node);
        }
      }
    }).observe(document.body, { childList: true, subtree: true });
  }

  function init() {
    removeAvatars(document);
    applyImageState();
    injectButton();
    startObserver();
    [300, 800, 1500, 3000].forEach(t => setTimeout(() => {
      removeAvatars(document);
      injectButton();
    }, t));
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', init);
  } else {
    init();
  }

})();