Advertisement
Guest User

jaa pierdolę

a guest
Apr 8th, 2020
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Notification.requestPermission();
  2. const strip = (html) => {
  3.     let doc = new DOMParser().parseFromString(html.replace(/<br>/gi, '\n'), 'text/html');
  4.     return doc.body.textContent || "";
  5. }
  6.  
  7. let thisTab = 0, active=1;
  8. let bc = new BroadcastChannel('superjavascript');
  9. bc.onmessage = ev => {
  10.     if (ev.data == "new tab") thisTab++;
  11.     else if (parseInt(ev.data) < thisTab) active = 0;
  12.     console.log("otrzymane dane: "+ev.data);
  13. }
  14. bc.postMessage('new tab');
  15.  
  16. const powiadomienie = (data) => {
  17.     console.log("ta karta: "+thisTab)
  18.     if ((document.hasFocus() && (window.location.href.includes(data.threadId) || !/\d/.test(window.location.href))) || typeof curbs[data.boardId][data.threadId] !== "undefined") {
  19.         bc.postMessage("-1");
  20.         active = 0;
  21.     } else bc.postMessage(thisTab);
  22.     setTimeout(() => {
  23.         if (active) {
  24.             const img = typeof data.file !== "undefined" ? `https://wilchan.org/boards/${data.boardId}/thumb/${data.fileThumbName}` : "";
  25.             const text = strip(data.message);
  26.             let notification = new Notification('Kliknij, aby przejść do tematu', { body: text, image: img });
  27.             console.log('to tutaj wysłano');
  28.             notification.onclick = (event) => {
  29.                 event.preventDefault();
  30.                 const win = window.open(`https://wilchan.org/${data.boardId}/thread/${data.threadId}#${data.postId}`, '_blank');
  31.                 win.focus();
  32.             }
  33.         }
  34.         active = 1;
  35.     }, 200)
  36. }
  37.  
  38. sseCreateFunctionArray.push(powiadomienie);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement