Repository navigation
Expand file tree
/
Copy pathnotification.ts
More file actions
73 lines (65 loc) · 2.43 KB
/
Copy pathnotification.ts
File metadata and controls
73 lines (65 loc) · 2.43 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
* @file github1s notification
* @author netcon
*/
import 'vs/css!./notification';
const NOTIFICATION_STORAGE_KEY = 'GITHUB1S_NOTIFICATION';
// Change this if a new notification should be shown
const NOTIFICATION_STORAGE_VALUE = '20210212';
const getGitpodRepoUrl = () => window.location.pathname.match(/^\/[^\/]+\/[^\/]+/) ? `https://gitpod.io/#https://github.com${window.location.pathname.match(/^\/[^\/]+\/[^\/]+/)![0]}` : '';
const notifications = [{
title: 'ATTENTION: This page is NOT officially provided by GitHub.',
content:
'GitHub1s is an open source project, which is not officially provided by GitHub.',
link: 'https://github.com/conwnet/github1s',
}, {
title: `<a class="notification-link" href="${getGitpodRepoUrl()}" alt="Gitpod ready-to-code" target="_blank"><img src="https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod"></a>`,
content:
'Click the button above to develop your project in the cloud.',
}];
const notificationHtml = `${
notifications.map(notification => (`
<div class="notification-main">
<div class="notification-title">${notification.title}</div>
<div class="notification-content">
${notification.content}
${notification.link ? `<a class="notification-link" href="${notification.link}" target="_blank">See more</a>` : ''}
</div>
</div>`
))
}
<div class="notification-footer">
<button class="notification-confirm-button">OK</button>
<div class="notification-show-me-again">
<input type="checkbox" checked>Don't show me again</div>
</div>
</div>
`;
export const renderNotification = () => {
// If user has confirmed the notification and checked `don't show me again`, ignore it
if (
!window.localStorage ||
window.localStorage.getItem(NOTIFICATION_STORAGE_KEY) ===
NOTIFICATION_STORAGE_VALUE
) {
return;
}
const notificationElement = <HTMLDivElement>document.createElement('div');
notificationElement.classList.add('github1s-notification');
notificationElement.innerHTML = notificationHtml;
document.body.appendChild(notificationElement);
(<HTMLButtonElement>(
notificationElement.querySelector('.notification-confirm-button')
))!.onclick = () => {
const notShowMeAgain = !!(<HTMLInputElement>(
notificationElement.querySelector('.notification-show-me-again input')
))!.checked;
if (notShowMeAgain) {
window.localStorage.setItem(
NOTIFICATION_STORAGE_KEY,
NOTIFICATION_STORAGE_VALUE
);
}
document.body.removeChild(notificationElement);
};
};