|
40 | 40 | } |
41 | 41 | }, |
42 | 42 |
|
43 | | - markEmployees: function () { |
44 | | - // Description: Adds the Stack Exchange logo next to users that *ARE* Stack Exchange employees |
45 | | - |
46 | | - const icon = sox.sprites.getSvg('se_logo'); |
47 | | - icon.classList.add('iconStackExchange', 'svg-icon', 'sox-markEmployees-logo'); |
48 | | - const logoSpan = document.createElement('span'); |
49 | | - logoSpan.className = 'sox-markEmployees'; |
50 | | - logoSpan.title = 'employee (added by SOX)'; |
51 | | - logoSpan.appendChild(icon); |
52 | | - |
53 | | - function getIds() { |
54 | | - const anchors = [...document.querySelectorAll('a.comment-user, .user-details a, .question-summary .started a')].filter(el => { |
55 | | - return ![...el.children].filter(el => el.classList.contains('sox-markEmployees')).length && el.href && el.href.match(/\/users\/\d+/); |
56 | | - }); |
57 | | - const ids = [...new Set(anchors.map(el => el.href.match(/(\d+)/)[0]))]; |
58 | | - sox.debug('markEmployees user IDs', ids); |
59 | | - |
60 | | - for (let i = 0; i < Math.ceil(ids.length / 100); i++) { |
61 | | - apiCall(i + 1, ids.slice(i * 100, (i * 100) + 100), anchors); |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - function apiCall(page, ids, anchors) { |
66 | | - sox.helpers.getFromAPI({ |
67 | | - endpoint: 'users', |
68 | | - ids, |
69 | | - sitename: sox.site.url, |
70 | | - filter: '!*MxJcsv91Tcz6yRH', |
71 | | - limit: 100, |
72 | | - page, |
73 | | - featureId: 'markEmployees', |
74 | | - cacheDuration: 60 * 24, // Cache for 24 hours (in minutes) |
75 | | - }, items => { |
76 | | - sox.debug('markEmployees returned data', items); |
77 | | - for (let i = 0; i < items.length; i++) { |
78 | | - if (!items[i].is_employee) continue; |
79 | | - const userId = items[i].user_id; |
80 | | - anchors.filter(el => el.href.contains(`/users/${userId}/`)).forEach(el => el.appendChild(logoSpan.cloneNode(true))); |
81 | | - } |
82 | | - }); |
83 | | - } |
84 | | - |
85 | | - getIds(); |
86 | | - window.addEventListener('sox-new-comment', getIds); |
87 | | - window.addEventListener('sox-new-review-post-appeared', getIds); |
88 | | - }, |
89 | | - |
90 | 43 | copyCommentsLink: function() { |
91 | 44 | // Description: Adds the 'show x more comments' link before the commnents |
92 | 45 | // Test on e.g. https://meta.stackexchange.com/questions/125439/ |
|
0 commit comments