CC: Split the profile history link into 2 links
Before there was a single link which pointed to the post history in all
forums. As this sometimes takes a long time to load, this commit splits
it into 2 links:
* A link to the post history in the current forum (loads faster)
* A link to the post history in all forums (loads slower)
Change-Id: Ifa3ed2340c5af2e87d75118eb6a66aba4f395e3c
diff --git a/src/content_scripts/console_inject.js b/src/content_scripts/console_inject.js
index eda9960..14556b8 100644
--- a/src/content_scripts/console_inject.js
+++ b/src/content_scripts/console_inject.js
@@ -14,6 +14,20 @@
};
}
+function addProfileHistoryLink(node, type, query) {
+ var urlpart = encodeURIComponent('query=' + query);
+ var container = document.createElement('div');
+ container.style.margin = '3px 0';
+
+ var link = document.createElement('a');
+ link.setAttribute(
+ 'href', 'https://support.google.com/s/community/search/' + urlpart);
+ link.innerText = chrome.i18n.getMessage('inject_previousposts_' + type);
+
+ container.appendChild(link);
+ node.querySelector('.main-card-content').appendChild(container);
+}
+
function mutationCallback(mutationList, observer) {
mutationList.forEach((mutation) => {
if (mutation.type == 'childList') {
@@ -34,18 +48,16 @@
node.parentNode.tagName == 'EC-USER') {
var nameElement = node.querySelector('.name span');
if (nameElement !== null) {
- var name = nameElement.innerHTML;
- var query = encodeURIComponent(
- '(creator:"' + name + '" | replier:"' + name + '") -forum:0');
- var urlpart = encodeURIComponent('query=' + query);
- var link = document.createElement('a');
- link.setAttribute(
- 'href',
- 'https://support.google.com/s/community/search/' + urlpart);
- link.innerText = chrome.i18n.getMessage('inject_previousposts');
- node.querySelector('.main-card-content')
- .appendChild(document.createElement('br'));
- node.querySelector('.main-card-content').appendChild(link);
+ var forumId =
+ location.href.split('/forum/')[1].split('/')[0] || '0';
+
+ var name = escapeUsername(nameElement.innerHTML);
+ var query1 = encodeURIComponent(
+ '(creator:"' + name + '" | replier:"' + name + '") forum:'+forumId);
+ var query2 = encodeURIComponent(
+ '(creator:"' + name + '" | replier:"' + name + '") forum:any');
+ addProfileHistoryLink(node, 'forum', query1);
+ addProfileHistoryLink(node, 'all', query2);
}
}
}