blob: ca1633771ae62cd0794d4850724008d055e9483c [file] [log] [blame]
avm99963d0757252019-03-30 20:13:00 +01001chrome.storage.sync.get(null, function(items) {
avm99963b69eb3d2020-08-20 02:03:44 +02002 if (items.history &&
3 document.querySelector('.user-profile__user-links') === null) {
4 var nameElement = document.querySelector('.user-profile__user-name');
avm99963d0757252019-03-30 20:13:00 +01005 if (nameElement !== null) {
avm9996314116b02020-11-02 14:04:14 +01006 var name = escapeUsername(nameElement.textContent);
avm999630bd07f62020-09-01 20:18:06 +02007 var filter = 'creator:"' + name + '" | replier:"' + name + '"';
8 var url = document.location.pathname.split('/profile')[0] +
9 '/threads?thread_filter=' + encodeURIComponent(filter);
10
11 var links = document.createElement('div');
12 links.classList.add('user-profile__user-links');
13
14 var linkTitle = document.createElement('div');
15 linkTitle.classList.add('user-profile__user-link-title');
16 linkTitle.textContent = chrome.i18n.getMessage('inject_links');
17
18 links.appendChild(linkTitle);
19
20 var ul = document.createElement('ul');
21
22 var li = document.createElement('li');
23 li.classList.add('user-profile__user-link');
24
25 var a = document.createElement('a');
avm9996306167752020-09-08 00:50:36 +020026 a.classList.add('user-profile__user-link', 'TWPT-user-link');
avm999630bd07f62020-09-01 20:18:06 +020027 a.href = url;
28 a.setAttribute(
29 'data-stats-id', 'user-posts-link--tw-power-tools-by-avm99963');
avm999630bd07f62020-09-01 20:18:06 +020030
avm9996306167752020-09-08 00:50:36 +020031 var badge = document.createElement('span');
32 badge.classList.add('TWPT-badge');
33 badge.setAttribute(
34 'title', chrome.i18n.getMessage('inject_extension_badge_helper', [
35 chrome.i18n.getMessage('appName')
36 ]));
37
38 var badgeImg = document.createElement('img');
39 badgeImg.src =
40 'https://fonts.gstatic.com/s/i/materialicons/repeat/v6/24px.svg';
41
42 badge.appendChild(badgeImg);
43 a.appendChild(badge);
44
45 var span = document.createElement('span');
46 span.textContent = chrome.i18n.getMessage('inject_previousposts');
47
48 a.appendChild(span);
avm999630bd07f62020-09-01 20:18:06 +020049 li.appendChild(a);
50 ul.appendChild(li);
51 links.appendChild(ul);
52
53 console.log(links);
54
avm99963b69eb3d2020-08-20 02:03:44 +020055 document.querySelector('.user-profile__user-details-container')
avm999630bd07f62020-09-01 20:18:06 +020056 .appendChild(links);
avm99963d0757252019-03-30 20:13:00 +010057 }
58 }
59});