-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtc.torn.js
165 lines (148 loc) · 5.3 KB
/
tc.torn.js
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
/*
tc.torn.js - generic object reference for Torn City
builds an object from current page data (that has side-panel),
using jQuery to find those objects, attaches "change" watchers
see: https://github.com/paulwratt/torn-city-pwtools/master/tc.torn.js.md
*/
var tc = { ver: 1, debug: false, long: false, scripts: false, timers: false, t: 0,
p: { n: '', id: '0', d: 0, l: { l: 0, u: false }, p: 0, m: 0, },
e: { c:0, m:0, t: '0:00' }, n: { c:0, m:0, t: '0:00' }, h: { c:0, m:0, t: '0:00' }, l: { c:0, m:0, t: '0:00' },
f: { id: '0', c: { c: 0, m : 0, t: '0:00' } },
s: {}
};
var tornCity = null;
function tc_LongForm() {
if ( tc.long == false || tornCity != null) return;
tornCity = { time: 0,
player: { name: '',
id: 0,
money: 0,
points: 0,
merits: 0,
level: { lvl: 0, up: false }
},
energy: { cur: 0, max: 0, time: '0:00' },
nerve: { cur: 0, max: 0, time: '0:00' },
happy: { cur: 0, max: 0, time: '0:00' },
life: { cur: 0, max: 0, time: '0:00' },
faction: { id: 0,
chain: { cur: 0, max: 0, time: '0:00' }
},
scripts: {}
};
}
// find chain timer object
var energyValue = $('#barEnergy').find("p[class^='bar-value']").get(0);
var energyTimer = $('#barEnergy').find("p[class^='bar-descr']").get(0);
var nerveValue = $('#barNerve').find("p[class^='bar-value']").get(0);
var nerveTimer = $('#barNerve').find("p[class^='bar-descr']").get(0);
var happyValue = $('#barHappy').find("p[class^='bar-value']").get(0);
var happyTimer = $('#barHappy').find("p[class^='bar-descr']").get(0);
var lifeValue = $('#barLife').find("p[class^='bar-value']").get(0);
var lifeTimer = $('#barLife').find("p[class^='bar-descr']").get(0);
var chainValue = $('#barChain').find("p[class^='bar-value']").get(0);
var chainTimer = $('#barChain').find("p[class^='bar-timeleft']").get(0);
// create an observer instance
var tc_observer = new MutationObserver(function(mutations) {
m.v = mutation.target.innerText;
m.t = mutation.type;
mutations.forEach(function(mutation) {
if (m.t == 'nerveValue') {
if (m.v.indexOf('/') == -1) {
v = m.v.split('/');
tc.n.c = v[0];
tc.n.m = v[1];
}else{
tc.n.c = m.v;
}
if (tc.debug) console.log("nerve values were updated");
}
if (m.t == 'chainValue') {
if (m.v.indexOf('/') == -1) {
v = m.v.split('/');
tc.f.c.c = v[0];
tc.f.c.m = v[1];
}else{
tc.f.c.c = m.v;
}
if (tc.debug) console.log("chain values were updated");
}
if (m.t == 'nerveTimer') {
tc.f.c.t = m.v;
if (tc.debug) console.log("nerve timer was updated");
}
if (m.t == 'chainTimer') {
tc.f.c.t = m.v;
if (tc.debug) console.log("chain timer was updated");
}
});
});
// Configuration of the observer.
// For possible options see:
// https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
// cur/max
var eValue = { energyValue:true };
var nValue = { nerveValue:true };
var hValue = { happyValue:true };
var lValue = { lifeValue:true };
var cValue = { chainValue:true };
// 0:00 or FULL
var eTimer = { energyTimer:true };
var nTimer = { nerveTimer:true };
var hTimer = { happyTimer:true };
var lTimer = { lifeTimer:true };
var cTimer = { chainTimer:true };
// pass in the target node, as well as the observer options
function tc_watchValues(){
// values
tc_observer.observe( energyValue, eValue );
tc_observer.observe( nerveValue, nValue );
tc_observer.observe( happyValue, hValue );
tc_observer.observe( lifeValue, lValue );
tc_observer.observe( chainValue, cValue );
}
function tc_attachTimers(){
// timers
tc_observer.observe( energyTimer, eTimer );
tc_observer.observe( nerveTimer, nTimer );
tc_observer.observe( happyTimer, hTimer );
tc_observer.observe( lifeTimer, lTimer );
tc_observer.observe( chainTimer, cTimer );
}
function tc_detectScripts(){
//
}
function tc_Populate(){
tc.t = 0;
if ( tc.scripts == true ) tc_detectScripts();
if ( tc.long == true ) {
if ( tornCity == null ) tc_LongForm();
tornCity.time = tc.t;
tornCity.player.name = tc.p.n;
tornCity.player.id = tc.p.id;
tornCity.player.money = tc.p.d;
tornCity.player.points = tc.p.p;
tornCity.player.merits = tc.p.m;
tornCity.player.level.lvl = tc.p.l.l;
tornCity.player.level.up = tc.p.l.u;
tornCity.energy.cur = tc.e.c;
tornCity.energy.max = tc.e.m;
tornCity.energy.timer = tc.e.t;
tornCity.nerve.cur = tc.n.c;
tornCity.nerve.max = tc.n.m;
tornCity.nerve.timer = tc.n.t;
tornCity.happy.cur = tc.h.c;
tornCity.happy.max = tc.h.m;
tornCity.happy.timer = tc.h.t;
tornCity.life.cur = tc.l.c;
tornCity.life.max = tc.l.m;
tornCity.life.timer = tc.l.t;
tornCity.faction.id = tc.f.id;
tornCity.faction.chain.cur = tc.f.c.c;
tornCity.faction.chain.max = tc.f.c.m;
tornCity.faction.chain.timer = tc.f.c.t;
}
tc_whatValues();
}
setTimeout('tc_Populate(); if ( tc.timers == true ) tc_attachTimers();',2000);
// https://github.com/paulwratt/torn-city-pwtools/raw/master/tc.torn.js