[HF] Report counter

Report counter in the header.

当前为 2016-11-13 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         [HF] Report counter
// @namespace    https://hackforums.net
// @version      0.1
// @description  Report counter in the header.
// @author       iNeo19
// @match        https://hackforums.net/*
// @grant        none
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// ==/UserScript==

function getElementByXpath(page, path) {
  return page.evaluate(path, page, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}

var userID = "3099730";

(function() {
    'use strict';
    var profileURL = "member.php?action=profile&uid=" + userID;
    $.get(profileURL).then(function(profilePage) {
        var HTMLParser = new DOMParser();
        var page = HTMLParser.parseFromString(profilePage, "text/html");
        var reportCount = getElementByXpath(page, '//*[@id="content"]/div[2]/table[2]/tbody/tr/td[1]/table[1]/tbody/tr[8]/td[2]/text()');
        updateReports(reportCount);
    });
})();

function updateReports(reports) {
    var banner = getElementByXpath(document, '//*[@id="container"]/div[1]');
    var container = document.createElement("span");
    container.innerHTML = " (<font color='#00aaff'>Reported content: </font><font style='font-weight:normal'>"+reports.textContent+"</font>)";
    banner.appendChild(container);
}