Skip to content

Instantly share code, notes, and snippets.

@WillSullivan
Created July 8, 2013 14:37
Show Gist options
  • Save WillSullivan/5949386 to your computer and use it in GitHub Desktop.
Save WillSullivan/5949386 to your computer and use it in GitHub Desktop.
This is a great tool for people who hate tags. Bad tags preferably. Automatically edits out tags you specify from questions. For example, a tag that stinks and should be burninated would be "guide". Its meta-y, is usually used by people looking for tutorial links, or by people who don't quite get tags (e.g., user asks the question "how do I add …
// ==UserScript==
// @name Shitty tag eradicator
// @namespace http://statestreetgang.net/
// @version 1.0
// @description Quick way to remove the Books tag and delete the question.
// @match http://stackoverflow.com/questions/*
// ==/UserScript==
function exec(fn) {
var script = document.createElement('script');
script.setAttribute("type", "application/javascript");
script.textContent = '(' + fn + ')();';
document.body.appendChild(script); // run the script
document.body.removeChild(script); // clean up
}
window.addEventListener("load", function () {
// script injection
exec(function () {
/* add other tags that indicate the question should be DELETED here */
var tagsThatGetYouDeleted = ["education", "suggestions", "books", "ebook", "exam", "tutorials", "tutorial", "oreilly-book", ];
/* add other tags that should get REMOVED but don't indicate the question is deletable */
var tagsThatShouldJustBeRemoved = ["mmorpg", "authors", "technologies", "code-reading", "teaching", "information", "guide", "tips-and-tricks", "railstutorial.org", "slowness", "blogs", "article", "programming-pearls", "database-optimization", "puzzle", "podcast", "audiobook", "economics", "usability", "recommendation", "training", "intermediate", "mindmap", "mindmapping", ]
var tags = $(".post-taglist .post-tag").map(function () { return $(this).text(); }).get();
var deleteQuestion = false;
var toSave = [];
$.each(tags,
function (index)
{
if ($.inArray(tags[index], tagsThatGetYouDeleted) !== -1) // if the tag is in the deletion list, mark delete as true
deleteQuestion = true;
else if ($.inArray(tags[index], tagsThatShouldJustBeRemoved) === -1) // the tag is not in the dl, and if it is not in the removed list
toSave.push(tags[index]); // save it
});
// we saved all tags, so are done
if (toSave.length === tags.length) return;
// Unfortunately, at this point, you probably need to flag it for mod attention because it sucks balls
if (toSave.length === 0){
alert('This question has nothing but bad tags on it. Either figure out a valid tag or flag and ask a mod to delete it if it is hopeless.');
return;
}
var id = document.location.href.match(/\d+/);
// posts your edit, and votes to delete if the question sucks
$.ajax({
type: "POST",
url: "http://stackoverflow.com/posts/" + id + "/edit-tags",
data: { fkey: StackExchange.options.user.fkey, tagnames: toSave.join(" ") },
success: function ()
{
if(deleteQuestion)
$.ajax({
type: "POST",
url: "http://stackoverflow.com/posts/" + id + "/vote/10",
data: { fkey: StackExchange.options.user.fkey },
success: function () { window.location.reload(); },
});
},
error: function (x, status, error)
{
alert(status + "\\n" + error);
},
});
});
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment