blob: d3995ea1a121f8f94c1628979dad160440cbb365 [file] [log] [blame]
import {escapeUsername} from '../../common/communityConsoleUtils.js';
import {isOptionEnabled} from '../../common/optionsUtils.js';
import {createExtBadge} from '../communityConsole/utils/common.js';
var authuser = (new URL(location.href)).searchParams.get('authuser') || '0';
export function getSearchUrl(query) {
var urlpart = encodeURIComponent('query=' + encodeURIComponent(query));
var authuserpart =
(authuser == '0' ? '' : '?authuser=' + encodeURIComponent(authuser));
return 'https://support.google.com/s/community/search/' + urlpart +
authuserpart;
}
export function injectPreviousPostsLinksUnifiedProfile(isCommunityConsole) {
var nameElement =
document.querySelector('.scTailwindUser_profileUsercardname');
if (nameElement === null) {
console.error('[previousposts] Can\'t find username.');
return;
}
var name = escapeUsername(nameElement.textContent);
var filter = '(creator:"' + name + '" | replier:"' + name + '") forum:any';
var url = getSearchUrl(filter);
var links = document.createElement('div');
links.classList.add('TWPT-user-profile__user-links');
var a = document.createElement('a');
a.classList.add('TWPT-user-profile__user-link', 'TWPT-user-link');
a.href = url;
a.target = '_parent';
a.setAttribute(
'data-stats-id', 'user-posts-link--tw-power-tools-by-avm99963');
let badge;
if (isCommunityConsole) {
badge = createExtBadge();
} else {
badge = document.createElement('span');
badge.classList.add('TWPT-badge');
badge.setAttribute(
'title', chrome.i18n.getMessage('inject_extension_badge_helper', [
chrome.i18n.getMessage('appName')
]));
var badgeImg = document.createElement('img');
badgeImg.src =
'https://fonts.gstatic.com/s/i/materialicons/repeat/v6/24px.svg';
badge.appendChild(badgeImg);
}
a.appendChild(badge);
var span = document.createElement('span');
span.textContent = chrome.i18n.getMessage('inject_previousposts');
a.appendChild(span);
links.appendChild(a);
var userDetailsNode =
document.querySelector('.scTailwindUser_profileUsercarddetails');
if (userDetailsNode === null) {
console.error('[previousposts] Can\'t get user card details div.');
return;
}
userDetailsNode.parentNode.insertBefore(links, userDetailsNode.nextSibling);
}
export function injectPreviousPostsLinksUnifiedProfileIfEnabled(isCommunityConsole) {
isOptionEnabled('history').then(isEnabled => {
if (isEnabled) injectPreviousPostsLinksUnifiedProfile(isCommunityConsole);
});
}