Last active
October 2, 2015 20:51
-
-
Save mogsdad/50c5a3e9686cf0a8867f to your computer and use it in GitHub Desktop.
When on a Stack Exchange network review tab, periodically checks whether there is a review available.
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 Load review | |
// @namespace https://gist.github.com/mogsdad/50c5a3e9686cf0a8867f | |
// @version 1.2 | |
// @description When on a Stack Exchange network review tab, periodically checks whether there is a review available. | |
// @author David Bingham (Mogsdad) | |
// @include /^https?://(meta\.)?(stackoverflow|stackexchange|serverfault|superuser|askubuntu|stackapps)\.com/review/*/ | |
// @grant none | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
var debugging = false; // Set true to enable logs | |
var interval = 30 * 1000; // reload interval, ms | |
var waiting = "Waiting..." // String to display when waiting for a post | |
var title = document.title; | |
debug(title); | |
// Set to call function after all ajax loads are complete | |
$(document).ajaxStop(loadReview); | |
function loadReview() { | |
debug('starting'); | |
var re = /^(\/review\/[^\/]+)\/.*$/; // Remove tab or post ID from end of URL | |
var path = window.location.pathname.replace(re, '$1'); | |
debug(path); | |
var anchor = 'a[href="' + path + '"]'; | |
debug(anchor); | |
var revTab = $(anchor); | |
debug(revTab.length); | |
var onRevTab = revTab.hasClass('youarehere'); | |
debug(onRevTab); | |
if (onRevTab) { | |
if ($('.review-content').is(':empty') | |
&& $('.review-instructions:contains("Thank you")').length === 0 | |
&& $('.review-instructions:contains("You have no more")').length === 0 | |
&& $('.review-instructions:contains("There are no items")').length === 0) { | |
debug('no post'); | |
document.title = waiting; | |
var timeoutID = setTimeout('$(\'.youarehere\')[0].click();', interval); | |
debug('timer ID: ' + timeoutID +' interval:' + interval); | |
} | |
else { | |
if (document.title === waiting) document.title = title; | |
debug('have post or done reviewing'); | |
} | |
} | |
} | |
function debug(msg) { | |
if (debugging) console.log('loadReview: '+msg); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment