User:Suzon99/common.js

/* Auto-Subscribe Module v 0.1 Coauthored by TK-999 and Suzon99*/ var ListingEdit = { init: function { if ( mw.config.get( "wgPageName" ) === "Autosubscribe_Module" ) { var page, inputBox, inputButton; page = document.getElementById("mw-content-text"); inputBox = document.createElement("input"); inputBox.id = "listing-edit"; inputBox.type = "text"; page.appendChild(inputBox); inputButton = document.createElement("button"); inputButton.id = "listing-update"; inputButton.textContent = "Subscribe!"; inputButton.addEventListener("click", function{ListingEdit.onSubmit}, false); page.appendChild(inputButton); } },  onSubmit: function, window.location.reload { var newItem, xhr; newItem = document.getElementById("listing-edit").value; xhr = new XMLHttpRequest; xhr.open( "POST", "/api.php" ); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xhr.send("action=edit&title="+encodeURIComponent(mw.config.get("wgPageName"))+"&token="+encodeURIComponent(mw.user.tokens.values.editToken)+"&summary=Use+of+ASM&section=1&appendtext=\n*"+encodeURIComponent(newItem)); } } ListingEdit.init;