User:Abdullah5599/textmacros.js

importScript('User:Abdullah/SidebarFunctions.js');

// Source: http://www.quirksmode.org function createCookie(name,value,days) { if (days) { var date = new Date; date.setTime(date.getTime+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString; }	else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }

function readCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); }	return null; }

function eraseCookie(name) { createCookie(name,"",-1); }

function createMacroBox { var mContainer = document.createElement('div'); mContainer.setAttribute('id', 'mContainer'); mContainer.style.position = 'fixed'; mContainer.style.bottom = '0'; mContainer.style.right = '0'; mContainer.style.border = '1px solid #426787'; mContainer.style.background = '#ccc'; mContainer.style.width = '200px'; mContainer.style.padding = '5px'; document.getElementById("content").appendChild(mContainer);

var mHeader = document.createElement('span'); mHeader.style.color = 'black'; mHeader.innerHTML = "Macros"; mContainer.appendChild(mHeader);

var mText = document.createElement('textarea'); mText.setAttribute('id', 'mText'); mText.setAttribute('cols', '10'); mText.setAttribute('rows', '10'); mText.setAttribute('style', 'word-wrap:break-word'); mContainer.appendChild(mText);

var mSave = document.createElement('button'); mSave.innerHTML = "Save"; mSave.setAttribute('onclick','saveMacro'); mContainer.appendChild(mSave);

var mHide = document.createElement('button'); mHide.innerHTML = "Hide"; mHide.setAttribute('onclick','hideMacro'); mContainer.appendChild(mHide);

loadMacro(mText); }

createMacroBox;

function loadMacro(textarea){ var macrolist = readCookie('macros'); textarea.value = macrolist; }

function saveMacro{ var textarea = document.getElementById("mText"); createCookie('macros',textarea.value); alert('Saved'); }

function hideMacro{ document.getElementById("mContainer").style.display = "none"; // Set cookie to hide and save macro }