Skip to content

Instantly share code, notes, and snippets.

@NekoTony
Last active October 20, 2017 22:59
Show Gist options
  • Save NekoTony/239ffc966b5a92bffbccf4d8ae8c6779 to your computer and use it in GitHub Desktop.
Save NekoTony/239ffc966b5a92bffbccf4d8ae8c6779 to your computer and use it in GitHub Desktop.
Atelier801 Forum Drafts
// ==UserScript==
// @name Atelier801 Drafts
// @namespace https://atelier801.com/topic?f=5&t=888706&p=1
// @version 1.1
// @description Save drafts on A801
// @author Nekotonyy & Thebndjames
// @match https://atelier801.com/topic?*
// @include http://www.atelier801.com/profile?*
// @include http://www.atelier801.com/new-topic?*
// @include https://atelier801.com/new-dialog
// @include https://atelier801.com/new-discussion
// @include https://atelier801.com/conversation?*
// @grant none
// ==/UserScript==
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = "[hidden] {display: none !important;}";
document.body.appendChild(css);
$(".btn-post").after(' <label class="btn btn-success">Upload Draft<input type="file" id="file" hidden></label> <label class="btn btn-warning">Download Draft<input value="download" type="button" id="download" hidden/></label>');
$("label #file").change(function(e) {
var file = e.target.files[0];
var textbubble = $('textarea');
var reader = new FileReader();
reader.readAsText(file);
reader.onload = function(evt) {
textbubble.text(evt.target.result);
};
reader.onerror = function(evt) {
textbubble.text("Failed to insert bbcode. Sry ^^");
};
});
function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 6; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
$("label #download").click(function() {
$("<a />", {
download: "bbcode_" + makeid() + ".txt",
href: URL.createObjectURL(
new Blob([$("#message_reponse").val()], {
type: "text/plain"
}))
})
.appendTo("body")[0].click();
$(window).one("focus", function() {
$("a").last().remove();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment