This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
102 lines (88 loc) · 4.09 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Sejm API - IX kadencja (lista posłów) = https://api.sejm.gov.pl/sejm/term9/MP
var CURRENT_POST_COUNT = 0;
var SEJM_POLITICIANS = [];
var HANDLES_TO_NAMES;
fetchJSON('data/parliament_polish_mps.json').then(p => {
SEJM_POLITICIANS = p;
});
fetchJSON('data/handle_to_name.json').then(htn => {
HANDLES_TO_NAMES = htn;
});
const hideElement = (elem) => {
elem.css('display', 'none');
};
const main = () => {
let posts = $('.r-kzbkwu'); // load all elements with Twitter post class
if (posts.length < 1) setTimeout(main, 500);
else if (posts.length == CURRENT_POST_COUNT) return;
else {
CURRENT_POST_COUNT = posts.length;
posts.each(function() {
if (!$(this).hasClass('searched')) {
let handle = $(this).find('a > div > span.r-poiln3').text(); // find a @tag of Twitter post's author
if (HANDLES_TO_NAMES.hasOwnProperty(handle)) { // if this person exists in JSON
let person;
for (person of SEJM_POLITICIANS) {
if (person.firstLastName.toLowerCase() == HANDLES_TO_NAMES[handle].toLowerCase()) break;
}
let elem = $(`
<div>
<span
class='person-info'
title='${
(person.firstLastName) + '\n'
+ 'okręg wyborczy - ' + (person.districtName) + ' (nr ' + (person.discritNum) + ')\n'
+ 'aktywn' + (person.firstName[person.firstName.length-1] === 'a' ? 'a' : 'y') + ' w polityce - ' + (person.active ? 'tak' : 'nie') + '\n' // if true then 'tak' else 'nie'
+ 'email - ' + (person.email) + ' (kliknij aby skopiować)'
}'
>
ⓘ Człon${ (person.firstName[person.firstName.length-1] === 'a' ? 'kini' : 'ek') } klubu ${ person.club }
</span>
</div>
`).css({
'color': 'rgb(109, 114, 119)',
'font-family': '\'Segoe UI\', system-ui, sans-serif',
'margin-bottom': '5px',
'font-weight': '550',
});
let onClickElem = $(`
<div id='popup'>
<span>
Email został skopiowany do schowka.
</span>
</div>
`).css({
'background': '#1d9bf0',
'color': 'white',
'font-family': '\'Segoe UI\', system-ui, sans-serif',
'font-weight': 'bold',
'border-radius': '50px',
'text-align': 'center',
'width': '300px',
'padding': '15px',
'position': 'fixed',
'top': 'calc(100vh - 70px)',
'left': 'calc(50% - 150px)',
'display': 'none',
});
$('body').append(onClickElem);
$('.person-info').click(function (elem) {
navigator.clipboard.writeText(person.email); // copy email to clipboard on click
$('#popup').css('display', 'block');
setTimeout(hideElement, 2000, $('#popup'));
elem.stopPropagation(); // remove other onclick functionalities
});
$(this).addClass('searched');
$(this).children(':last-child').before(elem);
}
}
});
}
}
document.addEventListener('scroll', main);
if (document.readyState === 'complete') main();
else {
document.onreadystatechange = function () {
if (document.readyState == 'complete') main();
}
}