Jump to content

User:GeorgeMoney/UserScripts/savecookie

From Wikipedia, the free encyclopedia

//

//COOKIE SAVING

function changemsg(msg,color) {
if(!color) {
var color = 'green';
}
var txtr = "editsts";
var div = document.getElementById(txtr);
div.innerHTML = '<div style="font-weight:bold; font-size:bigger;border:3px solid '+color+';background:honeydew;padding:3px;"><font color="'+color+'">'+msg+'</font></div>';

}

if (window.location.href.indexOf('action=edit') != -1 || window.location.href.indexOf('action=submit') != -1) {

addOnloadHook(function(){

s='<input id="wpSave" name="wpSave" type="submit" tabindex="5" value="Save page" accesskey="s" title="Save your changes [alt-s]" />\n<input id="wpPreview" name="wpPreview" type="submit" tabindex="6" value="Show preview" accesskey="p" title="Preview your changes, please use this before saving! [alt-p]" />\n<input id="wpDiff" name="wpDiff" type="submit" tabindex="7" value="Show changes" accesskey="v" title="Show which changes you made to the text. [alt-v]" />\n<br>';
s+='<input type="button" onclick="if(escape(document.getElementById(\'wpTextbox1\').value).length > 4038) { changemsg(\'Cannot save to cookie. Reason: Page size too large to be saved in cookie, sorry! It must be below 4038 characters in length, and your text is \'+escape(document.getElementById(\'wpTextbox1\').value).length+\' characters, which is \'+ (escape(document.getElementById(\'wpTextbox1\').value).length - 4038) + \' characters too many!\', \'red\'); alert(\'Error! Page size too large to be saved in cookie, sorry! It must be below 4038 characters in length, and your text is \'+escape(document.getElementById(\'wpTextbox1\').value).length+\' characters, which is \'+ (escape(document.getElementById(\'wpTextbox1\').value).length - 4038) + \' characters too many! \');  } else { createCookie(\'SAVEDWIKIPAGE-'+wgPageName+'\', escape(document.getElementById(\'wpTextbox1\').value), 365); changemsg(\'Cookie saved!\'); }" value="save to cookie" />  \n';
s+='<input type="button" onclick="var gh = unescape(readCookie(\'SAVEDWIKIPAGE-\'+document.getElementById(\'cookform\').value.replace(/\\s/g, \'_\'))); if(gh !== \'null\') { document.getElementById(\'wpTextbox1\').value = gh; changemsg(\'Cookie from page \'+document.getElementById(\'cookform\').value+\' successfully loaded into Edit Box\'); } else { changemsg(\'No cookie exists from page \'+document.getElementById(\'cookform\').value+\' \', \'red\'); }" value="load from cookie:" /><input type="button" onclick="eraseCookie(\'SAVEDWIKIPAGE-\'+document.getElementById(\'cookform\').value.replace(/\\s/g, \'_\')); changemsg(\'Cookie from page \'+document.getElementById(\'cookform\').value+\' deleted\');" value="delete cookie" />';
s+='<input type="text" value="'+wgPageName.replace(/\_/g, ' ')+'" id="cookform" size="40" />\n';
s+=' <input type="button" value="show all cookies" onclick="alert(document.cookie); changemsg(\'Cookies: \'+document.cookie);" /><input type="button" value="count characters" onclick="if(escape(document.getElementById(\'wpTextbox1\').value).length > 4038) { var extra = \'Which is too large to save into a cookie. Cookies can only handle 4038 characters. You have \' + (escape(document.getElementById(\'wpTextbox1\').value).length - 4038) + \' characters more than the limit. \'; } else { var extra = \'\'; } var msg = \'Characters in editbox (after converted to cookie encoded form): \'+ escape(document.getElementById(\'wpTextbox1\').value).length + \' characters. \'+extra; changemsg(msg); " />\n';
s+='<br><div id="editsts"> </div>\n';
    var divs = document.getElementsByTagName('div');
    for (i=0; i<divs.length; i++) {
	   if (divs[i].className == 'editButtons') {
	     divs[i].innerHTML = s;
	   }
	}

});

}

//END

//