Skip to content

Instantly share code, notes, and snippets.

@mogsdad
Last active January 7, 2016 19:40
Show Gist options
  • Save mogsdad/767f8adc04d1d5c732c9 to your computer and use it in GitHub Desktop.
Save mogsdad/767f8adc04d1d5c732c9 to your computer and use it in GitHub Desktop.
Display a notice at top of questions, showing whether you've already close-voted.
// ==UserScript==
// @name Close Vote Reminder
// @namespace https://gist.github.com/mogsdad/767f8adc04d1d5c732c9
// @version 0.2
// @description Display a notice at top of questions with their status wrt close votes.
// @author Mogsdad
// @include /^https?:\/\/\w*.?(stackoverflow|stackexchange|serverfault|superuser|askubuntu|stackapps)\.com\/(questions|posts|review)\/\d+\/.*/
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
(function(){
var headerWidth = $('#header').width();
var logoWidth = $('#hlogo').width();
var navWidth = $('#hmenus').width();
var availableWidth = headerWidth - (logoWidth + navWidth);
var noticeHolder = $('<div/>').css({'position':'absolute','left':logoWidth + 'px','font-size':'2em','font-weight':'bold','line-height':'75px','width':availableWidth + 'px','text-align':'center'});
$('#hmenus').before(noticeHolder);
$(document).ready(function(){
updateNotice();
});
$(document).ajaxComplete(function () {
updateNotice();
});
//$(document).ajaxComplete(function() {
function updateNotice() {
var msg = "";
if ($( ".close-question-link[title^='You voted']" ).length) {
var needsN = $( ".close-question-link" ).attr("title").match(/[\d]+ more/i);
msg = '<span style="color:maroon">You voted. (__more__)</span>'
.replace("__more__",needsN);
}
else if ($( ".close-question-link[title~='more']" ).length) {
var needsN = $( ".close-question-link" ).attr("title").match(/[\d]+ more/i);
msg = '<span style="color:green">Needs __more__</span>'
.replace("__more__",needsN);
}
else if ($( ".question-status:contains('deleted')" ).length) {
msg = '<span style="color:maroon">Question deleted.</span>';
}
else if ($( ".question-status:contains('closed'),.question-status:contains('put on hold')" ).length) {
msg = '<span style="color:maroon">Question closed.</span>';
}
else {
//msg = '<span style="color:green">Nevermind</span>';
}
noticeHolder.html( msg );
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment