Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Last active September 26, 2015 01:55
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/eda78869fdec36011c33 to your computer and use it in GitHub Desktop.
Save Tiny-Giant/eda78869fdec36011c33 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name CV Request Archiver
// @namespace http://your.homepage/
// @version 1.0.0.0
// @description Scans the chat transcript and checks all cv requests for status, then moves the closed ones.
// @author @TinyGiant
// @match http://chat.stackoverflow.com/rooms/89853/*
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function(){
"use strict";
$.ajax({
type: 'POST',
url: '/chats/89853/events',
data: 'since=0&mode=Messages&msgCount=100&fkey=' + $('#fkey').val(),
success: function(resp){
var requests = [];
for(var i in resp.events) {
var test = /^.a href="(?:https?:)?..stackoverflow.com.questions.tagged.cv-pl(?:ease|s|z).+http:..stackoverflow.com.(?:q[^\/]*|posts)\/(\d+)/.exec(resp.events[i].content);
if(test) {
requests.push({
msg: resp.events[i].message_id,
post: +test[1],
closed: false
});
}
}
var num = requests.length - 1;
if(num >= 0) {
var postchk = setInterval(function(){
if(num === 0) clearInterval(postchk);
GM_xmlhttpRequest({
method: 'GET',
url: 'http://stackoverflow.com/flags/questions/' + requests[num].post + '/close/popup',
onload: function(resp){
requests[num].closed = /This question is now closed/.test(resp.response);
console.log(requests[num]);
if(num-- === 0) {
var ids = [];
for(var i in requests) if(requests[i].closed) ids.push(requests[i].msg);
$.ajax({
data: 'ids=' + ids.join('%2C') + '&to=23262&fkey=' + $('#fkey').val(),
type: 'POST',
url: '/admin/movePosts/89853'
});
}
}
});
}, 4000);
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment