UD Underline Related Profile Links

Modernized take on Bradley Sattem's (a.k.a. Aichon) idea to underline all related profile links on mouse hover

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        UD Underline Related Profile Links
// @namespace   Avarice77
// @match       https://urbandead.com/map.cgi*
// @match       https://www.urbandead.com/map.cgi*
// @match       https://ispy.dxavier.net/*
// @run-at      document-end
// @inject-into auto
// @grant       none
// @license     MIT
// @version     1.2
// @author      Avarice77
// @description Modernized take on Bradley Sattem's (a.k.a. Aichon) idea to underline all related profile links on mouse hover
// ==/UserScript==

const debug = false;
const profileEl = document.querySelectorAll('.gt')[0].querySelector('a');
const playerId = profileEl.href.substring(profileEl.href.indexOf('id=') + 3);
if (debug) console.debug(`Your playerId:`, playerId);
const allProfiles = Array.from(document.querySelectorAll('a[href*="profile.cgi"]:not(.y)'));
allProfiles.forEach((profile, index) => {
  if (!profile.href.includes(playerId)) {
    const profileId = profile.href.substring(profile.href.indexOf('id=') + 3);
    if (debug) console.debug(`Processing profileId: ${profileId}`);
    profile.addEventListener('mouseover', (e) => {
      const relatedProfiles = [];
      allProfiles.forEach((otherProfile) => {
        const otherProfileId = otherProfile.href.substring(otherProfile.href.indexOf('id=') + 3);
        if (otherProfileId === profileId) {
          relatedProfiles.push(otherProfile);
          otherProfile.style.textDecoration = 'underline';
        } else {
          otherProfile.style.textDecoration = 'none';
        }
      });
      if (debug) console.debug(`Processing related profiles of profileId: ${profileId}`, relatedProfiles);
    });
    profile.addEventListener('mouseout', (e) => {
      allProfiles.forEach((profile) => {
        profile.style.textDecoration = 'none';
      });
    });
    if (debug) console.debug(`Added even listeners for profileId: ${profileId}`);
 }
});