User:Lil' Miss Rarity/queue.js

//Simple queue system made by Lil' Miss Rarity

var queue = window.queue || {};

queue.addPage = function(page, callback) {

if (typeof localStorage[mw.config.get("wgUserName") + "_deleteQueue"] === "undefined") {

localStorage[mw.config.get("wgUserName") + "_deleteQueue"] = "{}"; }

var currentQueue = JSON.parse(localStorage[mw.config.get("wgUserName") + "_deleteQueue"]);

if (typeof currentQueue[page] === "undefined") {

currentQueue[page] = true; } else {

alert(page + " is already in the queue."); }

localStorage[mw.config.get("wgUserName") + "_deleteQueue"] = JSON.stringify(currentQueue);

if (typeof callback === "function") {

callback; } };

queue.clearQueue = function {

localStorage[mw.config.get("wgUserName") + "_deleteQueue"] = "{}";

console.log("Queue cleared!"); };

queue.printQueue = function {

if (typeof localStorage[mw.config.get("wgUserName") + "_deleteQueue"] === "undefined") {

alert("Please add items to the queue before printing."); } else {

var currentQueue = JSON.parse(localStorage[mw.config.get("wgUserName") + "_deleteQueue"]); var list = "";

for (var page in currentQueue) {

list += page + "\n"; }

console.log(list); } };

queue.removePage = function(page, callback) {

if (typeof localStorage[mw.config.get("wgUserName") + "_deleteQueue"] === "undefined") {

alert("Please add items to the queue before deleting them."); } else {

var currentQueue = JSON.parse(localStorage[mw.config.get("wgUserName") + "_deleteQueue"]);

if (typeof currentQueue[page] === "undefined") {

alert("Item is not in the queue."); } else {

delete currentQueue[page];

localStorage[mw.config.get("wgUserName") + "_deleteQueue"] = JSON.stringify(currentQueue); }

if (typeof callback === "function") {

callback; }   } };

queue.addButtons = function {

var button = ""; button += "   Add"; button += ""; button += ""; button += "   Remove"; button += "";

$(".toolbar > ul.tools").append(button);

//Add to queue $("#queue-add").click(function {

queue.addPage(mw.config.get("wgPageName"), function {

alert("Added " + mw.config.get("wgPageName") + " to the queue!"); });   });

//Remove from queue $("#queue-remove").click(function {

queue.removePage(mw.config.get("wgPageName"), function {

alert("Removed " + mw.config.get("wgPageName") + " from the queue!"); });   }); };

$(document).ready(function {

queue.addButtons; });