AutoCloseTheStrong

automatically closes torn profile pages if target is not a punchbag

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         AutoCloseTheStrong
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  automatically closes torn profile pages if target is not a punchbag
// @author       WizardRubic
// @match        *.torn.com/profiles.php*
// @grant        window.close

// ==/UserScript==

(function() {
    'use strict';
    var isWeak = function(title) {
        // returns true if the targets is any of the following titles
        return title=="Punchbag" || title=="Healer" || title=="Loser";
    };
    var profileElement = (document.getElementsByClassName("content-wrapper")[0]);
    var callback = function(mutationsList) {
        var rankTitleElement = document.getElementsByClassName("two-row");
        if(rankTitleElement==undefined) {
            return;
        }
        var rankTitleArray = rankTitleElement[0];
        if(rankTitleArray == undefined) {
            return;
        }
        var title = rankTitleArray.children[1].innerText;
        if(title!=undefined && !isWeak(title)) {
            window.close();
        }
        observer.disconnect();
    };
    var mutationConfig = { attributes: true, childList: true, subtree: true };
    var observer = new MutationObserver(callback);
    observer.observe(profileElement, mutationConfig);
})();