Freeport7 visible sage

Brings back red sage span on FP7

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Freeport7 visible sage
// @namespace    http://freeport7.org/
// @version      0.0001
// @description  Brings back red sage span on FP7
// @author       紫
// @match        http://freeport7.org/*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
  "use strict";

  var process, addSage, postsWithSage;

  addSage = function(selected_post) {
    var sage_span, post_id, opening_id, post_info;

    sage_span = document.createElement('span');
    sage_span.className = 'sage';
    sage_span.style.cssText = `
      color: red;
      text-shadow: 0 0 2px red;
      font-weight: bold;
      margin-left: 15px;
      margin-right: 5px;
    `;

    post_id = selected_post.id.replace(/^i/, '');
    opening_id = selected_post.dataset.openingId;
    post_info = selected_post.getElementsByClassName('info')[0];
    if (selected_post.getElementsByClassName('sage').length === 0) {
      post_info.insertAdjacentElement('beforeend', sage_span);
      GM_xmlhttpRequest({
        method: 'GET',
        url: "/" + opening_id + "/" + post_id + ".json",
        onload: function(response) {
          var resp = JSON.parse(response.responseText);
          if (resp.post.sage === true) {
            sage_span.textContent = 'sage';
          }
        }
      });
    }
  };

  process = function() {
    var replies = document.getElementsByClassName('post reply');
    for (var i = 0, len = replies.length; i < len; i++) {
      addSage(replies[i]);
    }
  };

  document.onload = process();
  document.addEventListener('page:update', function() {
    setTimeout(process(), 500);
  });
})();