avm99963 | d075725 | 2019-03-30 20:13:00 +0100 | [diff] [blame] | 1 | chrome.storage.sync.get(null, function(items) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 2 | if (items.history && |
| 3 | document.querySelector('.user-profile__user-links') === null) { |
| 4 | var nameElement = document.querySelector('.user-profile__user-name'); |
avm99963 | d075725 | 2019-03-30 20:13:00 +0100 | [diff] [blame] | 5 | if (nameElement !== null) { |
avm99963 | 0bd07f6 | 2020-09-01 20:18:06 +0200 | [diff] [blame] | 6 | var name = escapeUsername(nameElement.innerHTML); |
| 7 | 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'); |
avm99963 | 0616775 | 2020-09-08 00:50:36 +0200 | [diff] [blame] | 26 | a.classList.add('user-profile__user-link', 'TWPT-user-link'); |
avm99963 | 0bd07f6 | 2020-09-01 20:18:06 +0200 | [diff] [blame] | 27 | a.href = url; |
| 28 | a.setAttribute( |
| 29 | 'data-stats-id', 'user-posts-link--tw-power-tools-by-avm99963'); |
avm99963 | 0bd07f6 | 2020-09-01 20:18:06 +0200 | [diff] [blame] | 30 | |
avm99963 | 0616775 | 2020-09-08 00:50:36 +0200 | [diff] [blame] | 31 | 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); |
avm99963 | 0bd07f6 | 2020-09-01 20:18:06 +0200 | [diff] [blame] | 49 | li.appendChild(a); |
| 50 | ul.appendChild(li); |
| 51 | links.appendChild(ul); |
| 52 | |
| 53 | console.log(links); |
| 54 | |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 55 | document.querySelector('.user-profile__user-details-container') |
avm99963 | 0bd07f6 | 2020-09-01 20:18:06 +0200 | [diff] [blame] | 56 | .appendChild(links); |
avm99963 | d075725 | 2019-03-30 20:13:00 +0100 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | }); |