Torn Extensions - Faction Activity

Shows the activity of employees.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Torn Extensions - Faction Activity
// @namespace    TornExtensions
// @version      1.2
// @description  Shows the activity of employees.
// @author       Mathias [XID 1918010]
// @match        https://www.torn.com/factions.php*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
	let APIKey = "API KEY HERE";
	let API = `https://api.torn.com/faction/?key=${APIKey}`;
	let targetNode = document.querySelector("#faction-info");
	let config = { childList: true };

	if($(".faction-tabs-title").text() == "INFO") {
		run();
	}
	
	let callback = function(mutationsList, observer) {
		run();
	}
	
	function run() {
		GM_xmlhttpRequest({
			method: "GET",
			url: API,
			onreadystatechange: (res) => {
				if(res.readyState > 3 && res.status === 200) {
					let resp = JSON.parse(res.response);
					$.each(resp.members, (id, data) => {
						let div = $(`a[href="/profiles.php?XID=${id}"].user.name`).parent().parent().parent(), days = data.last_action.relative.split(" ");
						if(days[1].includes("day"))
							if(parseInt(days[0]) == 1)
								$(div).css("background-color", "#e6c26a");
							else if(parseInt(days[0]) >= 2)
								$(div).css("background-color", "#e66a6a");
					});
				}
			},
			onerror: (err) => {
				console.log(err);
			}
		});
	}
	
	let observer = new MutationObserver(callback);
	observer.observe(targetNode, config);
})();