您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
description
当前为
// ==UserScript== // @name Faction Last Active // @namespace namespace // @version 0.1 // @description description // @author tos // @match *.torn.com/factions.php* // @grant GM_addStyle // ==/UserScript== const apiKey = 'APIKEY' GM_addStyle(` .last_action_icon { cursor: pointer; vertical-align: middle; display: inline-block; background-image: url(/images/v2/sidebar_icons_desktop_2017.png); background-repeat: no-repeat; background-position-y: -785px; width: 34px; height: 30px; } `) const get_api = async (key = apiKey) => { const response = await fetch(`https://api.torn.com/faction/$?selections=basic&key=${key}`) return await response.json() } const toggleLastAction = (iconsTitle, memberUL) => { if (iconsTitle.innerText === 'Icons') { iconsTitle.childNodes[0].nodeValue = 'Last Action' get_api().then((res) => { for (const li of memberUL.children) { const lastActionDIV = li.querySelector('.last-action') const memberID = lastActionDIV.getAttribute('data-member-ID') li.querySelector('.member-icons #iconTray').classList.toggle('hide') lastActionDIV.innerText = res.members[memberID].last_action lastActionDIV.classList.toggle('hide') } }) } else { iconsTitle.childNodes[0].nodeValue = 'Icons' for (const li of memberUL.children) { li.querySelector('.member-icons #iconTray').classList.toggle('hide') li.querySelector('.last-action').classList.toggle('hide') } } } const observer = new MutationObserver((mutations) => { for (const mutation of mutations) { for (const node of mutation.addedNodes) { if (node.className && node.className === 'faction-info-wrap another-faction') { const iconsTitle = node.querySelector('.title .member-icons') const memberUL = node.querySelector('.member-list') iconsTitle.insertAdjacentHTML('beforeend', `<i class="last_action_icon right"></i>`) node.querySelector('.last_action_icon').addEventListener('click', () => { toggleLastAction(iconsTitle, memberUL) }) for (const li of memberUL.children) { const memberID = li.querySelector('.kick-yes').getAttribute('data-id') li.querySelector('.member-icons #iconTray').insertAdjacentHTML('afterend', `<div class="last-action hide" data-member-id="${memberID}"></div>`) } } } } }) const wrapper = document.querySelector('#factions') observer.observe(wrapper, { subtree: true, childList: true })