block-unwanted-pickpocketing-target

Hide unwanted targets from pickpocketing crime page to avoid unintended operation.

As of 11.10.2023. See ბოლო ვერსია.

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 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         block-unwanted-pickpocketing-target
// @namespace    nodelore.torn.easy-market
// @version      1.2
// @description  Hide unwanted targets from pickpocketing crime page to avoid unintended operation.
// @author       nodelore[2786679]
// @license      MIT
// @match        https://www.torn.com/loader.php?sid=crimes*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=torn.com
// @require      https://greatest.deepsurf.us/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=250853
// @grant        none
// ==/UserScript==

(function(){
    const $ = window.jQuery;
	const url = location.href;
	if(url.indexOf('pickpocketing') === -1){
		return;
	}

    // add targets you want to block here
	const block_targets = [
		"Gang member",
		"Thug",
        "Police officer",
        "Mobster",
	]

    // add activities you want to block here
	const avoid_activities = [
		"Jogging",
        "Cycling",
        "Walking", // you can remove this to enable showing walking target
	]

	let blockFlag = true;
	const block_elements = [];

	const updatePocketState = function(crimeTitle){
		// update state
		const total = $('div.crime-option');
		let totalCount = 0;
		let blockCount = 0;
		total.each(function(){
			const clock = $(this).find("div[class^='clock']").text();
			if(clock === "0s"){
				// console.log('Hide timeout item');
				$(this).hide();
				return;
			}
			else if($(this).css('display') === 'none'){
				blockCount += 1;
			}
			totalCount += 1;
		})
		crimeTitle.find('span.pocket-state').text(`(${blockCount} of ${totalCount} blocked)`);
	}

	const updateCrimeOption = function(option){
		const crimeTitle = $("div[class^='crimeHeading'] div:eq(0)");
		if(crimeTitle.find("span.pocket-state").length < 1){
			const pocket_state = $(`<span class="pocket-state t-red" title="Click to toggle"></span>`);
			pocket_state.click(function(){
				blockFlag = !blockFlag;
				// console.log(`toggle to ${blockFlag}`)
				if(blockFlag){
					for(let ele of block_elements){
						if(ele){
							ele.hide();
						}
					}
				}
				else{
					$('div.crime-option').each(function(){
						if($(this).css('display') === 'none'){
							$(this).show();
							block_elements.push($(this));
						}
					})
				}
				updatePocketState(crimeTitle);
			});
			crimeTitle.append(pocket_state);
		}

		updatePocketState(crimeTitle);

	   const titleProps = $(option).find("div[class^='titleAndProps'] div");
	   const activities = $(option).find("div[class^='activity']");
	   if(titleProps.length > 0 && activities.length > 0){
		const title = titleProps.contents().filter(function(){
			return this.nodeType === 3;
		}).text();
		const activity = activities.contents().filter(function(){
			return this.nodeType === 3;
		}).text();
		if(block_targets.indexOf(title) !== -1){
            $(option).hide();
            console.log(`Block ${title} who is ${activity}`);
        }
        else if(avoid_activities.indexOf(activity) !== -1){
            $(option).hide();
            console.log(`Block ${title} who is ${activity}`);
        }
	   }
	}

	waitForElems({
        sel: '.crime-option',
        onmatch: updateCrimeOption
    });
})();