Enables attack button even if the target is in the hospital, changes icon to red, and works on Left click hold menu
当前为
// ==UserScript==
// @name Doobie's Hospital Button Bypass For Torn City
// @namespace http://tampermonkey.net/DoobiesHospitalBypass
// @version 1.6
// @description Enables attack button even if the target is in the hospital, changes icon to red, and works on Left click hold menu
// @match https://www.torn.com/profiles.php*
// @match https://www.torn.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function updateAttackButton(button) {
if (button && button.classList.contains('disabled')) {
button.classList.remove('disabled');
button.classList.add('active');
button.style.pointerEvents = 'auto';
button.style.opacity = '1';
button.setAttribute('aria-label', 'Attack (Bypass Hospital Restriction)');
let svgIcon = button.querySelector('svg');
if (svgIcon) {
svgIcon.style.filter = 'none';
svgIcon.style.fill = '#cf3b13';
}
button.addEventListener('click', function(e) {
e.preventDefault();
const attackUrl = button.getAttribute('href');
if (attackUrl) {
window.location.href = attackUrl;
}
});
}
}
function enableWarAttackButton() {
const outOfHospitalAttackButtons = document.querySelectorAll('.attack.left.attack___wBWp2 a.t-blue.h.c-pointer');
outOfHospitalAttackButtons.forEach(button => {
if (!button.classList.contains('disabled')) {
updateAttackButton(button);
}
});
const inHospitalAttackSpans = document.querySelectorAll('.status.left.hospital .t-gray-9');
inHospitalAttackSpans.forEach(span => {
const attackUrl = span.closest('.status.left.hospital').querySelector('a');
if (attackUrl) {
const newButton = document.createElement('a');
newButton.href = attackUrl.href;
newButton.classList.add('t-blue', 'h', 'c-pointer');
newButton.innerText = 'Attack';
span.replaceWith(newButton);
updateAttackButton(newButton);
}
});
}
function initializeObserver() {
const observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(function(node) {
if (node.nodeType === 1) {
enableWarAttackButton();
const profileAttackButton = document.querySelector('.profile-button-attack.disabled');
if (profileAttackButton) updateAttackButton(profileAttackButton);
const miniAttackButtons = document.querySelectorAll('[id^="mini-button"].profile-button-attack.disabled');
miniAttackButtons.forEach(button => updateAttackButton(button));
}
});
}
});
});
const targetNode = document.body;
observer.observe(targetNode, { childList: true, subtree: true });
}
window.onload = function() {
initializeObserver();
enableWarAttackButton();
const profileAttackButton = document.querySelector('.profile-button-attack.disabled');
if (profileAttackButton) updateAttackButton(profileAttackButton);
const miniAttackButtons = document.querySelectorAll('[id^="mini-button"].profile-button-attack.disabled');
miniAttackButtons.forEach(button => updateAttackButton(button));
};
})();
// Made with Love By Doobiesuckin