Last active
June 27, 2020 14:09
-
-
Save JanWichelmann/810c5a39bbc90b22ec45e01d9db5cf4a to your computer and use it in GitHub Desktop.
User script to add a heading when reviewing a suggested edit on the Stack Exchange Network.
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 Heading in suggested edits queue | |
// @version 1.1 | |
// @description Adds a heading to better indicate whether one is reviewing an edit on a question or an answer, and whether this post is closed. | |
// @author Jan Wichelmann | |
// | |
// @include https://*stackoverflow.com/review/suggested-edits/* | |
// @include https://*serverfault.com/review/suggested-edits/* | |
// @include https://*superuser.com/review/suggested-edits/* | |
// @include https://*askubuntu.com/review/suggested-edits/* | |
// @include https://*mathoverflow.net/review/suggested-edits/* | |
// @include https://*.stackexchange.com/review/suggested-edits/* | |
// @include https://stackapps.com/review/suggested-edits/* | |
// | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function improveReviewUi() | |
{ | |
// Find suggested edit div | |
let suggestedEditDiv = $('div[id^=suggested-edit-]'); | |
if(suggestedEditDiv.length == 0) | |
return; | |
// Check post type | |
let postIsQuestion = false; | |
let postIsAnswer = false; | |
if(suggestedEditDiv.hasClass('post-type-id-1')) | |
postIsQuestion = true; | |
else if(suggestedEditDiv.hasClass('post-type-id-2')) | |
postIsAnswer = true; | |
// Check post state | |
let titleText = $('div.summary > h2 > a').text(); | |
let postIsClosed = false; | |
let postIsDuplicate = false; | |
if(titleText.includes('[closed]')) | |
postIsClosed = true; | |
if(titleText.includes('[duplicate]')) | |
postIsDuplicate = true; | |
// Compose heading | |
let newHeading = ''; | |
if(postIsQuestion) | |
{ | |
newHeading += 'Question'; | |
if(postIsClosed) | |
newHeading += ' (closed)'; | |
if(postIsDuplicate) | |
newHeading += ' (closed as duplicate)'; | |
} | |
else if(postIsAnswer) | |
{ | |
newHeading += 'Answer'; | |
if(postIsClosed) | |
newHeading += ' (question closed)'; | |
if(postIsDuplicate) | |
newHeading += ' (question closed as duplicate)'; | |
} | |
// Add new heading | |
$('div.review-content > div.mainbar-full').prepend('<h2>' + newHeading + '</h2>'); | |
} | |
// Run function on page load | |
improveReviewUi(); | |
// ...and on each page update | |
$(document).ajaxComplete(function(event, xhr, settings) | |
{ | |
if(settings.url.includes('/review/next-task') || settings.url.includes('/review/task-reviewed/')) | |
{ | |
// Ignore inline edits | |
if(!location.href.includes('/questions/')) | |
{ | |
improveReviewUi(); | |
} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment