Created
November 13, 2011 09:31
-
-
Save banksJeremy/1361876 to your computer and use it in GitHub Desktop.
Stack Exchange deleted post user script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee --compile --bare | |
`// ==UserScript== | |
// @name Stack Exchange Deleted Question Viewer (Developer Trunk) | |
// @version 1.0 | |
// @description (Intended for developer use only.) | |
// @namespace http://jeremybanks.ca/ | |
// @include http://stackoverflow.com/* | |
// @include http://*.stackoverflow.com/* | |
// @include http://superuser.com/* | |
// @include http://*.superuser.com/* | |
// @include http://serverfault.com/* | |
// @include http://*.serverfault.com/* | |
// @include http://stackexchange.com/* | |
// @include http://*.stackexchange.com/* | |
// ==/UserScript== | |
` | |
load = (url, success, failure) -> | |
# Loads a script specified by a URL into the document. | |
e = document.createElement "script" | |
e.setAttribute "src", url | |
if success? then e.addEventListener "load", success | |
if failure? then e.addEventListener "error", failure | |
document.body.appendChild e | |
return e | |
inject = (f) -> | |
# Injects a function into the document and evaluates it. | |
# | |
# It is injected as source code, so it loses its current | |
# scope and gains a new one under the global scope. | |
e = document.createElement "script" | |
e.textContent = "(#{f})();" | |
document.body.appendChild e | |
return e | |
url = "https://raw.github.com/gist/9e1773d770e96d7338c8/deleted.user.js" | |
load url, null, -> console.error "Unable to load deleted question viewer trunk!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Stack Exchange Deleted Question Viewer (Developer Trunk) | |
// @version 1.0 | |
// @description (Intended for developer use only.) | |
// @namespace http://jeremybanks.ca/ | |
// @include http://stackoverflow.com/* | |
// @include http://*.stackoverflow.com/* | |
// @include http://superuser.com/* | |
// @include http://*.superuser.com/* | |
// @include http://serverfault.com/* | |
// @include http://*.serverfault.com/* | |
// @include http://stackexchange.com/* | |
// @include http://*.stackexchange.com/* | |
// ==/UserScript== | |
;var inject, load, url; | |
load = function(url, success, failure) { | |
var e; | |
e = document.createElement("script"); | |
e.setAttribute("src", url); | |
if (success != null) { | |
e.addEventListener("load", success); | |
} | |
if (failure != null) { | |
e.addEventListener("error", failure); | |
} | |
document.body.appendChild(e); | |
return e; | |
}; | |
inject = function(f) { | |
var e; | |
e = document.createElement("script"); | |
e.textContent = "(" + f + ")();"; | |
document.body.appendChild(e); | |
return e; | |
}; | |
url = "https://raw.github.com/gist/9e1773d770e96d7338c8/deleted.user.js"; | |
load(url, null, function() { | |
return console.error("Unable to load deleted question viewer trunk!"); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env coffee --compile --bare | |
`// ==UserScript== | |
// @name Stack Exchange Deleted Question Viewer | |
// @version 1.1 | |
// @description Allows you to view some deleted questions on Stack Exchange. | |
// @namespace http://jeremybanks.ca/ | |
// @include http://stackoverflow.com/* | |
// @include http://*.stackoverflow.com/* | |
// @include http://superuser.com/* | |
// @include http://*.superuser.com/* | |
// @include http://serverfault.com/* | |
// @include http://*.serverfault.com/* | |
// @include http://stackexchange.com/* | |
// @include http://*.stackexchange.com/* | |
// ==/UserScript== | |
` | |
### helpers from http://stackoverflow.com/q/6825715/1114 ### | |
load = (url, onLoad, onError) -> | |
# Loads the script at url into the document. Optionally, | |
# callbacks may be provided for onLoad and onError. | |
e = document.createElement "script" | |
e.setAttribute "src", url | |
if onLoad? then e.addEventListener "load", onLoad | |
if onError? then e.addEventListener "error", onError | |
document.body.appendChild e | |
return e | |
execute = (functionOrCode) -> | |
# Inserts a function or string of code into the document | |
# and executes it. The functions are converted to source | |
# code before being inserted, so they lose their current | |
# scope/closures and are run underneath the global scope | |
# (window). | |
if typeof functionOrCode is "function" | |
code = "(#{functionOrCode})();" | |
else | |
code = functionOrCode | |
e = document.createElement "script" | |
e.textContent = code | |
document.body.appendChild e | |
return e | |
loadAndExecute = (url, functionOrCode) -> | |
# A shortcut; this loads a script from url, then inserts | |
# and executes functionOrCode if successful. | |
load url, -> execute functionOrCode | |
### main script ### | |
loadAndExecute "//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", (-> | |
pathMatch = window.location.pathname.match /\/questions\/(\d+)[\/$]/ | |
onDeletedQuestion = pathMatch and | |
$("h1").text() is "Page Not Found" and | |
$(".revision-comment").length | |
return if not onDeletedQuestion then | |
rightCol = $(".rightcol").empty().css | |
color: "#444" | |
fontSize: "120%" | |
background: "#FFE" | |
leftCol = $(".leftcol") | |
print = (s) -> rightCol.append $("<p>").css(margin: "1em").text s | |
print "Deleted post detected. Loading post content..." | |
questionID = pathMatch[1] | |
questionTitle = null | |
questionMD = null | |
questionHTML = null | |
questionPoster = null | |
questionEditor = null | |
editorURL = "/posts/#{questionID}/edit" | |
editorRequest = $.ajax editorURL, dataType: "html" | |
editorLoaded = (data, statusText, request) -> | |
return editorFailed() if request.status isnt 200 | |
dataDOM = $(data) | |
questionTitle = dataDOM.find("input[name=title]").val() | |
questionMD = dataDOM.find("textarea").val() | |
questionPoster = dataDOM.find("select[name=revisions-list] option:last").text() | |
questionEditor = dataDOM.find("select[name=revisions-list] option:first").text() | |
print "Post \"#{questionTitle}\" loaded." | |
if questionPoster | |
print "Posted by: #{questionPoster}" | |
if questionEditor isnt questionPoster | |
print "Edited by: #{questionEditor}" | |
$("title").text $("title").text().replace "Page Not Found", questionTitle | |
$("h1").text questionTitle | |
leftCol.empty().append( | |
$("<pre>").html(questionMD).css(whiteSpace: "pre-wrap") | |
).animate(width: "+=150") | |
rightCol.animate width: "-=150" | |
print "Loading Markdown parser..." | |
mdRequest = $.getScript "/content/js/wmd.js", dataType: "script" | |
mdRequest.then mdLoaded, mdFailed | |
editorFailed = -> | |
print "Unable to load deleted question." | |
editorRequest.then editorLoaded, editorFailed | |
mdLoaded = (data, statusText, request) -> | |
print "Loaded." | |
questionHTML = (new Markdown.Converter).makeHtml questionMD | |
leftCol.html(questionHTML) | |
mdFailed = -> | |
print "Unable to load Markdown parser." | |
) # end injected code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Stack Exchange Deleted Question Viewer | |
// @version 1.1 | |
// @description Allows you to view some deleted questions on Stack Exchange. | |
// @namespace http://jeremybanks.ca/ | |
// @include http://stackoverflow.com/* | |
// @include http://*.stackoverflow.com/* | |
// @include http://superuser.com/* | |
// @include http://*.superuser.com/* | |
// @include http://serverfault.com/* | |
// @include http://*.serverfault.com/* | |
// @include http://stackexchange.com/* | |
// @include http://*.stackexchange.com/* | |
// ==/UserScript== | |
; | |
/* helpers from http://stackoverflow.com/q/6825715/1114 */var execute, load, loadAndExecute; | |
load = function(url, onLoad, onError) { | |
var e; | |
e = document.createElement("script"); | |
e.setAttribute("src", url); | |
if (onLoad != null) { | |
e.addEventListener("load", onLoad); | |
} | |
if (onError != null) { | |
e.addEventListener("error", onError); | |
} | |
document.body.appendChild(e); | |
return e; | |
}; | |
execute = function(functionOrCode) { | |
var code, e; | |
if (typeof functionOrCode === "function") { | |
code = "(" + functionOrCode + ")();"; | |
} else { | |
code = functionOrCode; | |
} | |
e = document.createElement("script"); | |
e.textContent = code; | |
document.body.appendChild(e); | |
return e; | |
}; | |
loadAndExecute = function(url, functionOrCode) { | |
return load(url, function() { | |
return execute(functionOrCode); | |
}); | |
}; | |
/* main script */ | |
loadAndExecute("//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js", (function() { | |
var editorFailed, editorLoaded, editorRequest, editorURL, leftCol, mdFailed, mdLoaded, onDeletedQuestion, pathMatch, print, questionEditor, questionHTML, questionID, questionMD, questionPoster, questionTitle, rightCol; | |
pathMatch = window.location.pathname.match(/\/questions\/(\d+)[\/$]/); | |
onDeletedQuestion = pathMatch && $("h1").text() === "Page Not Found" && $(".revision-comment").length; | |
if (!onDeletedQuestion) { | |
; | |
} | |
rightCol = $(".rightcol").empty().css({ | |
color: "#444", | |
fontSize: "120%", | |
background: "#FFE" | |
}); | |
leftCol = $(".leftcol"); | |
print = function(s) { | |
return rightCol.append($("<p>").css({ | |
margin: "1em" | |
}).text(s)); | |
}; | |
print("Deleted post detected. Loading post content..."); | |
questionID = pathMatch[1]; | |
questionTitle = null; | |
questionMD = null; | |
questionHTML = null; | |
questionPoster = null; | |
questionEditor = null; | |
editorURL = "/posts/" + questionID + "/edit"; | |
editorRequest = $.ajax(editorURL, { | |
dataType: "html" | |
}); | |
editorLoaded = function(data, statusText, request) { | |
var dataDOM, mdRequest; | |
if (request.status !== 200) { | |
return editorFailed(); | |
} | |
dataDOM = $(data); | |
questionTitle = dataDOM.find("input[name=title]").val(); | |
questionMD = dataDOM.find("textarea").val(); | |
questionPoster = dataDOM.find("select[name=revisions-list] option:last").text(); | |
questionEditor = dataDOM.find("select[name=revisions-list] option:first").text(); | |
print("Post \"" + questionTitle + "\" loaded."); | |
if (questionPoster) { | |
print("Posted by: " + questionPoster); | |
if (questionEditor !== questionPoster) { | |
print("Edited by: " + questionEditor); | |
} | |
} | |
$("title").text($("title").text().replace("Page Not Found", questionTitle)); | |
$("h1").text(questionTitle); | |
leftCol.empty().append($("<pre>").html(questionMD).css({ | |
whiteSpace: "pre-wrap" | |
})).animate({ | |
width: "+=150" | |
}); | |
rightCol.animate({ | |
width: "-=150" | |
}); | |
print("Loading Markdown parser..."); | |
mdRequest = $.getScript("/content/js/wmd.js", { | |
dataType: "script" | |
}); | |
return mdRequest.then(mdLoaded, mdFailed); | |
}; | |
editorFailed = function() { | |
return print("Unable to load deleted question."); | |
}; | |
editorRequest.then(editorLoaded, editorFailed); | |
mdLoaded = function(data, statusText, request) { | |
print("Loaded."); | |
questionHTML = (new Markdown.Converter).makeHtml(questionMD); | |
return leftCol.html(questionHTML); | |
}; | |
return mdFailed = function() { | |
return print("Unable to load Markdown parser."); | |
}; | |
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: | |
coffee --compile --bare . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What I should end up doing is finding every feature that | |
isn't locked down and using it. | |
Add the normal footer to posts: | |
link | edit | open | flag edited.... asked... | |
don't require markdown for that. | |
Remove the sidebar and add header bar including the deletion message. | |
$("<div>").addClass("module system-alert") | |
.append $("revision-comment").parent().detach() | |
class DeletedPostLoader | |
constructor: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't seem to be working. It looks like the /posts/ URLs for deleted questions now return short "The post has been deleted and you can't..." documents.