avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 1 | import {getOptions} from '../common/optionsUtils.js'; |
Adrià Vilanova Martínez | 4677317 | 2024-01-10 21:44:22 +0100 | [diff] [blame] | 2 | import {parseView} from '../common/TWBasicUtils.js'; |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 3 | |
| 4 | import PerForumStatsSection from './communityConsole/utils/PerForumStatsSection.js'; |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 5 | import {injectPreviousPostsLinksUnifiedProfile} from './utilsCommon/unifiedProfiles.js'; |
| 6 | |
Adrià Vilanova Martínez | 4677317 | 2024-01-10 21:44:22 +0100 | [diff] [blame] | 7 | const kProfileViewVar = 'view'; |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 8 | |
Adrià Vilanova Martínez | 89c5481 | 2022-06-06 13:32:29 +0200 | [diff] [blame] | 9 | getOptions(['history', 'perforumstats']).then(options => { |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 10 | if (options?.history) |
| 11 | injectPreviousPostsLinksUnifiedProfile(/* isCommunityConsole = */ false); |
| 12 | |
Adrià Vilanova Martínez | 89c5481 | 2022-06-06 13:32:29 +0200 | [diff] [blame] | 13 | if (options?.perforumstats) { |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 14 | try { |
| 15 | // Find chart |
| 16 | const chart = document.querySelector( |
| 17 | 'sc-tailwind-user_profile-user-profile ' + |
| 18 | '.scTailwindUser_profileUserprofilesection ' + |
| 19 | 'sc-tailwind-shared-activity-chart'); |
| 20 | if (!chart) throw new Error('Couldn\'t find existing chart.'); |
| 21 | |
| 22 | // Extract profile JSON information |
Adrià Vilanova Martínez | 4677317 | 2024-01-10 21:44:22 +0100 | [diff] [blame] | 23 | const profileView = parseView(kProfileViewVar); |
| 24 | const profileViewC = {'1': profileView}; |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 25 | if (!profileView) throw new Error('Could not find user view data.'); |
| 26 | new PerForumStatsSection( |
| 27 | chart?.parentNode, profileViewC, |
| 28 | document.documentElement?.lang ?? 'en', |
| 29 | /* isCommunityConsole = */ false); |
| 30 | } catch (err) { |
| 31 | console.error('Error while injecting extra info: ', err); |
| 32 | } |
| 33 | } |
| 34 | }); |