NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript==
// @name Jail lols
// @version 0.11
// @author Ahab [1735214]
// @match https://www.torn.com/jailview.php
// @updateURL https://openuserjs.org/meta/Ahab/Jail_lols.meta.js
// @downloadURL https://openuserjs.org/install/Ahab/Jail_lols.user.js
// @license MIT
// ==/UserScript==
const jailStyles = `
#bustNerve{
appearance: none;
border-radius: 8px;
height: 4px;
width: 20%;
--chat-range-range-color: var(--chat-theme-dark, #000) var(--chat-theme-light, #e5e5e5);
--chat-range-progress-color-default: var(--chat-theme-dark, #00698c) var(--chat-theme-light, rgba(0, 102, 153, .4));
--chat-range-progress-color-hover: var(--chat-theme-dark, #6edbff) var(--chat-theme-light, rgba(0, 102, 153, .8));
}
#bustNerve::-webkit-slider-thumb{
-webkit-appearance: none;
background-color: var(--chat-color-surface);
border-color: #6edbff #8cb5c9;
border-color: var(--chat-theme-dark,#6edbff) var(--chat-theme-light,#8cb5c9);
border-radius: 50%;
border-style: solid;
border-width: 2px;
cursor: pointer;
height: 14px;
width: 14px
}
#bustNerve:hover{
background: linear-gradient(to right, var(--chat-range-progress-color-hover) 100.00%, var(--chat-range-range-color) 100.00%, var(--chat-range-range-color) 100%);
}
#hardnessScore{
-webkit-appearance: none;
appearance: none;
background: var(--input-background-color);
color: var(--input-color);
border-radius: 5px;
border: 1px solid;
border-color: var(--input-border-color);
text-align: center;
}
#hardnessScore::-webkit-outer-spin-button,
#hardnessScore::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
#hardnessScore:hover {
border-color: var(--input-hover-border-color);
}
#bustBtn{
margin-left: 20px;
border-radius: 5px;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
vertical-align: middle;
background: var(--chat-theme-dark, linear-gradient(180deg, #555 0, #333 100%)) var(--chat-theme-light, linear-gradient(180deg, #fff 0, #ddd 100%));
border: var(--chat-theme-dark, 0) var(--chat-theme-light, 1px solid #ccc);
box-shadow: var(--chat-theme-dark, 0 0 2px #000) var(--chat-theme-light, 0);
color: var(--chat-theme-dark, #ddd) var(--chat-theme-light, #666) !important;
width: 50px;
height: 25px;
}
#bustBtn:hover{
background: var(--chat-theme-dark, linear-gradient(180deg, #666 0, #444 100%)) var(--chat-theme-light, #fff);
}
`
var prisoners = {}
var bustNerve = 5
var cxhr = {}
var ln = 0
if(localStorage.bustNerve != null){
bustNerve = localStorage.bustNerve
}
$("<style>").text(jailStyles).appendTo("head");
$('div.users-list-title span.title')[0].insertAdjacentHTML('beforeend', '<span id=hardCount></span>')
$('h4[id*="skip-to-content"]').append('<span style="font-size: 12px; font-weight: normal; display: inline-flex; align-items: center;"><label for="hardnessScore"> Hardness score: </label><input id=hardnessScore type="number" value="'+localStorage.hardnessValue+'" style="width: 50px; padding-left: 2px; margin-left: 2px;"/><label for="bustNerve" style="margin-left: 15px;"> Nerve per Bust: </label><input id=bustNerve type="range" min="2" max="5" step="1" value="'+bustNerve+'" style="margin-left: 2px; width: 50px;"/><label for="bustNerve" name="bustNerve">'+bustNerve+'</label></span><button id="bustBtn" type="button">Bust</button>')
$('input[id*="bustNerve"]').each( function(){
var n = (($(this)[0].value - 2) / (5 - 2) * 100).toFixed(2);
var o = "var(--chat-range-range-color)", c = "var(--chat-range-progress-color-default)";
$(this)[0].style.background = "linear-gradient(to right, ".concat(c, " ").concat(n, "%, ").concat(o, " ").concat(n, "%, ").concat(o, " 100%)")
})
$('input[id="hardnessScore"]').on('input change', function(e) {
if($(this).val() != ""){
localStorage.hardnessValue = $(this).val()
$('div[class*="msg right-round"]').text("Hardness score set")
}else{
localStorage.hardnessValue = 0
$('div[class*="msg right-round"]').text("Set a maximum hardness score for attempted busts")
}
if(e.type == "change"){
$.post("https://www.torn.com/jailview.php?"+new Date().getTime() + '=' + Math.random()+"&rfcv="+getRFC(),{action: "jail", start: (parseInt($('a.page-number.active').attr('page'), 10) - 1) * 50,},);
}
})
$('input[id="bustNerve"]').on('input change mouseover mouseleave', function(e){
var t = false
if(e.type == 'mouseover'){
ln = this.value
}
if(e.type != "mouseleave"){
t = true
}else{
t = false
if(this.value !== ln){
$.post("https://www.torn.com/jailview.php?"+new Date().getTime() + '=' + Math.random()+"&rfcv="+getRFC(),{action: "jail", start: (parseInt($('a.page-number.active').attr('page'), 10) - 1) * 50,},);
}
}
var n = (($(this)[0].value - 2) / (5 - 2) * 100).toFixed(2);
var o = "var(--chat-range-range-color)", c = "var(--chat-range-progress-color-".concat(t ? "hover" : "default", ")");
$('label[name="bustNerve"]')[0].textContent = event.target.value;
localStorage.bustNerve = $(this).val()
$('input[id="bustNerve"]').each( function(){
if($(this)[0] == e.currentTarget){
$(this)[0].style.background = "linear-gradient(to right, ".concat(c, " ").concat(n, "%, ").concat(o, " ").concat(n, "%, ").concat(o, " 100%)")
}
else{
$(this)[0].style.background = "linear-gradient(to right, ".concat("var(--chat-range-progress-color-default)", " ").concat(n, "%, ").concat(o, " ").concat(n, "%, ").concat(o, " 100%)")
}
})
display(cxhr)
})
$(document).ajaxSuccess(function(event, xhr, settings) {
if (settings.url.includes("jailview.php") && settings.type.toUpperCase() === "POST") {
prisoners = {}
$.each(JSON.parse(xhr.responseText).data.players, function () {
prisoners[this.user_id] = Math.floor((+this.level * (((+this.time.match(/\d+(?=h)/) || 0) + (+this.time.match(/\d+(?=m)/) || 0) / 60)+3)))
if ($('a.user.name[href*="=' + this.user_id + '"]').length === 0) {
const playerHTML = `
<li class="">
${this.online_offline}
<span class="user-wrap user-faction">${this.print_tag}</span>
<span class="user-wrap user-name">${this.print_name}</span>
<span class="info-wrap">
<span class="time"><span class="title bold">TIME</span> ${this.time}</span>
<span class="level"><span class="title bold">LEVEL</span> ${this.level}</span>
<span class="reason">${this.jailreason}</span>
</span>
<a class="bye t-gray-3" href="jailview.php?XID=${this.user_id}&action=rescue&step=buy">
<span class="bye-icon"></span>
<span class="title bold wai">BUY</span>
</a>
<a class="bust t-gray-3" href="jailview.php?XID=${this.user_id}&action=rescue&step=breakout">
<span class="bust-icon"></span>
<span class="title bold wai">BUST</span>
</a>
<div class="confirm-bye"></div>
<div class="confirm-bust"></div>
<div class="bottom-white"></div>
</li>
`;
$('.user-info-list-wrap').append(playerHTML);
}
});
var playerIds = JSON.parse(xhr.responseText).data.players.map(p => p.user_id);
$('a.user.name').filter((_, el) => !playerIds.includes(parseInt($(el).attr('href').split('=')[1], 10))).parent().parent().remove()
$('span[class*="total"]').text(JSON.parse(xhr.responseText).total)
if(!prisoners && !JSON.parse(xhr.responseText).data.pagination && $('a.page-number.active')){
$('div[class*="msg right-round"]').text("Current active page doesn't exist, return to previous page")
}else{
cxhr = xhr
display(cxhr)
}
}
});
function bust(){
if(localStorage.getItem("hardnessValue") != null){
if(parseInt($('a[class*="nerve_"]').find('[class*="bar-value"]')[0].childNodes[0].data) >= parseInt(localStorage.bustNerve)){
if(!prisoners && $('a.page-number.active') || Object.entries(prisoners).length === 0 && $('a.page-number.active')){
$('div[class*="msg right-round"]').text("Current active page doesn't exist, return to previous page")
}else{
if(Object.entries(prisoners).reduce((a, b) => a[1] < b[1] ? a : b)[1] <= localStorage.hardnessValue){
$.get("https://www.torn.com/jailview.php?XID="+Object.entries(prisoners).reduce((a, b) => a[1] < b[1] ? a : b)[0]+"&action=rescue&step=breakout1&rfcv="+getRFC(), function(response) {
$('div[class*="msg right-round"]').html(JSON.parse(response).msg)
if(JSON.parse(response).color == "green"){
$('a[href="/profiles.php?XID='+Object.entries(prisoners).reduce((a, b) => a[1] < b[1] ? a : b)[0]+'"]').parent().parent().remove()
delete prisoners[Object.entries(prisoners).reduce((a, b) => a[1] < b[1] ? a : b)[0]]
$('span#hardCount')[0].innerText = " | "+Object.entries(prisoners).filter(([key, value]) => value <= localStorage.hardnessValue).length+" people to bust"
}else if(JSON.parse(response).msg.includes("no longer in jail")){
$('a[href="/profiles.php?XID='+Object.entries(prisoners).reduce((a, b) => a[1] < b[1] ? a : b)[0]+'"]').parent().parent().remove()
delete prisoners[Object.entries(prisoners).reduce((a, b) => a[1] < b[1] ? a : b)[0]]
$('span#hardCount')[0].innerText = " | "+Object.entries(prisoners).filter(([key, value]) => value <= localStorage.hardnessValue).length+" people to bust"
}else{
$('div[class*="msg right-round"]').html(JSON.parse(response).msg)
}
});
}else{
$('div[class*="msg right-round"]').text("Refreshing...");
$.post("https://www.torn.com/jailview.php?"+new Date().getTime() + '=' + Math.random()+"&rfcv="+getRFC(),{action: "jail", start: (parseInt($('a.page-number.active').attr('page'), 10) - 1) * 50,},);
}
}
}else{
$('div[class*="msg right-round"]').text("Not enough nerve to bust")
}
}else{
$('div[class*="msg right-round"]').text("Set a maximum hardness score for attempted busts")
}
}
function display(xhr){
$('span#hardCount')[0].innerText = " | "+Object.entries(prisoners).filter(([key, value]) => value < localStorage.hardnessValue).length+" people to bust"
if(localStorage.getItem("hardnessValue") === null){
$('div[class*="msg right-round"]').text("Set a maximum hardness score for attempted busts")
}else if(parseInt($('a[class*="nerve_"]').find('[class*="bar-value"]').text()) < parseInt(localStorage.bustNerve)){
$('div[class*="msg right-round"]').text("Not enough nerve to bust")
}else if(Object.entries(prisoners).filter(([key, value]) => value <= localStorage.hardnessValue).length > 0){
$('div[class*="msg right-round"]').text("Prisoners need freeing")
}else if((Number.isNaN(parseInt($('a.page-number.active').attr('page'))) ? 1 : parseInt($('a.page-number.active').attr('page'))) < parseInt($(JSON.parse(xhr.responseText).data.pagination).find('a.page-number[page!="1"]').last().attr('page')) && $('div[class*="msg right-round"]').text().includes("Refreshing...")){
$('div[class*="msg right-round"]').text("Page "+$(JSON.parse(xhr.responseText).data.pagination).find('a.page-number[page!="1"]').last().attr('page')+" exists! Refresh and switch")
}else{
$('div[class*="msg right-round"]').text("Nobody to bust")
}
}
$("#bustBtn").on("keydown", function(e){
if (e.which === 13) {
e.preventDefault();
e.stopPropagation();
return false;
}
});
$("#bustBtn").on('click', function(e){
bust()
});
$(document).on('keyup', function(e){
if(e.which == 13 && e.target.id !== "hardnessScore" && !$(e.target).is('[class*="textarea_"]')){
bust()
}
})