-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIKS.gadget.js
214 lines (182 loc) · 6.56 KB
/
IKS.gadget.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
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
export class IKSGadget {
constructor(){
this.approval = false;
this.userInfo = {};
this.userToken = {};
this.form = [];
//内部用関数の実行状況
this.checkinState = {};
this.waiting = 0.0;
this.recoveryState = 0;
}
// 利用条件を調べる
async agreement(){
this.approval = confirm( "このツールでは駅メモ! Our-Rails利用規約に抵触する行為を行います\nツールの実行を開始してもよろしいですか" );
this.userInfo = await this.getUserInfo();
this.userToken = this.getCSRFToken();
return 0;
}
// main
async main(){
await this.agreement();
if ( this.approval !== true || !this.userInfo.contents.owner.platform.id.length || !this.userToken.length ){
alert( "利用条件を満たしていません。" );
return -1;
}
}
/*
* 内部用関数
*/
delay(n){
this.waiting = n;
return new Promise(function(resolve){
setTimeout(resolve,n*1000);
});
}
// fetch
ourFetch(uri, subParams){
const baseParams = {
credentials : 'include',
headers : {
'x-csrf-token' : this.userToken,
'x-requested-with' : 'XMLHttpRequest',
'Content-Type' : 'application/json'
}
};
const params = mergeDeeply(baseParams, subParams);
return fetch(uri, params);
}
// アカウントトークン取得
getCSRFToken(){
let csrf_token = "";
document.cookie.split(';').forEach((v)=>{
if (v.match(/csrf_token=/)){
csrf_token = v.match(/csrf_token=/)['input'].split('=')[1];
}
});
return csrf_token;
}
// ユーザ情報取得
getUserInfo(){
const time = (new Date()).getTime();
const uri = "https://game.our-rails.ekimemo.com/api/bundled/prefetch?__t" + time;
return this.ourFetch(uri, { method:'GET' }).then(res=>res.json());
}
// チェックイン
checkin( coord, dencoh ){
const time = (new Date()).getTime();
const uri = "https://game.our-rails.ekimemo.com/api/actions/access/checkin";
const Param = {
__t : time,
__os_id : this.userInfo.contents.owner.platform.id,
acc : 0,
acquired : '',
kalman_distance : '',
kalman_lat : '',
kalman_lng : '',
lat : coord.lat,
lng : coord.lng,
partner_name_en : dencoh,
speed : null,
mocked : null,
time : Math.floor(time/1000),
}
this.checkinState = this.ourFetch(uri + getURIstr(Param), { method:'POST' }).then(res=>res.json());
return this.checkinState;
};
// HP 全回復
fullRecovery( dencoh ){
const time = (new Date()).getTime();
const uri = "https://game.our-rails.ekimemo.com/api/actions/partner/full_recovery";
const Param = {
__t : time,
__os_id : this.userInfo.contents.owner.platform.id
};
const body = {
target_name_en : dencoh
};
return this.ourFetch(uri + getURIstr(Param), { method:'POST', body:JSON.stringify(body) }).then(res=>res.json());
};
// 編成 取得
getFormation(){
const time = (new Date()).getTime();
const uri = "https://game.our-rails.ekimemo.com/api/my/slots";
const Param = {
__t : time,
__os_id : this.userInfo.contents.owner.platform.id,
fields : 'hp,name_en,linked_stations,dress,theme_color'
};
return this.ourFetch(uri + getURIstr(Param)).then(res=>res.json());
};
// 編成 設定
setFormation(formation){
const time = (new Date()).getTime();
const uri = "https://game.our-rails.ekimemo.com/api/my/slots";
const Param = {
__t : time,
__os_id : this.userInfo.contents.owner.platform.id,
fields : 'hp,name_en,linked_stations,dress,theme_color'
};
const body = {
formation : formation
};
return this.ourFetch(uri + getURIstr(Param), { method:'POST', body:JSON.stringify(body) }).then(res=>res.json());
}
// ふくびき
pullLottery(){
const time = (new Date()).getTime();
const uri = "https://game.our-rails.ekimemo.com/api/actions/daily_mission/lottery_box/lot";
const Param = {
__t : time,
__os_id : this.userInfo.contents.owner.platform.id
};
const body = {
lottery_box_id : 1
};
return this.ourFetch(uri + getURIstr(Param), { method:'POST', body:JSON.stringify(body) }).then(res=>res.json());
}
// HP 自動回復
autoRecovery(){
this.recoveryState = setInterval(()=>{
this.getFormation().then((res)=>{
res.contents.forEach((e)=>{
if (e.hp.current < e.hp.max){
this.fullRecovery( e.name_en );
}
})
});
}, 1000)
};
// HP 自動回復 停止
stopRecovery(){
clearInterval( this.recoveryState );
this.recoveryState = 0;
return 0;
}
}
function getURIstr(params){
const paramStr = "?" + Object.entries(params).map((p) => {
return `${p[0]}=${p[1]}`;
}).join("&");
return paramStr;
}
function mergeDeeply(target, source, opts) {
const isObject = obj => obj && typeof obj === 'object' && !Array.isArray(obj);
const isConcatArray = opts && opts.concatArray;
let result = Object.assign({}, target);
if (isObject(target) && isObject(source)) {
for (const [sourceKey, sourceValue] of Object.entries(source)) {
const targetValue = target[sourceKey];
if (isConcatArray && Array.isArray(sourceValue) && Array.isArray(targetValue)) {
result[sourceKey] = targetValue.concat(...sourceValue);
}
else if (isObject(sourceValue) && target.hasOwnProperty(sourceKey)) {
result[sourceKey] = mergeDeeply(targetValue, sourceValue, opts);
}
else {
Object.assign(result, {[sourceKey]: sourceValue});
}
}
}
return result;
}