blob: c7b04b18149442ba6d1621e30a04ca55b00c90c0 [file] [log] [blame]
avm99963104bad32021-02-05 22:00:44 +01001var authuser = (new URL(location.href)).searchParams.get('authuser') || '0';
2
avm99963d0757252019-03-30 20:13:00 +01003chrome.storage.sync.get(null, function(items) {
avm99963b69eb3d2020-08-20 02:03:44 +02004 if (items.history &&
5 document.querySelector('.user-profile__user-links') === null) {
6 var nameElement = document.querySelector('.user-profile__user-name');
avm99963d0757252019-03-30 20:13:00 +01007 if (nameElement !== null) {
avm99963104bad32021-02-05 22:00:44 +01008 var profileLink = document.querySelector('.community-console');
9 if (profileLink === null) {
10 console.error(
11 '[previousposts] ' +
12 'The user is not a PE so we can\'t show the previous posts link.');
13 return;
14 }
15
16 var profileUrl = profileLink.href || '';
17 var profileUrlSplit = profileUrl.split('/forum/');
18 if (profileUrlSplit.length < 2) {
19 console.error('[previousposts] Can\'t get forum id.');
20 return;
21 }
22
23 var forumId = profileUrlSplit[1].split('/')[0];
avm9996314116b02020-11-02 14:04:14 +010024 var name = escapeUsername(nameElement.textContent);
avm99963104bad32021-02-05 22:00:44 +010025 var filter =
26 '(creator:"' + name + '" | replier:"' + name + '") forum:' + forumId;
27 var urlpart = encodeURIComponent('query=' + encodeURIComponent(filter));
28 var authuserpart =
29 (authuser == '0' ? '' : '?authuser=' + encodeURIComponent(authuser));
30 var url = 'https://support.google.com/s/community/search/' + urlpart +
31 authuserpart;
avm999630bd07f62020-09-01 20:18:06 +020032
33 var links = document.createElement('div');
34 links.classList.add('user-profile__user-links');
35
36 var linkTitle = document.createElement('div');
37 linkTitle.classList.add('user-profile__user-link-title');
38 linkTitle.textContent = chrome.i18n.getMessage('inject_links');
39
40 links.appendChild(linkTitle);
41
42 var ul = document.createElement('ul');
43
44 var li = document.createElement('li');
45 li.classList.add('user-profile__user-link');
46
47 var a = document.createElement('a');
avm9996306167752020-09-08 00:50:36 +020048 a.classList.add('user-profile__user-link', 'TWPT-user-link');
avm999630bd07f62020-09-01 20:18:06 +020049 a.href = url;
50 a.setAttribute(
51 'data-stats-id', 'user-posts-link--tw-power-tools-by-avm99963');
avm999630bd07f62020-09-01 20:18:06 +020052
avm9996306167752020-09-08 00:50:36 +020053 var badge = document.createElement('span');
54 badge.classList.add('TWPT-badge');
55 badge.setAttribute(
56 'title', chrome.i18n.getMessage('inject_extension_badge_helper', [
57 chrome.i18n.getMessage('appName')
58 ]));
59
60 var badgeImg = document.createElement('img');
61 badgeImg.src =
62 'https://fonts.gstatic.com/s/i/materialicons/repeat/v6/24px.svg';
63
64 badge.appendChild(badgeImg);
65 a.appendChild(badge);
66
67 var span = document.createElement('span');
68 span.textContent = chrome.i18n.getMessage('inject_previousposts');
69
70 a.appendChild(span);
avm999630bd07f62020-09-01 20:18:06 +020071 li.appendChild(a);
72 ul.appendChild(li);
73 links.appendChild(ul);
74
avm99963b69eb3d2020-08-20 02:03:44 +020075 document.querySelector('.user-profile__user-details-container')
avm999630bd07f62020-09-01 20:18:06 +020076 .appendChild(links);
avm99963104bad32021-02-05 22:00:44 +010077 } else {
78 console.error('[previousposts] Can\'t find username.');
avm99963d0757252019-03-30 20:13:00 +010079 }
80 }
81});