This repository was archived by the owner on Jun 21, 2023. It is now read-only.
forked from refined-github/refined-github
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathopen-all-notifications.js
More file actions
59 lines (49 loc) · 1.75 KB
/
open-all-notifications.js
File metadata and controls
59 lines (49 loc) · 1.75 KB
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
import select from 'select-dom';
import {h} from 'dom-chef';
import {isNotifications} from '../libs/page-detect';
function openNotifications() {
const urls = select.all('.js-notification-target').map(el => el.href);
browser.runtime.sendMessage({
urls,
action: 'openAllInTabs'
});
for (const listItem of select.all('.list-group .list-group-item')) {
listItem.classList.add('read');
}
}
export default function () {
if (!isNotifications()) {
return;
}
const unreadCount = select.all('.js-notification-target').length;
if (unreadCount === 0) {
return;
}
const openButton = <a href="#open_all_in_tabs" class="btn btn-sm BtnGroup-item">Open all in tabs</a>;
// Make a button group
const markAsReadButton = select('[href="#mark_as_read_confirm_box"]');
markAsReadButton.parentNode.classList.add('BtnGroup');
markAsReadButton.classList.add('BtnGroup-item');
markAsReadButton.before(openButton);
// Move out the extra node that messes with .BtnGroup-item:last-child
document.body.append(select('#mark_as_read_confirm_box'));
if (unreadCount < 10) {
openButton.addEventListener('click', openNotifications);
} else {
// Add confirmation modal
openButton.setAttribute('rel', 'facebox');
document.body.append(
<div id="open_all_in_tabs" style={{display: 'none'}}>
<h2 class="facebox-header" data-facebox-id="facebox-header">Are you sure?</h2>
<p data-facebox-id="facebox-description">Are you sure you want to open {unreadCount} tabs?</p>
<div class="full-button">
<button class="btn btn-block" id="open-all-notifications">Open all notifications</button>
</div>
</div>
);
$(document).on('click', '#open-all-notifications', () => {
openNotifications();
select('.js-facebox-close').click(); // Close modal
});
}
}