-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhitman.html
474 lines (405 loc) · 16.5 KB
/
hitman.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
<!-- This is a wide open CSP declaration. To lock this down for production, see below. -->
<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *" />
<!-- Good default declaration:
* gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
* https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
* Disables use of eval() and inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
* Enable eval(): add 'unsafe-eval' to default-src
* Create your own at http://cspisawesome.com
-->
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: 'unsafe-inline' https://ssl.gstatic.com; style-src 'self' 'unsafe-inline'; media-src *" /> -->
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" type="text/css" href="css/bars.css" />
<link rel="stylesheet" href="./css/css/fontawesome-all.css" />
<link rel="manifest" href="./manifest.json">
<script src="js/jquery-3.3.1.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tinysort/3.2.5/tinysort.min.js" integrity="sha512-P3lisBxY1PusizpelihVrBeciBfWA9r7Ff/8j16b4K399OWJIrY1UdzdE7/BctqKv6Xujr8hp3IA2XiQX3Bsew==" crossorigin="anonymous"></script>
<!-- <link rel="stylesheet" type="text/css" href="progress/progress.css" /> -->
<script>
function applyBackgroundTheme(color) {
var css = `
/* --------- Dark Theme --------- */
html{background-color: #27292C;}
.body {background-color: #27292C;color: white;}
.main {background: #35383C;}
body {background-color: #27292C;}
h1,h2,h3,h4 {color: #ffffff;}
.btn a {background-color: #ffffff;border: solid 1px #27292C;color: #27292C;}
.btn-primary table td {background-color: #27292C;}
.btn-primary a {background-color: #27292C;border-color: #27292C;color: #ffffff; }
p,span,ul,ol {color:white;}
`,
head = document.head || document.getElementsByTagName('head')[0],
style = document.createElement('style');
head.appendChild(style);
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
}
else {
style.appendChild(document.createTextNode(css));
}
}
if(localStorage.dark == 'true'){
applyBackgroundTheme("black") // color for dark mode
}
</script>
<title>Eazy-T: Hitman</title>
</head>
<body id="main" onload="main()">
<script>
//Main function that is called ASAP
function main() {
if("apiKey" in localStorage){
//alertify.success('API key found');
}
else {
alertify.error('API key not found');
}
}//END
//Reloads the current window. Eazy
function reloadApp(){window.location.reload()}
function goHome() {
//alert('This feature is currently in development!');
window.location="index.html";
}
</script>
<table border="0" cellpadding="0" cellspacing="0" class="body">
<tr>
<td> </td>
<td class="container">
<div class="content">
<!-- START CENTERED WHITE CONTAINER -->
<table class="main">
<!-- START MAIN CONTENT AREA -->
<tr>
<td class="wrapper">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<a href="./index.html"><h1 id="playername">Eazy-T</h1></a>
<!-- Start Page -->
<style>
ul {
list-style: none;
padding-left: 0;
}
</style>
<h1>Targets:</h1>
<input type="text" name="skill" id="newSkill">
<input type="button" value="Add Target">
<ul id="skillList"></ul>
<script type="text/javascript">
function numFormatter(num) {
if(num > 999 && num < 1000000){
return (num/1000).toFixed(0) + 'K'; // convert to K for number from > 1000 < 1 million
}else if(num == 1000000){
return '1M'; // For when exactly 1 million
}else if(num > 1000000){
return (num/1000000).toFixed(0) + 'M'; // convert to M for number from > 1 million
}else if(num < 900){
return num; // if value < 1000, nothing to do
}
}
// Get all the element references you'll need just once:
var skillList = document.querySelector("#skillList");
var newSkill = document.querySelector("#newSkill");
var btnAddSkill = document.querySelector("input[type='button'");
// Do all of your event binding in JavaScript, not with inline HTML event attributes
btnAddSkill.addEventListener("click", addSkill);
var tempTargets = []; //used to temp store and manipulate targets.
//USE JSON.stringify() && JSON.parse()
if("targets" in localStorage){
tempTargets = localStorage.targets;
tempTargets = JSON.parse(tempTargets);
console.log("Done Parsing: " + tempTargets);
tempTargets.forEach(element => addExistingSkill(element));
} else {alertify.log("No targets found!")}
function addExistingSkill(target){
if(target !== ""){
// Don't build new HTML by concatenating strings. Create elements and configure them as objects
var li = document.createElement("li");
li.setAttribute("id", target);
li.setAttribute("data-position", "1");
li.textContent = target;
console.log("Found existing target: " + target); // The new value
// Only use hyperlinks for navigation, not to have something to click on. Any element can be clicked
var span = document.createElement("span");
span.classList.add("remove");
span.textContent = " - Delete";
span.addEventListener("click", removeSkill);
li.appendChild(span); // Add the span to the bullet
skillList.appendChild(li); // Add the bullet to the list
target = "";
}
}
function addSkill(){
if(newSkill.value !== ""){
// Don't build new HTML by concatenating strings. Create elements and configure them as objects
var li = document.createElement("li");
li.setAttribute("id", newSkill.value);
li.setAttribute("data-position", "1");
li.textContent = newSkill.value;
console.log("Adding new target: " + newSkill.value); // The new value
tempTargets.push(newSkill.value);
localStorage.setItem("targets", JSON.stringify(tempTargets));
// Only use hyperlinks for navigation, not to have something to click on. Any element can be clicked
var span = document.createElement("span");
span.classList.add("remove");
span.textContent = " - Delete";
span.addEventListener("click", removeSkill);
li.appendChild(span); // Add the span to the bullet
skillList.appendChild(li); // Add the bullet to the list
newSkill.value = "";
}
}
function removeSkill(){
//console.log(this.closest("li").nodeValue);
xxxx = getStringsFromChildren(this.closest("li")).toString();
console.log(xxxx);
tempTargets = tempTargets.filter(val => val !== xxxx);
localStorage.setItem("targets", JSON.stringify(tempTargets));
// Just remove the closest <li> ancestor to the <span> that got clicked
skillList.removeChild(this.closest("li"));
}
function removeById(id){
tempTargets = tempTargets.filter(val => val !== id);
localStorage.setItem("targets", JSON.stringify(tempTargets));
console.log("removed: " + id);
document.getElementById(id).innerHTML = "Deleted: " + id;
}
function updateList(){
var ul = document.getElementById("skillList");
var items = ul.getElementsByTagName("li");
//START promise
var bar = new Promise((resolve, reject) => {
for (var i = 0; i < items.length; ++i) {
try {
var meat = items[i].querySelector("#statusTime").textContent;
var parent = $(items[i]).closest("li");
parent.attr('data-position', meat);
//console.log(meat);
//console.log(parent);
}
catch(err) {
console.log("Error updating list: " + err);
}
if (i === items.length -1) resolve();
}
});
bar.then(() => {
updateListTwo();
});
}
function updateListTwo(){
tinysort('ul#skillList>li',{attr:'data-position'});
console.log("============ / ============");
//console.log("Updated list to sort by hospital time");
}
//https://stackoverflow.com/questions/6520192/how-to-get-the-text-node-of-an-element
/**
* Collects strings from child text nodes.
* Generic, cross platform solution. No string filtering or conditioning.
*
* @author Anthony Rutledge
* @version 7.0
* @param parentNode An instance of the Node interface, such as an Element. object.
* @return Array of strings, or null.
* @throws TypeError if the parentNode is not a Node object.
*/
function getStringsFromChildren(parentNode)
{
var strings = [],
nodeList,
length,
i = 0;
if (!parentNode instanceof Node) {
throw new TypeError("The parentNode parameter expects an instance of a Node.");
}
if (!parentNode.hasChildNodes()) {
return null; // We are done. Node may resemble <element></element>
}
nodeList = parentNode.childNodes;
length = nodeList.length;
do {
if ((nodeList[i].nodeType === Node.TEXT_NODE)) {
strings.push(nodeList[i].nodeValue);
}
i++;
} while (i < length);
if (strings.length > 0) {
return strings;
}
return null;
}
var getJSON = function(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'json';
xhr.onload = function() {
var status = xhr.status;
if (status === 200) {
callback(null, xhr.response);
} else {
callback(status, xhr.response);
}
};
xhr.send();
};
function updateTarget(){
//Randomly Select Target
//make sure still has a bounty
//Update information
//Send notification if needed
var randomItem = tempTargets[Math.floor(Math.random()*tempTargets.length)];
//console.log("Selected: " + randomItem);
getJSON('https://api.torn.com/user/' + randomItem + '?selections=basic,icons,profile&key=' + localStorage.apiKey,
function(err, data) {
if (err !== null) {
alertify.log('Cannot retrieve BASIC information: ' + err);
}
else {
$(document.getElementById(randomItem)).fadeOut();
//
//Profile Information
//
try{
delete data.status["details"];
}
catch(err) {
console.log("Error deleting problematic details field: " + err);
}
var playerName = data.name;
var playerStatus1 = data.status["description"];
const abroadHospitals = ['Emirati', 'African', 'Chinese', 'Swiss', 'Canadian', 'British'];
const found = abroadHospitals.find(v => playerStatus1.includes(v));
if(found != undefined){
playerStatus1 = "Hospital Abroad";
}
//remove 'In hospital for ' & 'Traveling to'
try {
playerStatus1 = playerStatus1.replace('In hospital for ','');
playerStatus1 = playerStatus1.replace('Traveling to ','➡️ ');
playerStatus1 = playerStatus1.replace('Returning to Torn from ','⬅️ ');
}
catch(err) {
Console.log("Error: Unable to remove 'In hospital for' string: " + err.message);
}
var playerActivity = data.last_action["status"].toLowerCase();
var statusTime = data.status["until"];
var statusColor = data.status["color"];
if(statusColor == "blue"){
statusColor = "#00BFFF";
}else if(statusColor == "red"){
statusColor = "#ff4000";
}
var bountyText = "0";
var bountyColor = "";
var imageSource = "";
if(playerActivity == "offline"){
imageSource = "<img style='margin-bottom: -0.25em;' src='./img/offline.png'></img>";
}
else if(playerActivity == "online"){
imageSource = "<img style='margin-bottom: -0.25em;' src='./img/online.png'></img>";
}
else{
//must be idle
imageSource = "<img style='margin-bottom: -0.25em;' src='./img/idle.png'></img>";
}
//Checking for bounty status
if(data.icons["icon13"]){
console.log("// Bounty on " + randomItem);
imageSource = imageSource.concat("<img style='margin-bottom: -0.25em;' src='./img/bounty.png'></img>");
bountyText = data.icons["icon13"]; //Bounty - On this person's head for $100,000
bountyText = bountyText.substring(36).replace(/\:.*/, '').trim(); //150,000
bountyText = Number(bountyText.replace(/[^0-9.-]+/g,"")); //150,000 => 150000
if(bountyText > 199000){
bountyColor = "green";
}
if(bountyText > 999000){
bountyColor = "yellow";
}
}else{console.log("|| NO Bounty on " + randomItem);}
var deleteButton = "<span onclick=\"removeById('" + randomItem + "'); return false;\"> - ❌</span>";
//console.log(deleteButton);
document.getElementById(randomItem).innerHTML = imageSource + " [<span style='color: " + bountyColor +"'>" + numFormatter(bountyText) + "</span>] <a style='text-decoration:none; color: inherit' href='https://www.torn.com/profiles.php?XID=" + randomItem + "'>" + playerName + "</a> - <span style='color:" + statusColor + "'>" + playerStatus1 + " <span id='statusTime'>" + statusTime + "</span></span>";
document.getElementById(randomItem).innerHTML += unescape(deleteButton);
$(document.getElementById(randomItem)).fadeIn();
}
}
); //END basic
setTimeout(updateTarget, 2000);
}
updateTarget();
const interval = setInterval(function() {
updateList();
}, 6000);
//clearInterval(interval);
</script>
<style>
#statusTime{
display: none;
}
</style>
<!-- END PAGE -->
</td>
</tr>
</table>
</td>
</tr>
<!-- END MAIN CONTENT AREA -->
</table>
<!-- START FOOTER -->
<div class="footer">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="content-block">
<table class="btn btn-primary">
<tbody>
<tr>
<td>
<center><table border="0" cellpadding="0" cellspacing="15">
<tbody>
<tr>
<td> <a onclick="goHome()"><i class="fas fa-home fa-2x"></i></a> </td>
</tr>
</tbody>
</table></center>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td class="content-block powered-by">
Created by: <a href="https://www.torn.com/profiles.php?XID=1947498">LunarControl</a>
</td>
</tr>
</table>
</div>
<!-- END FOOTER -->
<!-- END CENTERED WHITE CONTAINER -->
</div>
</td>
<td> </td>
</tr>
</table>
<script src="js/alertify.js"></script>
<script>
/* global PullToRefresh */
//PullToRefresh.init({
// mainElement: '#main',
// onRefresh: function() { reloadApp(); }
//});
</script>
</body>
</html>