Global Review Summary v0.2
This commit is contained in:
parent
a151e66ed1
commit
7ca2dda435
1 changed files with 63 additions and 25 deletions
|
@ -1,9 +1,11 @@
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Stack Exchange Global Review Summary
|
// @name Stack Exchange Global Review Summary
|
||||||
// @version 0.1
|
// @version 0.2
|
||||||
// @description Stack Exchange network wide review summary available in your network profile
|
// @description Stack Exchange network wide review summary available in your network profile
|
||||||
// @author Glorfindel
|
// @author Glorfindel
|
||||||
// @attribution Floern (https://github.com/Floern)
|
// @attribution Floern (https://github.com/Floern)
|
||||||
|
// @updateURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/global-review-summary/global-review-summary.user.js
|
||||||
|
// @downloadURL https://raw.githubusercontent.com/Glorfindel83/SE-Userscripts/master/global-review-summary/global-review-summary.user.js
|
||||||
// @include *://stackexchange.com/users/*/*
|
// @include *://stackexchange.com/users/*/*
|
||||||
// @match *://*.stackexchange.com/review*
|
// @match *://*.stackexchange.com/review*
|
||||||
// @match *://*.stackoverflow.com/review*
|
// @match *://*.stackoverflow.com/review*
|
||||||
|
@ -240,7 +242,7 @@ function parseNetworkAccounts(html) {
|
||||||
}
|
}
|
||||||
|
|
||||||
let siteName = siteLinkNode.textContent.trim();
|
let siteName = siteLinkNode.textContent.trim();
|
||||||
let siteReviewURL = siteLinkNode.href.replace(/users\/.*$/i, 'review/');
|
let siteURL = siteLinkNode.href.replace(/users\/.*$/i, '');
|
||||||
|
|
||||||
// get reputation
|
// get reputation
|
||||||
let reputationNode = accountNode.querySelector('.account-stat span.account-number');
|
let reputationNode = accountNode.querySelector('.account-stat span.account-number');
|
||||||
|
@ -248,29 +250,37 @@ function parseNetworkAccounts(html) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let reputation = parseInt(reputationNode.innerHTML.replace(",", ""));
|
let reputation = parseInt(reputationNode.innerHTML.replace(",", ""));
|
||||||
// 350 is the minimum (for beta sites)
|
|
||||||
if (reputation < 350) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
accounts.push({ siteName: siteName, reviewURL: siteReviewURL });
|
accounts.push({ siteName: siteName, reputation: reputation, siteURL: siteURL });
|
||||||
|
|
||||||
// add meta site
|
// add meta site
|
||||||
if (!/(meta\.stackexchange|stackapps)\.com\//.test(siteReviewURL)) {
|
if (!/(meta\.stackexchange|stackapps)\.com\//.test(siteURL)) {
|
||||||
let metaSiteReviewURL;
|
let metaSiteURL;
|
||||||
if (/\.stackexchange\.com\//.test(siteReviewURL)) // SE 2.0 sites
|
if (/\.stackexchange\.com\//.test(siteURL)) // SE 2.0 sites
|
||||||
metaSiteReviewURL = siteReviewURL.replace('.stackexchange.com', '.meta.stackexchange.com');
|
metaSiteURL = siteURL.replace('.stackexchange.com', '.meta.stackexchange.com');
|
||||||
else if (/\/\/[a-z]{2}\.stackoverflow\.com\//.test(siteReviewURL)) // localized SO sites
|
else if (/\/\/[a-z]{2}\.stackoverflow\.com\//.test(siteURL)) // localized SO sites
|
||||||
metaSiteReviewURL = siteReviewURL.replace('.stackoverflow.com', '.meta.stackoverflow.com');
|
metaSiteURL = siteURL.replace('.stackoverflow.com', '.meta.stackoverflow.com');
|
||||||
else // SE 1.0 sites
|
else // SE 1.0 sites
|
||||||
metaSiteReviewURL = siteReviewURL.replace('//', '//meta.');
|
metaSiteURL = siteURL.replace('//', '//meta.');
|
||||||
accounts.push({ siteName: siteName + " Meta", reviewURL: metaSiteReviewURL });
|
accounts.push({ siteName: siteName + " Meta", reputation: reputation, siteURL: metaSiteURL });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the sites
|
// load the sites
|
||||||
let i = -1;
|
let i = -1;
|
||||||
let loaded = 0;
|
let loaded = 0;
|
||||||
|
function startLoadingSiteReviewSummary(account) {
|
||||||
|
loadSiteReviewSummary(account.siteName, account.siteURL + 'review/', loadCallback, 0);
|
||||||
|
};
|
||||||
|
function loadCallback() {
|
||||||
|
loaded++;
|
||||||
|
document.getElementById('review-summary-loading-progress').textContent = loaded + " / " + accounts.length;
|
||||||
|
if (loaded >= accounts.length) {
|
||||||
|
// end of list
|
||||||
|
document.getElementById('review-summary-loading').style.visibility = 'hidden';
|
||||||
|
}
|
||||||
|
loadNextSite();
|
||||||
|
};
|
||||||
function loadNextSite() {
|
function loadNextSite() {
|
||||||
i++;
|
i++;
|
||||||
if (i >= accounts.length) {
|
if (i >= accounts.length) {
|
||||||
|
@ -281,15 +291,43 @@ function parseNetworkAccounts(html) {
|
||||||
let account = accounts[i];
|
let account = accounts[i];
|
||||||
let delay = 1000;
|
let delay = 1000;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
loadSiteReviewSummary(account.siteName, account.reviewURL, function() {
|
if (account.reputation >= 350) {
|
||||||
loaded++;
|
// 350 is the minimum reputation to review on beta-sites
|
||||||
document.getElementById('review-summary-loading-progress').textContent = loaded + " / " + accounts.length;
|
startLoadingSiteReviewSummary(account);
|
||||||
if (loaded >= accounts.length) {
|
} else {
|
||||||
// end of list
|
// check for Custodian badges first
|
||||||
document.getElementById('review-summary-loading').style.visibility = 'hidden';
|
console.log('loading ' + account.siteName + ' (badges)');
|
||||||
}
|
var url = account.siteURL + 'users/current?tab=badges&sort=name';
|
||||||
loadNextSite();
|
GM.xmlHttpRequest({
|
||||||
}, 0);
|
method: 'GET',
|
||||||
|
url: url,
|
||||||
|
onload: function(response) {
|
||||||
|
let pageNode = document.createElement('div');
|
||||||
|
pageNode.innerHTML = response.response;
|
||||||
|
var badges = pageNode.querySelectorAll(".user-badges a.badge");
|
||||||
|
var found = false;
|
||||||
|
for (j = 0; j < badges.length; j++) {
|
||||||
|
// On localized sites, this badge has a different name
|
||||||
|
if (/Custodian|Страж|見回り|Guardião|Custodio/gi.test(badges[j].innerText)) {
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
startLoadingSiteReviewSummary(account);
|
||||||
|
} else {
|
||||||
|
loadCallback();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onerror: function(response) {
|
||||||
|
console.error('loadSiteReviewSummary: ' + url);
|
||||||
|
console.error('loadSiteReviewSummary: ' + JSON.stringify(response));
|
||||||
|
loadCallback();
|
||||||
|
showLoadingError(url, response.status);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}, delay);
|
}, delay);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue