-
Notifications
You must be signed in to change notification settings - Fork 0
/
meetup-friends.user.js
107 lines (87 loc) · 2.38 KB
/
meetup-friends.user.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
103
104
105
106
107
// ==UserScript==
// @name Meetup-friends
// @namespace valdun.net
// @description Manage a friend list on meetup.com
// @include http://www.meetup.com/*/events/*
// @include https://www.meetup.com/*/events/*
// @version 1.1
// @grant none
// @require http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==
/* eslint-env greasemonkey, jquery */
this.$ = this.jQuery = jQuery.noConflict(true);
const friends = [
// 123456789, // ID of a friend
];
const colors = {
list: '#0fd9a3',
waitlist: '#353e48',
no: '#ed1c40',
};
const displaySections = getDisplaySections();
displayWaitPosition();
displayWaitLength();
displayFriends();
autoUpdate();
/** **************************************************************************
* Functions
*/
function autoUpdate() {
$('.nav-appendPager').click(() => {
window.setTimeout(() => {
displayFriends();
}, 1000);
});
}
function displayFriends() {
Object.values(displaySections).forEach(($list) => {
$list.empty().show();
});
friends.forEach((id) => {
const $friend = $(`#rsvp_${id}`);
if (!$friend.length) {
return;
}
const friendStatus = $friend.parent().attr('id').replace(/.*-/, '');
$friend.clone().appendTo(displaySections[`$${friendStatus}`]);
$friend.css({
'background-color': colors.list,
'box-shadow': `10px 0 0 0 ${colors.list}, -10px 0 0 0 ${colors.list}`,
});
});
Object.values(displaySections).forEach(($list) => {
if (!$list.children().length) {
$list.hide();
}
});
}
function displayWaitLength() {
const waitLength = $('#rsvp-list-waitlist li').length;
$('.event-attendees h3')
.after(`<h4>${waitLength} waiting</h4>`);
}
function displayWaitPosition() {
$('#rsvp-list-waitlist li').each((i) => {
$('h5', this).prepend(`#${i + 1} - `);
});
}
function get$firstAttendee() {
let $attendee = $('#rsvp-list').children().first();
if (!$attendee.hasClass('memberinfo-widget')) {
$attendee = $attendee.next();
}
return $attendee;
}
function getDisplaySections() {
const $firstAttendee = get$firstAttendee();
const sections = {};
for (let status in colors) {
sections[`$${status}`] = $('<div/>')
.css({
'box-shadow': `0 0 0 10px ${colors[status]}`,
'margin-bottom': '20px',
})
.insertBefore($firstAttendee);
}
return sections;
}