blob: 375831413455ad35e78efe683e3fbd96438cf9a7 [file] [log] [blame]
Adrià Vilanova Martínez4f56d562022-01-26 00:23:27 +01001window.addEventListener('message', e => {
2 if (e.source === window && e.data?.prefix === 'TWPT-extrainfo') {
3 switch (e.data?.action) {
Adrià Vilanova Martínez69c30502022-01-28 20:47:08 +01004 case 'renderProfileActivityChart':
5 if (typeof window.sc_renderProfileActivityChart !== 'function') {
6 console.error(
7 'extraInfo: window.sc_renderProfileActivityChart is not available.');
Adrià Vilanova Martínez4f56d562022-01-26 00:23:27 +01008 return;
9 }
Adrià Vilanova Martínez69c30502022-01-28 20:47:08 +010010
11 let chartEl = document.querySelector(
12 '.scTailwindSharedActivitychartchart[data-twpt-per-forum-chart]');
13 if (!chartEl) {
14 console.error('extraInfo: couldn\'t find per-forum chart div.');
15 return;
16 }
17
18 chartEl.replaceChildren();
19 window.sc_renderProfileActivityChart(
20 chartEl, e.data?.data, e.data?.metadata, e.data?.chartTitle);
Adrià Vilanova Martínez4f56d562022-01-26 00:23:27 +010021 break;
22
23 default:
24 console.error(
25 'Action \'' + e.data?.action +
26 '\' unknown to TWPT-extrainfo receiver.');
27 }
28 }
29});