Guilty Record Lookup for scboy.cc

Complement the forum's existing guilty record feature

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Guilty Record Lookup for scboy.cc
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Complement the forum's existing guilty record feature
// @author       tianyi
// @include      https://www.scboy.cc/*
// ==/UserScript==

(function() {
  'use strict';

  const $guiltyRecord = $(`
  <div id="guilty-record" style="padding: 5px; background-color: white; border: 1px solid gray; width: 300px; z-index: 999; position: absolute;">
    <li class="media sc-banlog">
      <div class="media-body">
        <div id="confession" class="justify-content-between text-muted">
        </div>
      </div>
    </li>
  </div>
  `).appendTo('body').hide();

  const $confession = $guiltyRecord.find('#confession');
  let currentUID = '';
  let record = '';

  $('img.avatar-3').mouseenter((ev) => {
    const $victim = $(ev.target);
    const uid = $victim.attr('uid');

    if (!uid) {
      return;
    }

    if (uid === currentUID) {
      if (record) {
        showGuiltyRecord($victim);
      }
      return;
    } else {
      currentUID = uid;
    }

    $.xpost('mod-ban_yy.htm', {uid: uid}, (code, msg) => {
      if (code === 0) {
        const confession = $.parseJSON(msg);
        record = '';

        for (let i = 0; i < confession.length; i++) {
          let showInfo = '';
          if (confession[i]['state_fmt'] === '解封') {
            showInfo = '系统 解封';
          } else {
            showInfo = `${confession[i]['admin_username']} ${confession[i]['state_fmt']} 原因: ${confession[i]['remark']}`;
          }
          record += `<p>${confession[i]['opt_date_fmt']} 被 ${showInfo}</p>`;
        }
        if (!record) {
          return;
        }
        $confession.empty().append(`${record}`);

        showGuiltyRecord($victim);
      }
    });
  }).mouseleave(() => {
    $guiltyRecord.hide();
  });

  function showGuiltyRecord($victim) {
    const offset = $victim.offset();
    $guiltyRecord.css({
      top: `${offset.top}px`,
      left: `${offset.left + $victim.outerWidth() + 5}px`
    });
    $guiltyRecord.show();
  }
})();