User:Awesome Aasim/savedraft.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Awesome Aasim/savedraft. |
if (!savedraft) {
var savedraft = {};
if (mw.config.get("wgAction") == "edit") {
$(document).ready(function() {
savedraft.key = mw.config.get("wgUserName") + "#" + mw.config.get("wgPageName");
$('<span id="savedraft-widget" class="oo-ui-widget oo-ui-widget-enabled oo-ui-inputWidget oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-buttonInputWidget"></span>').append($('<button id="wp-savedraft" class="oo-ui-inputWidget-input oo-ui-buttonElement-button"></button>').text("Save draft").click(function(e) {
e.preventDefault();
if (localStorage.getItem(savedraft.key)) {
if (confirm("Draft already exists. Clicking \"OK\" will overwrite the previous draft.")) {
localStorage.setItem(savedraft.key, $("#wpTextbox1").val());
}
} else {
localStorage.setItem(savedraft.key, $("#wpTextbox1").val());
$("#mw-content-text").prepend($('<span id="savedraft-buttons"></span>').append($("<a/>", {
text: "Load draft",
id: "savedraft-load",
href: "#",
click: function(e) {
e.preventDefault();
$("#wpTextbox1").val(localStorage.getItem(savedraft.key));
location.href = "#editform";
}
})).append(" • ").append($("<a/>", {
text: "Delete draft",
id: "savedraft-delete",
href: "#",
click: function(e) {
e.preventDefault();
if (confirm("Really delete the draft for this page?")) {
localStorage.removeItem(savedraft.key);
mw.notify("Draft deleted.");
$("#savedraft-buttons").remove();
}
}
})));
}
mw.notify("Draft saved.");
})).insertAfter("#wpDiffWidget");
if (localStorage.getItem(savedraft.key)) {
$("#mw-content-text").prepend($('<div id="savedraft-buttons"></div>').append($("<a/>", {
text: "Load draft",
id: "savedraft-load",
href: "#",
click: function(e) {
e.preventDefault();
$("#wpTextbox1").val(localStorage.getItem(savedraft.key));
mw.notify("Draft loaded.");
}
})).append(" • ").append($("<a/>", {
text: "Delete draft",
id: "savedraft-delete",
href: "#",
click: function(e) {
e.preventDefault();
if (confirm("Really delete the draft for this page?")) {
localStorage.removeItem(savedraft.key);
mw.notify("Draft deleted.");
$("#savedraft-buttons").remove();
}
}
})));
}
});
}
}