Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Notification.requestPermission();
- const strip = (html) => {
- let doc = new DOMParser().parseFromString(html.replace(/<br>/gi, '\n'), 'text/html');
- return doc.body.textContent || "";
- }
- let thisTab = 0, active=1;
- let bc = new BroadcastChannel('superjavascript');
- bc.onmessage = ev => {
- if (ev.data == "new tab") thisTab++;
- else if (parseInt(ev.data) < thisTab) active = 0;
- console.log("otrzymane dane: "+ev.data);
- }
- bc.postMessage('new tab');
- const powiadomienie = (data) => {
- console.log("ta karta: "+thisTab)
- if ((document.hasFocus() && (window.location.href.includes(data.threadId) || !/\d/.test(window.location.href))) || typeof curbs[data.boardId][data.threadId] !== "undefined") {
- bc.postMessage("-1");
- active = 0;
- } else bc.postMessage(thisTab);
- setTimeout(() => {
- if (active) {
- const img = typeof data.file !== "undefined" ? `https://wilchan.org/boards/${data.boardId}/thumb/${data.fileThumbName}` : "";
- const text = strip(data.message);
- let notification = new Notification('Kliknij, aby przejść do tematu', { body: text, image: img });
- console.log('to tutaj wysłano');
- notification.onclick = (event) => {
- event.preventDefault();
- const win = window.open(`https://wilchan.org/${data.boardId}/thread/${data.threadId}#${data.postId}`, '_blank');
- win.focus();
- }
- }
- active = 1;
- }, 200)
- }
- sseCreateFunctionArray.push(powiadomienie);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement