Skip to content

Instantly share code, notes, and snippets.

@johan
Created October 16, 2016 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johan/28086781646888563aef69fcc7d30063 to your computer and use it in GitHub Desktop.
Save johan/28086781646888563aef69fcc7d30063 to your computer and use it in GitHub Desktop.
// ==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