-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-notification-fixer.user.js
92 lines (80 loc) · 3.41 KB
/
github-notification-fixer.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
// ==UserScript==
// @name GitHub Notification Fixer
// @namespace http://javascript.about.com
// @version 0.1
// @include https://github.com/notifications*
// @grant none
// @run-at document-start
// ==/UserScript==
// replaces the DONE action with a MARK AS READ action
function gh_replaceDoneWithMarkAsRead()
{
console.log("Replacing single...");
let elements = document.querySelectorAll('form[data-status="archived"][action="/notifications/beta/archive"]');
//console.log("Found elements:", elements);
elements.forEach((element) => {
element.setAttribute("data-status", "read");
element.setAttribute("action", "/notifications/beta/mark");
// replace auth token to make the mark as read request work (every form has its own dedicated auth token)
let token = document.querySelector('.js-notifications-mark-selected-actions details-menu form[data-status="read"] input').value;
element.querySelector('input[name="authenticity_token"').value = token;
element.querySelectorAll("button").forEach((btn) => {
btn.setAttribute("title", "Mark as read");
btn.setAttribute("style", "color: red"); // verify the action was replaced
});
});
}
function gh_replaceGroupDoneWithMarkAsRead()
{
console.log("Replacing groups...");
let elements = document.querySelectorAll('.js-grouped-notifications-mark-all-read-button[action="/notifications/beta/archive"]');
//console.log("Found elements:", elements);
elements.forEach((element) => {
element.setAttribute("action", "/notifications/beta/mark");
// replace auth token to make the mark as read request work (every form has its own dedicated auth token)
let token = document.querySelector('.js-notifications-mark-selected-actions details-menu form[data-status="read"] input').value;
element.querySelector('input[name="authenticity_token"').value = token;
element.querySelectorAll("button").forEach((btn) => {
//btn.setAttribute("title", "Mark all as read");
btn.setAttribute("style", "color: red"); // verify the action was replaced
});
});
}
function gh_removeNotificationTrackingLinks()
{
console.log("Removing tracking links...");
let links = document.querySelectorAll(".Box-body a.js-navigation-open.notification-list-item-link");
links.forEach((link) => {
let href = link.getAttribute("href");
let queryPos = href.indexOf("?");
if (queryPos === -1)
{
return;
}
link.setAttribute("href", href.substring(0, queryPos));
});
}
function gh_addRepoLinkToGroup()
{
console.log("Adding repository link to headers...");
let elements = document.querySelectorAll(".Box-header h6");
elements.forEach((element) => {
let text = element.innerHTML.trim();
element.outerHTML = '<a style="color: black; width: 100%; font-weight: bold" href="/' + text + '">' + text + '</a>';
});
}
function gh_script_eventloop() {
setTimeout(function () {
gh_replaceDoneWithMarkAsRead();
gh_replaceGroupDoneWithMarkAsRead();
gh_addRepoLinkToGroup();
gh_removeNotificationTrackingLinks();
gh_script_eventloop();
}, 10000);
}
// start script
gh_replaceDoneWithMarkAsRead();
gh_replaceGroupDoneWithMarkAsRead();
gh_addRepoLinkToGroup();
gh_removeNotificationTrackingLinks();
gh_script_eventloop();