Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Forked from gunr2171/cv-plz-userscript
Last active August 29, 2015 14:27
Show Gist options
  • Save Tiny-Giant/ae7c0f5e6823468d75c1 to your computer and use it in GitHub Desktop.
Save Tiny-Giant/ae7c0f5e6823468d75c1 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Stack Overflow 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://*.stackoverflow.com/questions/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
// Usage:
// This script works on stackoverflow.com and meta.stackoverflow.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 SO Close Vote Reviewers 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 = '41570';
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://stackoverflow.com" + $('#question .short-link').attr('href') + ')';
var result = '[tag:cv-pls] ' + reason + ' ' + tit;
GM_xmlhttpRequest({
method: 'GET',
url: 'http://chat.stackoverflow.com/rooms/' + room,
onload: function(response) {
GM_xmlhttpRequest({
method: 'POST',
url: 'http://chat.stackoverflow.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();
});
@gunr2171
Copy link

Would you like to put this script in the SOCVR repo? https://github.com/SO-Close-Vote-Reviewers/UserScripts

@Tiny-Giant
Copy link
Author

Yeah, don't know much about github yet though. If you want to add me / do it yourself go ahead. But then the pin will have to change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment