Fix per-forum activity in TW basic
Fixed: twpowertools:169
Change-Id: I77a25cb5a047cdf84b74de79ecba2ad3591ef33c
diff --git a/src/contentScripts/communityConsole/utils/PerForumStatsSection.js b/src/contentScripts/communityConsole/utils/PerForumStatsSection.js
index b0074f6..c0154e8 100644
--- a/src/contentScripts/communityConsole/utils/PerForumStatsSection.js
+++ b/src/contentScripts/communityConsole/utils/PerForumStatsSection.js
@@ -115,7 +115,7 @@
getAplosData(forumId) {
let aplosData = [];
for (const [key, name, color] of kDataKeys) {
- let rawData = this.data.find(f => f.id === forumId)?.forumUserInfo?.[key];
+ let rawData = this.data.find(f => f.id == forumId)?.forumUserInfo?.[key];
let data;
if (!rawData) {
data = [];
diff --git a/src/contentScripts/publicProfile.js b/src/contentScripts/publicProfile.js
index 693aa3f..6c3da8d 100644
--- a/src/contentScripts/publicProfile.js
+++ b/src/contentScripts/publicProfile.js
@@ -4,7 +4,7 @@
import PerForumStatsSection from './communityConsole/utils/PerForumStatsSection.js';
import {injectPreviousPostsLinksUnifiedProfile} from './utilsCommon/unifiedProfiles.js';
-const profileViewRegex = /var view ?= ?(.+\]);/;
+const profileViewRegex = /var view ?= ?'([^']+)';/;
getOptions(['history', 'perforumstats']).then(options => {
if (options?.history)
@@ -25,12 +25,22 @@
for (let i = 0; i < scripts.length; ++i) {
const matches = scripts[i].textContent.match(profileViewRegex);
if (matches?.[1]) {
- profileView = JSON.parse(matches[1]);
+ let rawJsonStringContents =
+ matches[1]
+ .replace(
+ /\\x([0-9a-f]{2})/ig,
+ (_, pair) => {
+ return String.fromCharCode(parseInt(pair, 16));
+ })
+ .replace(/\\'/g, `'`)
+ .replace(/"/g, `\\"`);
+ let rawJsonString = `"${rawJsonStringContents}"`;
+ let rawJson = JSON.parse(rawJsonString);
+ profileView = JSON.parse(rawJson);
break;
}
}
const profileViewC = {'1': correctArrayKeys(profileView)};
- console.log(profileViewC);
if (!profileView) throw new Error('Could not find user view data.');
new PerForumStatsSection(
chart?.parentNode, profileViewC,