Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tiny-Giant/3bbc399ed06c11c045e8 to your computer and use it in GitHub Desktop.
Save Tiny-Giant/3bbc399ed06c11c045e8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Programmers CV Request Generator
// @namespace http://your.homepage/
// @version 0.1
// @description This script generates formatted close vote requests and sends them to a specified chat room
// @author @TinyGiant
// @match http://*.programmers.stackexchange.com/questions/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
// Usage:
// This script works on programmers.stackexchange.com and meta.programmers.stackexchange.com
// To open the reason prompt:
// Press ctrl+shift+a or,
// Click [cv-pls] in the post menu
// Enter your reason into the prompt
// Anything that is acceptable in chat is acceptable in the reason dialog.
// Click [OK] or press enter on your keyboard to submit the request.
// Clicking on the [X] at the top of the dialog will cancel the request.
// This script will send the request to the Programmers CV Please room.
// To change this, change `room` to the id number of the room in question.
// Requests generated by this script will follow the following format:
// [tag:cv-pls] reason [title](url) - [user](url) time
// For feature requests, new site requests or bug reports:
// Send me a message in the SOCVR addressed to @TinyGiant
// I will respond as soon as I can.
var room = '26942';
var cvButton = $('<a href="#">cv-pls</a>');
$('#question .post-menu').append(cvButton);
var cvRequest = function() {
var reason = window.prompt('Reason for closing');
if(reason !== null) {
var tit = '[' + $('#question-header h1 a').text() + '](' + "http://programmers.stackexchange.com" + $('#question .short-link').attr('href') + ')';
var usr = '[' + $('#question .owner a').text() + '](' + "http://programmers.stackexchange.com" + $('#question .owner a').attr('href') + ')';
var tim = $('#question .owner .relativetime').html();
var result = '[tag:cv-pls] ' + reason + ' ' + tit + ' - ' + usr + ' ' + tim;
GM_xmlhttpRequest({
method: 'GET',
url: 'http://chat.stackexchange.com/rooms/' + room,
onload: function(response) {
GM_xmlhttpRequest({
method: 'POST',
url: 'http://chat.stackexchange.com/chats/' + room + '/messages/new',
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
data: 'text=' + encodeURIComponent(result) + '&fkey=' + response.responseText.match(/hidden" value="([\dabcdef]{32})/)[1]
});
}
});
}
}
cvButton.on('click', cvRequest);
$(document).keydown(function(e) {
if(e.ctrlKey && e.shiftKey && e.which === 65)
cvRequest();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment