Add profile indicator support in CC interop threads
Bug: twpowertools:96
Change-Id: Ida952fec9828999fefefd03882a7b2589cc9b66a
diff --git a/src/injections/profileIndicator.js b/src/injections/profileIndicator.js
index ae96b3f..98c6092 100644
--- a/src/injections/profileIndicator.js
+++ b/src/injections/profileIndicator.js
@@ -4,7 +4,7 @@
import {createPlainTooltip} from '../common/tooltip.js';
var CCProfileRegex =
- /^(?:https:\/\/support\.google\.com)?\/s\/community(?:\/forum\/[0-9]*)?\/user\/(?:[0-9]+)$/;
+ /^(?:https:\/\/support\.google\.com)?\/s\/community(?:\/forum\/[0-9]*)?\/user\/(?:[0-9]+)(?:\?.*)?$/;
var CCRegex = /^https:\/\/support\.google\.com\/s\/community/;
const OP_FIRST_POST = 0;
@@ -26,6 +26,7 @@
const UI_COMMUNITY_CONSOLE = 0;
const UI_TW_LEGACY = 1;
const UI_TW_INTEROP = 2;
+const UI_COMMUNITY_CONSOLE_INTEROP = 3;
const indicatorTypes = ['numPosts', 'indicatorDot'];
@@ -37,6 +38,14 @@
var authuser = null;
+function isCommunityConsole(ui) {
+ return ui === UI_COMMUNITY_CONSOLE || ui === UI_COMMUNITY_CONSOLE_INTEROP;
+}
+
+function isInterop(ui) {
+ return ui === UI_TW_INTEROP || ui === UI_COMMUNITY_CONSOLE_INTEROP;
+}
+
function isElementInside(element, outerTag) {
while (element !== null && ('tagName' in element)) {
if (element.tagName == outerTag) return true;
@@ -115,8 +124,8 @@
var dotContainer = document.createElement('div');
dotContainer.classList.add('profile-indicator', 'profile-indicator--loading');
- var dotLink = (ui === UI_COMMUNITY_CONSOLE) ? createImmuneLink() :
- document.createElement('a');
+ var dotLink = (isCommunityConsole(ui)) ? createImmuneLink() :
+ document.createElement('a');
dotLink.href = searchURL;
dotLink.innerText = '●';
@@ -135,8 +144,8 @@
// Create badge indicating the number of posts with a loading state
function createNumPostsBadge(sourceNode, searchURL, ui) {
- var link = (ui === UI_COMMUNITY_CONSOLE) ? createImmuneLink() :
- document.createElement('a');
+ var link = (isCommunityConsole(ui)) ? createImmuneLink() :
+ document.createElement('a');
link.href = searchURL;
var numPostsContainer = document.createElement('div');
@@ -180,10 +189,10 @@
if (ui === UI_COMMUNITY_CONSOLE)
nameEl = sourceNode.querySelector('.name-text');
if (ui === UI_TW_LEGACY) nameEl = sourceNode.querySelector('span');
- if (ui === UI_TW_INTEROP) nameEl = sourceNode;
+ if (isInterop(ui)) nameEl = sourceNode;
var escapedUsername = escapeUsername(nameEl.textContent);
- if (ui === UI_COMMUNITY_CONSOLE) {
+ if (isCommunityConsole(ui)) {
var threadLink = document.location.href;
} else {
var CCLink = document.getElementById('onebar-community-console');
@@ -213,10 +222,10 @@
if (options.numPosts) {
var profileURL = new URL(sourceNode.href);
- var userId =
- profileURL.pathname
- .split(ui === UI_COMMUNITY_CONSOLE ? 'user/' : 'profile/')[1]
- .split('/')[0];
+ var userId = profileURL.pathname
+ .split(isCommunityConsole(ui) ? 'user/' : 'profile/')[1]
+ .split('?')[0]
+ .split('/')[0];
var numPostsContainer = createNumPostsBadge(sourceNode, searchURL, ui);
@@ -344,11 +353,19 @@
if (mutation.type == 'childList') {
mutation.addedNodes.forEach(function(node) {
if (node.tagName == 'A' && ('href' in node) &&
- CCProfileRegex.test(node.href) &&
- node.matches(
- 'ec-question ec-message-header .name-section ec-user-link a')) {
- console.info('Handling profile indicator via mutation callback.');
- getOptionsAndHandleIndicators(node, UI_COMMUNITY_CONSOLE);
+ CCProfileRegex.test(node.href)) {
+ if (node.matches(
+ 'ec-question ec-message-header .name-section ec-user-link a')) {
+ console.info('Handling profile indicator via mutation callback.');
+ getOptionsAndHandleIndicators(node, UI_COMMUNITY_CONSOLE);
+ } else if (node.matches(
+ 'sc-tailwind-thread-question-question-card ' +
+ 'sc-tailwind-thread-post_header-user-info ' +
+ '.scTailwindThreadPost_headerUserinfoname a')) {
+ console.info(
+ 'Handling interop profile indicator via mutation callback.');
+ getOptionsAndHandleIndicators(node, UI_COMMUNITY_CONSOLE_INTEROP);
+ }
}
});
}
@@ -367,6 +384,15 @@
if (node !== null) {
console.info('Handling profile indicator via first check.');
getOptionsAndHandleIndicators(node, UI_COMMUNITY_CONSOLE);
+ } else {
+ var node = document.querySelector(
+ 'sc-tailwind-thread-question-question-card ' +
+ 'sc-tailwind-thread-post_header-user-info ' +
+ '.scTailwindThreadPost_headerUserinfoname a');
+ if (node !== null) {
+ console.info('Handling interop profile indicator via first check.');
+ getOptionsAndHandleIndicators(node, UI_COMMUNITY_CONSOLE_INTEROP);
+ }
}
var mutationObserver = new MutationObserver(mutationCallback);