Organised Crime

Easy initiation of Torn organised crimes.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name Organised Crime
// @namespace Organised Crime
// @version 0.1.2
// @description Easy initiation of Torn organised crimes.
// @author mrmuskrat [1863650]
// @include *.torn.com/factions.php?step=your*
// @require http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js
// @grant unsafeWindow
// ==/UserScript==

this.$ = this.jQuery = jQuery.noConflict(true);

var $CRIMES = $('#faction-crimes');

// Modified from code found in torn_stats.user.js
function watchFactionPage() {
    new MutationObserver( function( mutations ) {
		mutations.forEach( function( mutation ) {
            if ( mutation.addedNodes.length ) {
                var item = mutation.addedNodes.item(0);
                if ( $(item).hasClass('faction-crimes-wrap') ) {
                    crimes();
                }
			}
		});
	}).observe( $CRIMES[0], { childList: true } );
}

function crimes() {
	var items = $CRIMES.find('ul.crimes-list li.item-wrap');
	items.each( function( i, ele ) {
		var details = $(ele).find('div.details-wrap');
		if ( $(details).length ) {
			var ready = 1;
			var list = $(details).find('ul.details-list > li > ul.item > li.stat');
			if ( $(list).length ) {
				list.each( function( i, item ) {
					if ( $(item).hasClass('t-red') ) ready = 0;
				});
                var item = $(ele).find('ul.item');
                var status = $(item).children(1).children(1).get(0);
				if ( ready ) {
                    var wrap = $(details).find('div.initiate-crime-wrap');
                    var bwrap = $(wrap).length ? $(wrap).find('span.btn-wrap') : '';
                    var btn = $(bwrap).length ? $(bwrap).find('span.btn') : '';
					if ( $(status).hasClass('t-green') ) {
                        if ( $(bwrap).length ) {
                            var newBtn = $(bwrap).clone();
                            newBtn.click( function() { $(btn).trigger( 'click' ); } );
                            newBtn.css('cursor', 'pointer');
                            $(status).replaceWith( newBtn );
                        }
					}
                } else {
                    if ( $(status).text() == 'Ready' ) {
                        $(status).removeClass('t-green');
                        $(status).addClass('t-red');
                    }
                }
			}
		}
	});
}

watchFactionPage();