Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 21 additions & 34 deletions dev/ReviewSidebarLink.user.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
// ==UserScript==
// @name Review Sidebar Link
// @description Adds a link to the "reviews" to the sidebar of posts.
// @version 0.1.1
// @version 0.1.2
// @author Cody Gray
// @homepage https://github.com/codygray/so-userscripts
//
// @updateURL https://github.com/codygray/so-userscripts/raw/master/ReviewSidebarLink.user.js
// @downloadURL https://github.com/codygray/so-userscripts/raw/master/ReviewSidebarLink.user.js
//
// @include https://*stackoverflow.com/*
// @include https://*serverfault.com/*
// @include https://*superuser.com/*
// @include https://*askubuntu.com/*
// @include https://*mathoverflow.net/*
// @include https://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.serverfault.com/*
// @match *://*.superuser.com/*
// @match *://*.askubuntu.com/*
// @match *://*.mathoverflow.net/*
// @match *://*.stackexchange.com/*
// @match *://*.stackapps.com/*
//
// @exclude *chat.*
// @exclude *blog.*
Expand Down Expand Up @@ -48,10 +49,10 @@ $(document).ready(function(e)
var $modMenu = $(data);

// Determine how many reviews the post has.
var $reviews = $modMenu.find('input[name="mod-actions"][value="show-reviews"]');
var $reviews = $modMenu.find('input[id="se-mod-menu-action-show-reviews"]');
if (!$reviews.disabled)
{
var reviewsCount = $reviews.siblings('.action-name').find('.mod-flag-indicator').text().trim().split(' ')[0];
var reviewsCount = $reviews.parents().find('label[for="se-mod-menu-action-show-reviews"] span.s-badge').text();
if (reviewsCount !== '')
{
// If the post has reviews...
Expand All @@ -68,15 +69,16 @@ $(document).ready(function(e)
var $reviewsHistory = $(data);

// Only count this review queue if it has had a non-zero count of reviews.
var actualReviewsCount = 0;
var activeReviewsCount = 0;
var reviewTooltip = 'Reviews:\n';
var $reviewsTable = $reviewsHistory.find('#content table.sorter tbody tr').each(function()
{
var $tr = $(this);
var queue = $tr.find('td:nth-child(1)').text();
var count = $tr.find('td:nth-child(4)').text();
actualReviewsCount += (parseInt(count, 10) > 0);
reviewTooltip += (' ' + queue + '\t' + count + '\n');
var dequeued = $tr.find('td:nth-child(4)').text();
var count = $tr.find('td:nth-child(5)').text();
activeReviewsCount += (!dequeued);
reviewTooltip += (' ' + queue + ' \t' + count + (dequeued ? " [completed]" : "") + '\n');
});

// Build the reviews link.
Expand All @@ -87,29 +89,13 @@ $(document).ready(function(e)
'<svg aria-hidden="true"' +
' class="svg-icon mr2 iconReviewQueue"' +
' width="18" height="18" viewBox="0 0 18 18">' +
'<path d="M16 7.5l-5 4.97-1.79-1.77a1 1 0 0 0-1.4 0l-2.1 2.1a1 1 0 0 0 0 1.4L8.5 17H2a2 2 0 0 1-2-2V3c0-1.1.9-2 2-2h12a2 2 0 0 1 2 2v4.5zM12 7H2v2h10V7zm2-4H2v2h12V3zM2 11v2h3v-2H2zm16-.5l-7 7-4-4L8.5 12l2.5 2.5L16.5 9l1.5 1.5z"></path>' +
'</svg>' +
actualReviewsCount +
'<path d="M16 7.5l-5 4.97-1.79-1.77a1 1 0 0 0-1.4 0l-2.1 2.1a1 1 0 0 0 0 1.4L8.5 17H2a2 2 0 0 1-2-2V3c0-1.1.9-2 2-2h12a2 2 0 0 1 2 2v4.5zM12 7H2v2h10V7zm2-4H2v2h12V3zM2 11v2h3v-2H2zm16-.5l-7 7-4-4L8.5 12l2.5 2.5L16.5 9l1.5 1.5z"' +
(activeReviewsCount ? ' color="red"' : '') + '>' +'</path></svg>' +
(activeReviewsCount ? activeReviewsCount : '') +
'</a>';

// Determine where to insert the link (after flags, before comments, or at end).
var $flagsLink = $votingContainer.find('[data-shortcut="F"]');
if ($flagsLink.length !== 0)
{
$flagsLink.after(reviewsLink);
}
else
{
var $deletedCommentsLink = $votingContainer.find('[data-shortcut="D"]');
if ($deletedCommentsLink !== 0)
{
$deletedCommentsLink.before(reviewsLink);
}
else
{
$votingContainer.append(reviewsLink);
}
}
// insert the link after the timeline
$votingContainer.find('[data-shortcut="T"]').after(reviewsLink);
}
});
}
Expand All @@ -118,6 +104,7 @@ $(document).ready(function(e)
});
});

// this next stuff no longer seems to work - the review summary is not available this way now?
if (window.location.pathname.endsWith('/show-reviews'))
{
// Iterate through each review queue.
Expand Down