Adrià Vilanova Martínez | 4f56d56 | 2022-01-26 00:23:27 +0100 | [diff] [blame] | 1 | window.addEventListener('message', e => { |
| 2 | if (e.source === window && e.data?.prefix === 'TWPT-extrainfo') { |
| 3 | switch (e.data?.action) { |
Adrià Vilanova Martínez | 69c3050 | 2022-01-28 20:47:08 +0100 | [diff] [blame] | 4 | case 'renderProfileActivityChart': |
| 5 | if (typeof window.sc_renderProfileActivityChart !== 'function') { |
| 6 | console.error( |
| 7 | 'extraInfo: window.sc_renderProfileActivityChart is not available.'); |
Adrià Vilanova Martínez | 4f56d56 | 2022-01-26 00:23:27 +0100 | [diff] [blame] | 8 | return; |
| 9 | } |
Adrià Vilanova Martínez | 69c3050 | 2022-01-28 20:47:08 +0100 | [diff] [blame] | 10 | |
| 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ínez | 4f56d56 | 2022-01-26 00:23:27 +0100 | [diff] [blame] | 21 | break; |
| 22 | |
| 23 | default: |
| 24 | console.error( |
| 25 | 'Action \'' + e.data?.action + |
| 26 | '\' unknown to TWPT-extrainfo receiver.'); |
| 27 | } |
| 28 | } |
| 29 | }); |