-
Notifications
You must be signed in to change notification settings - Fork 478
/
nf_rating.js
562 lines (548 loc) ยท 20.1 KB
/
nf_rating.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
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/*
README๏ผhttps://github.com/yichahucha/surge/tree/master
*/
const $tool = new Tool()
const consoleLog = false;
const imdbApikeyCacheKey = "ImdbApikeyCacheKey";
const netflixTitleCacheKey = "NetflixTitleCacheKey";
if (!$tool.isResponse) {
let url = $request.url;
const urlDecode = decodeURIComponent(url);
const videos = urlDecode.match(/"videos","(\d+)"/);
const videoID = videos[1];
const map = getTitleMap();
const title = map[videoID];
const isEnglish = url.match(/languages=en/) ? true : false;
if (!title && !isEnglish) {
const currentSummary = urlDecode.match(/\["videos","(\d+)","current","summary"\]/);
if (currentSummary) {
url = url.replace("&path=" + encodeURIComponent(currentSummary[0]), "");
}
url = url.replace(/&languages=(.*?)&/, "&languages=en-US&");
}
url += "&path=" + encodeURIComponent(`[${videos[0]},"details"]`);
$done({ url });
} else {
var IMDbApikeys = IMDbApikeys();
var IMDbApikey = $tool.read(imdbApikeyCacheKey);
if (!IMDbApikey) updateIMDbApikey();
let obj = JSON.parse($response.body);
if (consoleLog) console.log("Netflix Original Body:\n" + $response.body);
if (typeof (obj.paths[0][1]) == "string") {
const videoID = obj.paths[0][1];
const video = obj.value.videos[videoID];
const map = getTitleMap();
let title = map[videoID];
if (!title) {
title = video.summary.title;
setTitleMap(videoID, title, map);
}
let year = null;
let type = video.summary.type;
if (type == "show") {
type = "series";
}
if (video.details) {
if (type == "movie") {
year = video.details.releaseYear;
}
delete video.details;
}
const requestRatings = async () => {
const IMDb = await requestIMDbRating(title, year, type);
const Douban = await requestDoubanRating(IMDb.id);
const IMDbrating = IMDb.msg.rating;
const tomatoes = IMDb.msg.tomatoes;
const country = IMDb.msg.country;
const awards = IMDb.msg.awards;
const doubanRating = Douban.rating;
const message = `${awards.length > 0 ? awards + "\n": ""}${country}\n${IMDbrating}\n${doubanRating}${tomatoes.length > 0 ? "\n" + tomatoes + "\n" : "\n"}`;
return message;
}
let msg = "";
requestRatings()
.then(message => msg = message)
.catch(error => msg = error + "\n")
.finally(() => {
let summary = obj.value.videos[videoID].summary;
summary["supplementalMessage"] = `${msg}${summary && summary.supplementalMessage ? "\n" + summary.supplementalMessage : ""}`;
msg_obj = {"tagline":summary.supplementalMessage, "classification":"REGULAR"}
if (summary["supplementalMessages"]) {
summary["supplementalMessages"].push(msg_obj)
}else {
summary["supplementalMessages"] = [msg_obj]
}
if (consoleLog) console.log("Netflix Modified Body:\n" + JSON.stringify(obj));
$done({ body: JSON.stringify(obj) });
});
} else {
$done({});
}
}
function getTitleMap() {
const map = $tool.read(netflixTitleCacheKey);
return map ? JSON.parse(map) : {};
}
function setTitleMap(id, title, map) {
map[id] = title;
$tool.write(JSON.stringify(map), netflixTitleCacheKey);
}
function requestDoubanRating(imdbId) {
return new Promise(function (resolve, reject) {
const url = `https://www.douban.com/search?cat=1002&q=${imdbId}`;
if (consoleLog) console.log("Netflix Douban Rating URL:\n" + url);
$tool.get(url, function (error, response, data) {
if (!error) {
if (consoleLog) console.log("Netflix Douban Rating Data:\n" + data);
if (response.status == 200) {
const rating = get_douban_rating_message(data);
resolve({ rating });
} else {
resolve({ rating: "Douban: " + errorTip().noData });
}
} else {
if (consoleLog) console.log("Netflix Douban Rating Error:\n" + error);
resolve({ rating: "Douban: " + errorTip().error });
}
});
});
}
function requestIMDbRating(title, year, type) {
return new Promise(function (resolve, reject) {
let url = "https://www.omdbapi.com/?t=" + encodeURI(title) + "&apikey=" + IMDbApikey;
if (year) url += "&y=" + year;
if (type) url += "&type=" + type;
if (consoleLog) console.log("Netflix IMDb Rating URL:\n" + url);
$tool.get(url, function (error, response, data) {
if (!error) {
if (consoleLog) console.log("Netflix IMDb Rating Data:\n" + data);
if (response.status == 200) {
const obj = JSON.parse(data);
if (obj.Response != "False") {
const id = obj.imdbID;
const msg = get_IMDb_message(obj);
resolve({ id, msg });
} else {
reject(errorTip().noData);
}
} else if (response.status == 401) {
if (IMDbApikeys.length > 1) {
updateIMDbApikey();
requestIMDbRating(title, year, type);
} else {
reject(errorTip().noData);
}
} else {
reject(errorTip().noData);
}
} else {
if (consoleLog) console.log("Netflix IMDb Rating Error:\n" + error);
reject(errorTip().error);
}
});
});
}
function updateIMDbApikey() {
if (IMDbApikey) IMDbApikeys.splice(IMDbApikeys.indexOf(IMDbApikey), 1);
const index = Math.floor(Math.random() * IMDbApikeys.length);
IMDbApikey = IMDbApikeys[index];
$tool.write(IMDbApikey, imdbApikeyCacheKey);
}
function get_IMDb_message(data) {
let rating_message = "IMDb: โญ๏ธ N/A";
let tomatoes_message = "";
let country_message = "";
let ratings = data.Ratings;
let awards_message = "";
if (data.Awards && data.Awards != "N/A") {
awards_message = "๐ " + data.Awards;
}
if (ratings.length > 0) {
const imdb_source = ratings[0]["Source"];
if (imdb_source == "Internet Movie Database") {
const imdb_votes = data.imdbVotes;
const imdb_rating = ratings[0]["Value"];
rating_message = "IMDb: โญ๏ธ " + imdb_rating + " " + imdb_votes;
if (data.Type == "movie") {
if (ratings.length > 1) {
const source = ratings[1]["Source"];
if (source == "Rotten Tomatoes") {
const tomatoes = ratings[1]["Value"];
tomatoes_message = "Tomatoes: ๐
" + tomatoes;
}
}
}
}
}
country_message = get_country_message(data.Country);
return { rating: rating_message, tomatoes: tomatoes_message, country: country_message, awards: awards_message }
}
function get_douban_rating_message(data) {
const s = data.replace(/\n| |&#\d{2}/g, '')
.match(/\[(\u7535\u5f71|\u7535\u89c6\u5267)\].+?subject-cast\">.+?<\/span>/g);
const average = s ? s[0].split(/">(\d\.\d)</)[1] || '' : '';
const numRaters = s ? s[0].split(/(\d+)\u4eba\u8bc4\u4ef7/)[1] || '' : '';
const rating_message = `Douban: โญ๏ธ ${average ? average + "/10" : "N/A"} ${!numRaters ? "" : parseFloat(numRaters).toLocaleString()}`;
return rating_message;
}
function get_country_message(data) {
const country = data;
const countrys = country.split(", ");
let emoji_country = "";
countrys.forEach(item => {
emoji_country += countryEmoji(item) + " " + item + ", ";
});
return emoji_country.slice(0, -2);
}
function errorTip() {
return { noData: "โญ๏ธ N/A", error: "โ N/A" }
}
function IMDbApikeys() {
const apikeys = [
"f75e0253", "d8bb2d6b",
"ae64ce8d", "7218d678",
"b2650e38", "8c4a29ab",
"9bd135c2", "953dbabe",
"1a66ef12", "3e7ea721",
"457fc4ff", "d2131426",
"9cc1a9b7", "e53c2c11",
"f6dfce0e", "b9db622f",
"e6bde2b9", "d324dbab",
"d7904fa3", "aeaf88b9",
"4e89234e",];
return apikeys;
}
function countryEmoji(name) {
const emojiMap = {
"Chequered": "๐",
"Triangular": "๐ฉ",
"Crossed": "๐",
"Black": "๐ด",
"White": "๐ณ",
"Rainbow": "๐ณ๏ธโ๐",
"Pirate": "๐ดโโ ๏ธ",
"Ascension Island": "๐ฆ๐จ",
"Andorra": "๐ฆ๐ฉ",
"United Arab Emirates": "๐ฆ๐ช",
"Afghanistan": "๐ฆ๐ซ",
"Antigua & Barbuda": "๐ฆ๐ฌ",
"Anguilla": "๐ฆ๐ฎ",
"Albania": "๐ฆ๐ฑ",
"Armenia": "๐ฆ๐ฒ",
"Angola": "๐ฆ๐ด",
"Antarctica": "๐ฆ๐ถ",
"Argentina": "๐ฆ๐ท",
"American Samoa": "๐ฆ๐ธ",
"Austria": "๐ฆ๐น",
"Australia": "๐ฆ๐บ",
"Aruba": "๐ฆ๐ผ",
"ร
land Islands": "๐ฆ๐ฝ",
"Azerbaijan": "๐ฆ๐ฟ",
"Bosnia & Herzegovina": "๐ง๐ฆ",
"Barbados": "๐ง๐ง",
"Bangladesh": "๐ง๐ฉ",
"Belgium": "๐ง๐ช",
"Burkina Faso": "๐ง๐ซ",
"Bulgaria": "๐ง๐ฌ",
"Bahrain": "๐ง๐ญ",
"Burundi": "๐ง๐ฎ",
"Benin": "๐ง๐ฏ",
"St. Barthรฉlemy": "๐ง๐ฑ",
"Bermuda": "๐ง๐ฒ",
"Brunei": "๐ง๐ณ",
"Bolivia": "๐ง๐ด",
"Caribbean Netherlands": "๐ง๐ถ",
"Brazil": "๐ง๐ท",
"Bahamas": "๐ง๐ธ",
"Bhutan": "๐ง๐น",
"Bouvet Island": "๐ง๐ป",
"Botswana": "๐ง๐ผ",
"Belarus": "๐ง๐พ",
"Belize": "๐ง๐ฟ",
"Canada": "๐จ๐ฆ",
"Cocos (Keeling) Islands": "๐จ๐จ",
"Congo - Kinshasa": "๐จ๐ฉ",
"Congo": "๐จ๐ฉ",
"Central African Republic": "๐จ๐ซ",
"Congo - Brazzaville": "๐จ๐ฌ",
"Switzerland": "๐จ๐ญ",
"Cรดte dโIvoire": "๐จ๐ฎ",
"Cook Islands": "๐จ๐ฐ",
"Chile": "๐จ๐ฑ",
"Cameroon": "๐จ๐ฒ",
"China": "๐จ๐ณ",
"Colombia": "๐จ๐ด",
"Clipperton Island": "๐จ๐ต",
"Costa Rica": "๐จ๐ท",
"Cuba": "๐จ๐บ",
"Cape Verde": "๐จ๐ป",
"Curaรงao": "๐จ๐ผ",
"Christmas Island": "๐จ๐ฝ",
"Cyprus": "๐จ๐พ",
"Czechia": "๐จ๐ฟ",
"Czech Republic": "๐จ๐ฟ",
"Germany": "๐ฉ๐ช",
"Diego Garcia": "๐ฉ๐ฌ",
"Djibouti": "๐ฉ๐ฏ",
"Denmark": "๐ฉ๐ฐ",
"Dominica": "๐ฉ๐ฒ",
"Dominican Republic": "๐ฉ๐ด",
"Algeria": "๐ฉ๐ฟ",
"Ceuta & Melilla": "๐ช๐ฆ",
"Ecuador": "๐ช๐จ",
"Estonia": "๐ช๐ช",
"Egypt": "๐ช๐ฌ",
"Western Sahara": "๐ช๐ญ",
"Eritrea": "๐ช๐ท",
"Spain": "๐ช๐ธ",
"Ethiopia": "๐ช๐น",
"European Union": "๐ช๐บ",
"Finland": "๐ซ๐ฎ",
"Fiji": "๐ซ๐ฏ",
"Falkland Islands": "๐ซ๐ฐ",
"Micronesia": "๐ซ๐ฒ",
"Faroe Islands": "๐ซ๐ด",
"France": "๐ซ๐ท",
"Gabon": "๐ฌ๐ฆ",
"United Kingdom": "๐ฌ๐ง",
"UK": "๐ฌ๐ง",
"Grenada": "๐ฌ๐ฉ",
"Georgia": "๐ฌ๐ช",
"French Guiana": "๐ฌ๐ซ",
"Guernsey": "๐ฌ๐ฌ",
"Ghana": "๐ฌ๐ญ",
"Gibraltar": "๐ฌ๐ฎ",
"Greenland": "๐ฌ๐ฑ",
"Gambia": "๐ฌ๐ฒ",
"Guinea": "๐ฌ๐ณ",
"Guadeloupe": "๐ฌ๐ต",
"Equatorial Guinea": "๐ฌ๐ถ",
"Greece": "๐ฌ๐ท",
"South Georgia & South Sandwich Is lands": "๐ฌ๐ธ",
"Guatemala": "๐ฌ๐น",
"Guam": "๐ฌ๐บ",
"Guinea-Bissau": "๐ฌ๐ผ",
"Guyana": "๐ฌ๐พ",
"Hong Kong SAR China": "๐ญ๐ฐ",
"Hong Kong": "๐ญ๐ฐ",
"Heard & McDonald Islands": "๐ญ๐ฒ",
"Honduras": "๐ญ๐ณ",
"Croatia": "๐ญ๐ท",
"Haiti": "๐ญ๐น",
"Hungary": "๐ญ๐บ",
"Canary Islands": "๐ฎ๐จ",
"Indonesia": "๐ฎ๐ฉ",
"Ireland": "๐ฎ๐ช",
"Israel": "๐ฎ๐ฑ",
"Isle of Man": "๐ฎ๐ฒ",
"India": "๐ฎ๐ณ",
"British Indian Ocean Territory": "๐ฎ๐ด",
"Iraq": "๐ฎ๐ถ",
"Iran": "๐ฎ๐ท",
"Iceland": "๐ฎ๐ธ",
"Italy": "๐ฎ๐น",
"Jersey": "๐ฏ๐ช",
"Jamaica": "๐ฏ๐ฒ",
"Jordan": "๐ฏ๐ด",
"Japan": "๐ฏ๐ต",
"Kenya": "๐ฐ๐ช",
"Kyrgyzstan": "๐ฐ๐ฌ",
"Cambodia": "๐ฐ๐ญ",
"Kiribati": "๐ฐ๐ฎ",
"Comoros": "๐ฐ๐ฒ",
"St. Kitts & Nevis": "๐ฐ๐ณ",
"North Korea": "๐ฐ๐ต",
"South Korea": "๐ฐ๐ท",
"Kuwait": "๐ฐ๐ผ",
"Cayman Islands": "๐ฐ๐พ",
"Kazakhstan": "๐ฐ๐ฟ",
"Laos": "๐ฑ๐ฆ",
"Lebanon": "๐ฑ๐ง",
"St. Lucia": "๐ฑ๐จ",
"Liechtenstein": "๐ฑ๐ฎ",
"Sri Lanka": "๐ฑ๐ฐ",
"Liberia": "๐ฑ๐ท",
"Lesotho": "๐ฑ๐ธ",
"Lithuania": "๐ฑ๐น",
"Luxembourg": "๐ฑ๐บ",
"Latvia": "๐ฑ๐ป",
"Libya": "๐ฑ๐พ",
"Morocco": "๐ฒ๐ฆ",
"Monaco": "๐ฒ๐จ",
"Moldova": "๐ฒ๐ฉ",
"Montenegro": "๐ฒ๐ช",
"St. Martin": "๐ฒ๐ซ",
"Madagascar": "๐ฒ๐ฌ",
"Marshall Islands": "๐ฒ๐ญ",
"North Macedonia": "๐ฒ๐ฐ",
"Mali": "๐ฒ๐ฑ",
"Myanmar (Burma)": "๐ฒ๐ฒ",
"Mongolia": "๐ฒ๐ณ",
"Macau Sar China": "๐ฒ๐ด",
"Northern Mariana Islands": "๐ฒ๐ต",
"Martinique": "๐ฒ๐ถ",
"Mauritania": "๐ฒ๐ท",
"Montserrat": "๐ฒ๐ธ",
"Malta": "๐ฒ๐น",
"Mauritius": "๐ฒ๐บ",
"Maldives": "๐ฒ๐ป",
"Malawi": "๐ฒ๐ผ",
"Mexico": "๐ฒ๐ฝ",
"Malaysia": "๐ฒ๐พ",
"Mozambique": "๐ฒ๐ฟ",
"Namibia": "๐ณ๐ฆ",
"New Caledonia": "๐ณ๐จ",
"Niger": "๐ณ๐ช",
"Norfolk Island": "๐ณ๐ซ",
"Nigeria": "๐ณ๐ฌ",
"Nicaragua": "๐ณ๐ฎ",
"Netherlands": "๐ณ๐ฑ",
"Norway": "๐ณ๐ด",
"Nepal": "๐ณ๐ต",
"Nauru": "๐ณ๐ท",
"Niue": "๐ณ๐บ",
"New Zealand": "๐ณ๐ฟ",
"Oman": "๐ด๐ฒ",
"Panama": "๐ต๐ฆ",
"Peru": "๐ต๐ช",
"French Polynesia": "๐ต๐ซ",
"Papua New Guinea": "๐ต๐ฌ",
"Philippines": "๐ต๐ญ",
"Pakistan": "๐ต๐ฐ",
"Poland": "๐ต๐ฑ",
"St. Pierre & Miquelon": "๐ต๐ฒ",
"Pitcairn Islands": "๐ต๐ณ",
"Puerto Rico": "๐ต๐ท",
"Palestinian Territories": "๐ต๐ธ",
"Portugal": "๐ต๐น",
"Palau": "๐ต๐ผ",
"Paraguay": "๐ต๐พ",
"Qatar": "๐ถ๐ฆ",
"Rรฉunion": "๐ท๐ช",
"Romania": "๐ท๐ด",
"Serbia": "๐ท๐ธ",
"Russia": "๐ท๐บ",
"Rwanda": "๐ท๐ผ",
"Saudi Arabia": "๐ธ๐ฆ",
"Solomon Islands": "๐ธ๐ง",
"Seychelles": "๐ธ๐จ",
"Sudan": "๐ธ๐ฉ",
"Sweden": "๐ธ๐ช",
"Singapore": "๐ธ๐ฌ",
"St. Helena": "๐ธ๐ญ",
"Slovenia": "๐ธ๐ฎ",
"Svalbard & Jan Mayen": "๐ธ๐ฏ",
"Slovakia": "๐ธ๐ฐ",
"Sierra Leone": "๐ธ๐ฑ",
"San Marino": "๐ธ๐ฒ",
"Senegal": "๐ธ๐ณ",
"Somalia": "๐ธ๐ด",
"Suriname": "๐ธ๐ท",
"South Sudan": "๐ธ๐ธ",
"Sรฃo Tomรฉ & Prรญncipe": "๐ธ๐น",
"El Salvador": "๐ธ๐ป",
"Sint Maarten": "๐ธ๐ฝ",
"Syria": "๐ธ๐พ",
"Swaziland": "๐ธ๐ฟ",
"Tristan Da Cunha": "๐น๐ฆ",
"Turks & Caicos Islands": "๐น๐จ",
"Chad": "๐น๐ฉ",
"French Southern Territories": "๐น๐ซ",
"Togo": "๐น๐ฌ",
"Thailand": "๐น๐ญ",
"Tajikistan": "๐น๐ฏ",
"Tokelau": "๐น๐ฐ",
"Timor-Leste": "๐น๐ฑ",
"Turkmenistan": "๐น๐ฒ",
"Tunisia": "๐น๐ณ",
"Tonga": "๐น๐ด",
"Turkey": "๐น๐ท",
"Trinidad & Tobago": "๐น๐น",
"Tuvalu": "๐น๐ป",
"Taiwan": "๐จ๐ณ",
"Tanzania": "๐น๐ฟ",
"Ukraine": "๐บ๐ฆ",
"Uganda": "๐บ๐ฌ",
"U.S. Outlying Islands": "๐บ๐ฒ",
"United Nations": "๐บ๐ณ",
"United States": "๐บ๐ธ",
"USA": "๐บ๐ธ",
"Uruguay": "๐บ๐พ",
"Uzbekistan": "๐บ๐ฟ",
"Vatican City": "๐ป๐ฆ",
"St. Vincent & Grenadines": "๐ป๐จ",
"Venezuela": "๐ป๐ช",
"British Virgin Islands": "๐ป๐ฌ",
"U.S. Virgin Islands": "๐ป๐ฎ",
"Vietnam": "๐ป๐ณ",
"Vanuatu": "๐ป๐บ",
"Wallis & Futuna": "๐ผ๐ซ",
"Samoa": "๐ผ๐ธ",
"Kosovo": "๐ฝ๐ฐ",
"Yemen": "๐พ๐ช",
"Mayotte": "๐พ๐น",
"South Africa": "๐ฟ๐ฆ",
"Zambia": "๐ฟ๐ฒ",
"Zimbabwe": "๐ฟ๐ผ",
"England": "๐ด๓ ง๓ ข๓ ฅ๓ ฎ๓ ง๓ ฟ",
"Scotland": "๐ด๓ ง๓ ข๓ ณ๓ ฃ๓ ด๓ ฟ",
"Wales": "๐ด๓ ง๓ ข๓ ท๓ ฌ๓ ณ๓ ฟ",
}
return emojiMap[name] ? emojiMap[name] : emojiMap["Chequered"];
}
function Tool() {
_node = (() => {
if (typeof require == "function") {
const request = require('request')
return ({ request })
} else {
return (null)
}
})()
_isSurge = typeof $httpClient != "undefined"
_isQuanX = typeof $task != "undefined"
this.isSurge = _isSurge
this.isQuanX = _isQuanX
this.isResponse = typeof $response != "undefined"
this.notify = (title, subtitle, message) => {
if (_isQuanX) $notify(title, subtitle, message)
if (_isSurge) $notification.post(title, subtitle, message)
if (_node) console.log(JSON.stringify({ title, subtitle, message }));
}
this.write = (value, key) => {
if (_isQuanX) return $prefs.setValueForKey(value, key)
if (_isSurge) return $persistentStore.write(value, key)
}
this.read = (key) => {
if (_isQuanX) return $prefs.valueForKey(key)
if (_isSurge) return $persistentStore.read(key)
}
this.get = (options, callback) => {
if (_isQuanX) {
if (typeof options == "string") options = { url: options }
options["method"] = "GET"
$task.fetch(options).then(response => { callback(null, _status(response), response.body) }, reason => callback(reason.error, null, null))
}
if (_isSurge) $httpClient.get(options, (error, response, body) => { callback(error, _status(response), body) })
if (_node) _node.request(options, (error, response, body) => { callback(error, _status(response), body) })
}
this.post = (options, callback) => {
if (_isQuanX) {
if (typeof options == "string") options = { url: options }
options["method"] = "POST"
$task.fetch(options).then(response => { callback(null, _status(response), response.body) }, reason => callback(reason.error, null, null))
}
if (_isSurge) $httpClient.post(options, (error, response, body) => { callback(error, _status(response), body) })
if (_node) _node.request.post(options, (error, response, body) => { callback(error, _status(response), body) })
}
_status = (response) => {
if (response) {
if (response.status) {
response["statusCode"] = response.status
} else if (response.statusCode) {
response["status"] = response.statusCode
}
}
return response
}
}