Created
October 16, 2016 00:03
-
-
Save johan/28086781646888563aef69fcc7d30063 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Clear Facebook Notifications Once | |
// @description If you have multiple Facebook tabs open | |
// @match https://*.facebook.com/* | |
// @namespace https://github.com/johan/ | |
// ==/UserScript== | |
const onStorageChange, onNotificationClick; | |
window.addEventListener('storage', onStorageChange = (e) => { | |
if (e.key !== 'clearNotification') return; | |
let v = e.newValue; | |
let n = document.querySelector(`.jewelItemNew[data-alert-id="${v}"]`); | |
if (n) n.classList.remove('jewelItemNew'); | |
console.log(n ? 'Cleared notification' : 'Missing notification', v); | |
}); | |
document.addEventListener('click', onNotificationClick = (e) => { | |
let {target} = e; | |
let id; | |
while (target) { | |
if ((id = target.dataset.alertId)) { | |
localStorage.clearNotification = id; | |
console.log('broadcast clearNotification', id); | |
break; | |
} | |
target = target.parentNode; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment