Improved profile_inject.js code
Change-Id: I5d154b987fe90f2f8e6c89f374c6f37f9986acc1
diff --git a/src/content_scripts/profile_inject.js b/src/content_scripts/profile_inject.js
index a84eba3..2ad5002 100644
--- a/src/content_scripts/profile_inject.js
+++ b/src/content_scripts/profile_inject.js
@@ -3,19 +3,40 @@
document.querySelector('.user-profile__user-links') === null) {
var nameElement = document.querySelector('.user-profile__user-name');
if (nameElement !== null) {
- var name = encodeURIComponent(nameElement.innerHTML);
- var link = document.location.pathname.split('/profile')[0] +
- '/threads?thread_filter=(creator:%22' + name + '%22+%7C+replier:%22' +
- name + '%22)';
+ var name = escapeUsername(nameElement.innerHTML);
+ var filter = 'creator:"' + name + '" | replier:"' + name + '"';
+ var url = document.location.pathname.split('/profile')[0] +
+ '/threads?thread_filter=' + encodeURIComponent(filter);
+
+ var links = document.createElement('div');
+ links.classList.add('user-profile__user-links');
+
+ var linkTitle = document.createElement('div');
+ linkTitle.classList.add('user-profile__user-link-title');
+ linkTitle.textContent = chrome.i18n.getMessage('inject_links');
+
+ links.appendChild(linkTitle);
+
+ var ul = document.createElement('ul');
+
+ var li = document.createElement('li');
+ li.classList.add('user-profile__user-link');
+
+ var a = document.createElement('a');
+ a.classList.add('user-profile__user-link');
+ a.href = url;
+ a.setAttribute(
+ 'data-stats-id', 'user-posts-link--tw-power-tools-by-avm99963');
+ a.textContent = chrome.i18n.getMessage('inject_previousposts');
+
+ li.appendChild(a);
+ ul.appendChild(li);
+ links.appendChild(ul);
+
+ console.log(links);
+
document.querySelector('.user-profile__user-details-container')
- .insertAdjacentHTML(
- 'beforeend',
- '<div class="user-profile__user-links"><div class="user-profile__user-link-title">' +
- chrome.i18n.getMessage('inject_links') +
- '</div><ul><li class="user-profile__user-link"><a href="' +
- link + '" data-stats-id="my-posts-link">' +
- chrome.i18n.getMessage('inject_previousposts') +
- '</a></li></ul></div>');
+ .appendChild(links);
}
}
});
diff --git a/templates/manifest.gjson b/templates/manifest.gjson
index 60c3feb..97deaba 100644
--- a/templates/manifest.gjson
+++ b/templates/manifest.gjson
@@ -35,7 +35,7 @@
},
{
"matches": ["https://support.google.com/*/profile/*"],
- "js": ["content_scripts/profile_inject.js"]
+ "js": ["common/content_scripts.js", "content_scripts/profile_inject.js"]
}
],
"permissions": [