Last active
December 29, 2021 19:27
-
-
Save gen3vra/92d4a80d7a0eec0b55a7e129ca1487a5 to your computer and use it in GitHub Desktop.
Adds a 'Clear All Visible' button under main notification title on Upwork. Clicking it clicks every close button on the page for you. Works 12/xx/2021
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 Upwork Clear All | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description why don't they have this already | |
// @author Gen | |
// @match https://www.upwork.com/ab/notifications/ | |
// @icon https://www.google.com/s2/favicons?domain=upwork.com | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
'use strict'; | |
var observer = new MutationObserver(function (mutations, me) { | |
try { | |
var canvas = document.getElementsByClassName("up-card-header"); | |
if (canvas.length > 0) { | |
InjectButton(); | |
me.disconnect(); | |
return; | |
} | |
} catch (ex) {console.log(ex);} | |
}); | |
observer.observe(document, { | |
childList: true, | |
subtree: true | |
}); | |
} | |
)(); | |
function InjectButton() { | |
console.log("Injecting clear all button in 500ms..."); | |
setTimeout(() => { | |
let header = document.getElementsByClassName("up-card-header")[0]; | |
let btn = document.createElement("button"); | |
btn.innerHTML = "Clear All Visible"; | |
btn.onclick = function () { | |
//Clear all notifs | |
let notifContainers = document.getElementsByClassName("notifications-list"); | |
console.log(notifContainers); | |
for (var i = 0; i < notifContainers.length; i++) { | |
console.log(notifContainers[i].childNodes); | |
for (var index = 0; index < notifContainers[i].childNodes.length; index++) { | |
console.log("Notif: " + notifContainers[i].childNodes[index]); | |
console.log("Checking if button exists"); | |
let elem = notifContainers[i].childNodes[index]; | |
let closeBtn = elem.getElementsByClassName("up-btn-link")[0]; | |
closeBtn.click(); | |
} | |
} | |
}; | |
header.appendChild(btn); | |
}, 500); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment