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 http://thisisnotafish.net/
// @version 0.1
// @description Display a notice at top of questions, showing whether you've already close-voted.
// @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).ajaxComplete(function() {
$(document).ready(function() {
var msg = "";
var alreadyvoted = $( ".close-question-link[title^='You voted']" );
//console.log( "alreadyvoted:"+alreadyvoted.length );
var closed = $( ".question-status:contains('put on hold')" );
//console.log( "closed:"+closed.length );
if (alreadyvoted.length) {
msg = '<span style="color:maroon">Previously voted.</span>';
}
else if (closed.length) {
msg = '<span style="color:maroon">Question closed.</span>';
}
else {
msg = '<span style="color:green">Please vote!</span>';
}
noticeHolder.html( msg );
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment