-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
52 lines (47 loc) · 1.47 KB
/
index.ts
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
/* eslint-disable import/no-unused-modules */
/** TNS counter options */
export interface TnsCounterOptions {
/** Account ID */
account: string
/** Param */
tmsec: string
}
/** TNS counter */
export class TnsCounter {
/** Promise that resolves when counter is ready */
ready: Promise<void>
/** TNS counter constructor */
constructor(options: TnsCounterOptions) {
this.ready = new Promise((resolve) => {
if (process.env.NODE_ENV === 'development') {
resolve()
return
}
/* eslint-disable */
// prettier-ignore
;(function(win, doc, cb){
// @ts-ignore
(win[cb] = win[cb] || []).push(function() {
try {
// @ts-ignore
win[`tnsCounter${options.account}_${options.tmsec}`] = new Mediascope.TnsCounter({
account: options.account,
tmsec: options.tmsec
});
} catch {}
});
var tnsscript = doc.createElement('script');
tnsscript.type = 'text/javascript';
tnsscript.async = true;
tnsscript.src = ('https:' == doc.location.protocol ? 'https:' : 'http:') +
'//www.tns-counter.ru/tcounter.js';
tnsscript.onload = () => resolve();
tnsscript.onerror = () => resolve();
var s = doc.getElementsByTagName('script')[0];
// @ts-ignore
s.parentNode.insertBefore(tnsscript, s);
})(window, window.document,'tnscounter_callback');
/* eslint-enable */
})
}
}