patternjavascriptMinorCanonical
Desktop notifications for queue items
Viewed 0 times
desktopnotificationsitemsforqueue
Problem
I wasn't satisfied with Simon's alert on the orange alert. I wanted to know if even 1 review item was available, so I made some modifications to the userscript so that it runs on the Review page, and only alerts you when there are reviews that show a positive number.
This is Simon's version, and here is my version:
This is also available on my GitHub as a userscript.
Follow-up question with new GitHub repo
This is Simon's version, and here is my version:
/** @preserve
// ==UserScript==
// @name Review Queue Notification
// @author Malachi Edited Simon Forsberg Created
// @description Shows a desktop notification when there review items in the queue.
// @namespace https://github.com/Zomis/SE-Scripts
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_notification
// @match *://*.stackexchange.com/review*
// @match *://*.stackoverflow.com/review*
// @match *://*.superuser.com/review*
// @match *://*.serverfault.com/review*
// @match *://*.askubuntu.com/review*
// @match *://*.stackapps.com/review*
// @match *://*.mathoverflow.net/review*
// ==/UserScript==
*/
var KEY_NEXT = 'NextReload';
var DELAY = 60 * 1000; //60,000 milliseconds
var currentTime = Date.now ? Date.now() : new Date().getTime();
var lastTime = GM_getValue(KEY_NEXT, 0);
var nextTime = currentTime + DELAY;
GM_setValue(KEY_NEXT, nextTime);
var timeDiff = Math.abs(lastTime - currentTime);
setTimeout(function(){
window.location.reload();
}, DELAY);
var title = document.title.split(' - '); // keep the site name
document.title = 'Desktop Notifications - ' + title[1];
// a way to detect that the script is being executed because of an automatic script reload, not by the user.
if (timeDiff 0) {
notifications.push(reviewCount + ' Review Items');
}
if (notifications.length) {
var details = {
title: document.title,
text: notifications.join('\n'),
timeout: 0
};
GM_notification(details, null);
}
}This is also available on my GitHub as a userscript.
Follow-up question with new GitHub repo
Solution
This is mostly personal preference, but, I usually stack the
into:
Just looks nicer, I suppose.
You don't use
You could consider replacing the
I can't see the point in using
or even just move
As of ECMAScript 5, the default radix used in
@matches in descending size:// @match *://*.stackexchange.com/review*
// @match *://*.stackoverflow.com/review*
// @match *://*.superuser.com/review*
// @match *://*.serverfault.com/review*
// @match *://*.askubuntu.com/review*
// @match *://*.stackapps.com/review*
// @match *://*.mathoverflow.net/review*into:
// @match *://*.stackexchange.com/review*
// @match *://*.stackoverflow.com/review*
// @match *://*.mathoverflow.net/review*
// @match *://*.serverfault.com/review*
// @match *://*.askubuntu.com/review*
// @match *://*.stackapps.com/review*
// @match *://*.superuser.com/review*Just looks nicer, I suppose.
var title = document.title.split(' - ');:You don't use
title for anything other than title[1], so just use var title = document.title.split(' - ')[1] instead..replace(',',''): You should have a space after ','.You could consider replacing the
.length style for loop with a for (var i in reviewItems) style loop. If not, you can also declare reviewCount in the for loop like: for (var reviewCount = 0, i = 0;.var details = {
title: document.title,Desktop Notifications - Code Review Stack Exchange sounds a little bulky and over-the-top. Review Items is a better name for it, and you could consider removing Stack Exchange, but, consider the effect that would have on MSE.I can't see the point in using
notifications as an array, as it should really just have the one notification.if (reviewCount > 0) {
notifications.push(reviewCount + ' Review Items');
}
if (notifications.length) {
var details = {
text: notifications.join('\n'),if (reviewCount > 0) {
notification = reviewCount + ' Review Items';
}
if (notification) {
var details = {
text: notification,or even just move
reviewCount + ' Review Items' into details, like:if (reviewCount > 0) {
var details = {
text: reviewCount + ' Review Items',As of ECMAScript 5, the default radix used in
parseInt is supposed to be \$10\$, before that, \$0\$ would get parsed as a octal number instead of a decimal number, and, as it seems, you can just omit that optional radix argument entirely. Although, as @EthanBierlein pointed out in the comments; MDN recommends not to omit it.Code Snippets
// @match *://*.stackexchange.com/review*
// @match *://*.stackoverflow.com/review*
// @match *://*.superuser.com/review*
// @match *://*.serverfault.com/review*
// @match *://*.askubuntu.com/review*
// @match *://*.stackapps.com/review*
// @match *://*.mathoverflow.net/review*// @match *://*.stackexchange.com/review*
// @match *://*.stackoverflow.com/review*
// @match *://*.mathoverflow.net/review*
// @match *://*.serverfault.com/review*
// @match *://*.askubuntu.com/review*
// @match *://*.stackapps.com/review*
// @match *://*.superuser.com/review*var details = {
title: document.title,if (reviewCount > 0) {
notifications.push(reviewCount + ' Review Items');
}
if (notifications.length) {
var details = {
text: notifications.join('\n'),if (reviewCount > 0) {
notification = reviewCount + ' Review Items';
}
if (notification) {
var details = {
text: notification,Context
StackExchange Code Review Q#98619, answer score: 7
Revisions (0)
No revisions yet.