Skip to content

Instantly share code, notes, and snippets.

@kappa7194 kappa7194/user.js

Last active Aug 29, 2015
Embed
What would you like to do?
// ==UserScript==
// @name My Fancy New Userscript
// @namespace http://your.homepage/
// @version 0.1
// @description enter something useful
// @author You
// @match http://stackoverflow.com/review/close*
// @grant none
// ==/UserScript==
(function () {
'use strict';
var addSiblingHelper = function (root, selector, key) {
var element = $(root).find(selector).next();
element.html('[' + key + '] ' + element.html());
};
var addCousinHelper = function (root, selector, key) {
var element = $(root).find(selector).parent().next().next();
element.html('[' + key + '] ' + element.html());
};
var addCloseReasonHelper = function (root, reason, key) {
addSiblingHelper(root, '[name="close-reason"][value="' + reason + '"]', key);
};
var addOffTopicReasonHelper = function (root, reason, key) {
addSiblingHelper(root, '[name="close-as-off-topic-reason"][value="' + reason +'"]', key);
};
var addMigrationHelper = function (root, reason, key) {
addCousinHelper(root, '[name="migration"][value="' + reason + '"]', key);
};
var addHelpers = function (root) {
addCloseReasonHelper(root, 'Duplicate', '1');
addCloseReasonHelper(root, 'OffTopic', '2');
addCloseReasonHelper(root, 'Unclear', '3');
addCloseReasonHelper(root, 'TooBroad', '4');
addCloseReasonHelper(root, 'OpinionBased', '5');
addOffTopicReasonHelper(root, '4', '1');
addOffTopicReasonHelper(root, '7', '2');
addOffTopicReasonHelper(root, '16', '3');
addOffTopicReasonHelper(root, '13', '4');
addOffTopicReasonHelper(root, '11', '5');
addOffTopicReasonHelper(root, '2', '6');
addOffTopicReasonHelper(root, '3', '7');
addMigrationHelper(root, 'meta.stackoverflow.com', '1');
addMigrationHelper(root, 'superuser.com', '2');
addMigrationHelper(root, 'tex.stackexchange.com', '3');
addMigrationHelper(root, 'dba.stackexchange.com', '4');
addMigrationHelper(root, 'stats.stackexchange.com', '5');
};
var observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
for (var i = 0, j = mutation.addedNodes.length; i < j; i++) {
var node = mutation.addedNodes[i];
if (node.tagName === 'DIV' && node.id === 'popup-close-question') {
addHelpers(node);
}
}
});
});
observer.observe(document.querySelector('.review-content'), { 'childList': true, 'subtree': true });
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.