Last active
June 11, 2020 19:10
-
-
Save double-beep/031cd2b2afe2ebcb98d1cf361b3fa4b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Review Queue Notifier | |
| // @namespace stackexchange.com | |
| // @version 0.1 | |
| // @description Notifies you with a desktop-notification of any reviews on any sites where you have review privileges on | |
| // @author Daniil | |
| // @include /^https://stackexchange.com/users/\d+/ | |
| // @grant GM_xmlhttpRequest | |
| // @connect * | |
| // ==/UserScript== | |
| (async function() { | |
| 'use strict'; | |
| const userid = window.location.href.split('/')[4]; | |
| const API_KEY = 'BsS8W0LXZaGo9s8qNRRrvg(('; | |
| const filter = '!*LB1tiXePck5wP0y'; | |
| Notification.requestPermission(); | |
| async function notifyMe(queue, site, sitename) { | |
| if (!("Notification" in window)) alert("This browser does not support desktop notification"); | |
| else if (Notification.permission === "granted") { | |
| var notification = new Notification(queue + ' on ' + sitename, { | |
| body: 'Click to go there!', | |
| icon: site + '/favicon.ico' | |
| }); | |
| notification.onclick = function(event) { | |
| event.preventDefault(); // prevent the browser from focusing the Notification's tab | |
| window.open(site + '/review', '_blank'); | |
| }; | |
| } | |
| else if (Notification.permission !== "denied") Notification.requestPermission(); | |
| await new Promise(x => setTimeout(x, 5000)); | |
| } | |
| var sites = [], sitenames = []; | |
| for (var i = 1; i < 3; i++) { | |
| const url = `https://api.stackexchange.com/2.2/users/${userid}/associated?filter=${filter}&key=${API_KEY}&pagesize=100&page=${i}`; | |
| const resp = await fetch(url); | |
| const items = await resp.json(); | |
| const data = items.items.filter(x => x.reputation >= 350); | |
| data.forEach(v => { | |
| sites.push(v.site_url); | |
| sitenames.push(v.site_name); | |
| }); | |
| } | |
| var queues = {}; | |
| async function loop() { | |
| for (let i = 0; i < sites.length; i++) { | |
| const site = sites[i]; | |
| const sitename = sitenames[i]; | |
| queues = []; | |
| GM_xmlhttpRequest({ | |
| method: 'GET', | |
| url: site + '/topbar/review', | |
| onload: async function(res) { | |
| const parsedHTML = new DOMParser().parseFromString(res.response, 'text/html'); | |
| [...parsedHTML.querySelectorAll('.-item .v-visible-sr')].forEach(v => queues.push(v.previousElementSibling.innerHTML)); | |
| if (queues.length) await notifyMe(queues.join(','), site, sitename); | |
| } | |
| }); | |
| } | |
| await new Promise(x => setTimeout(x, 300000)); | |
| loop(); | |
| } | |
| loop(); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment