Last active
December 9, 2019 15:19
-
-
Save cornzz/92565401f304a55ca828ce8814686d27 to your computer and use it in GitHub Desktop.
SACNR property filter script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var e = document.querySelector('html body.houses div#page div#content div.section div'); | |
var f = document.createElement('div'); | |
f.setAttribute('style', 'margin: 0px 15px 10px; padding: 5px; border: 0.5px solid black;'); | |
var a = document.createElement('div'); | |
a.setAttribute('id', 'ints'); | |
a.innerHTML = 'Ints: '; | |
for (var i = 0; i < 14; i++) { | |
if (i < 13) { | |
var b = document.createElement('label'); | |
var c = document.createElement('input'); | |
c.setAttribute('type', 'checkbox'); | |
c.value = i; | |
c.setAttribute('style', 'margin-right: 8px;') | |
b.innerHTML += i + ' '; | |
b.appendChild(c); | |
a.appendChild(b); | |
} | |
} | |
f.appendChild(a); | |
f.innerHTML += 'Last visit (days ago): '; | |
var g = document.createElement('input'); | |
g.setAttribute('id', 'lv'); | |
g.setAttribute('value', '0'); | |
f.appendChild(g); | |
f.innerHTML += '<br>Money: '; | |
var k = document.createElement('input'); | |
k.setAttribute('id', 'mon'); | |
k.setAttribute('value', '0'); | |
f.appendChild(k); | |
f.innerHTML += '<br>Owner: '; | |
var p = document.createElement('input'); | |
p.setAttribute('id', 'own'); | |
p.setAttribute('value', 'Anyone'); | |
f.appendChild(p); | |
f.innerHTML += '<br>Locations: '; | |
var k = document.createElement('input'); | |
k.setAttribute('id', 'locs'); | |
k.setAttribute('value', 'Everywhere'); | |
f.appendChild(k); | |
f.innerHTML += '<br>'; | |
var l = document.createElement('button'); | |
l.setAttribute('onclick', 'filter()'); | |
l.setAttribute('id', 'fb'); | |
l.setAttribute('style', 'width: 75px'); | |
l.innerHTML = 'Go'; | |
f.appendChild(l); | |
e.appendChild(f); | |
function filter() { | |
document.getElementById('fb').innerHTML = 'Loading...'; | |
setTimeout(function() { | |
var ints = []; // interior ids (see e.g. https://www.sacnr.com/img/int/10.png) | |
var cb = document.getElementById('ints').childNodes; | |
for (var i = 1; i < cb.length; i++) { | |
if (cb[i].childNodes[1].checked) { | |
ints.push(i - 1); | |
} | |
} | |
var lv = parseInt(document.getElementById('lv').value); // days since last visit | |
var mon = parseInt(document.getElementById('mon').value); // minimum amount of money stored in house | |
var locs = document.getElementById('locs').value.split(','); // If empty it will search everywhere | |
var owners = document.getElementById('own').value.split(','); | |
var m = document.querySelector('html body.houses div#page div#content div.section'); | |
var old = document.getElementById('hl'); | |
if (old) m.removeChild(old); | |
var o = document.createElement('div'); | |
o.setAttribute('id', 'hl'); | |
o.setAttribute('style', 'margin: 15px 30px;'); | |
var d = new Date; | |
d.setDate(d.getDate() - lv); | |
var e = new Date, | |
mapType = new SanMapType(0, 5, function(e, i, s) { | |
return -1 == i && -1 == s ? "/maps/tiles/basic.outer.png" : "/maps/tiles/basic." + e + "." + i + "." + s + ".png" | |
}), | |
satType = new SanMapType(0, 3, function(e, i, s) { | |
return -1 == i && -1 == s ? "/maps/tiles/sat.outer.png" : "/maps/tiles/sat." + e + "." + i + "." + s + ".png" | |
}), | |
map = SanMap.createMap(document.getElementById("map-canvas"), { | |
Map: mapType, | |
Satellite: satType | |
}, 2, null, !1, "Satellite"); | |
map.setZoom(1); | |
var iconOwned = "/maps/icons/unavailable.png", iconUnowned = "/maps/icons/house.png", mapInfo = [], mapHouses = []; | |
console.clear(); | |
for (var i = 0; i < houses.length; i++) { | |
var info = "", icon = ""; | |
if ((ints.includes(parseInt(houses[i].interior)) || 0 == ints.length) && houses[i].lastvisit + "000" < d.getTime() && houses[i].money >= mon && (locs.includes('Everywhere') || locs.includes(houses[i].zone)) && (owners.includes('Anyone') || owners.includes(houses[i].owner))) { | |
var lastvisit = new Date(parseInt(houses[i].lastvisit + "000")); | |
o.innerHTML += "House ID: <a href='/house/" + houses[i].house_id + "/' target='_blank'>" + houses[i].house_id + "</a>, Int: " + houses[i].interior + ", Owner: " + houses[i].owner + ", Money: $" + parseInt(houses[i].money, 10).formatMoney(0, ".", ",") + ", Location: " + houses[i].zone + ", Last visit: " + ((e - lastvisit) / 864e5 | 0) + " days ago<br>"; | |
icon = "SACNR Inc." != houses[i].owner ? iconOwned : iconUnowned; | |
info += "<div class='map-spacing'><b><a href='/house/" + houses[i].house_id + "/'>" + houses[i].name + "</a></b></div>" + "<div><b>Owner:</b> <a href='/u/" + houses[i].owner + "'>" + houses[i].owner + "</a></div>" + "<div><b>Location:</b> " + houses[i].zone + "</div>" + "<div><b>Money:</b> $" + parseInt(houses[i].money, 10).formatMoney(0, ".", ",") + "</div>" + "<div><b>Value:</b> $" + parseInt(houses[i].value, 10).formatMoney(0, ".", ",") + "</div>" + "<div><b>Original value:</b> $" + parseInt(houses[i].org_value, 10).formatMoney(0, ".", ",") + "</div>", parseInt(houses[i].rent, 10) > 0 && (info += "<div><b>Rent:</b> $" + parseInt(houses[i].rent, 10).formatMoney(0, ".", ",") + "</div>") + "<div class='map-spacing'><b>Interior:</b> " + houses[i].interior + "</div>" + "<div><img src='/img/int/" + houses[i].interior + ".png' alt='Interior " + houses[i].interior + "'></div>"; | |
mapInfo[i] = new google.maps.InfoWindow({ | |
content: info | |
}), mapHouses[i] = new google.maps.Marker({ | |
position: SanMap.getLatLngFromPos(houses[i].floatx, houses[i].floaty), | |
map: map, | |
icon: icon | |
}), google.maps.event.addListener(mapHouses[i], "click", function(e) { | |
var i = mapHouses.indexOf(this); | |
map.setCenter(this.position), mapInfo[i].open(map, this) | |
}) | |
} | |
} | |
m.appendChild(o); | |
document.getElementById('fb').innerHTML = 'Go'; | |
}, 5); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment