Allegro.cc - Online Community

Allegro.cc Forums » The Depot » A.cc Extension: Post Recovery

This thread is locked; no one can reply to it. rss feed Print
A.cc Extension: Post Recovery
ImLeftFooted
Member #3,935
October 2003
avatar

New a.cc javascript extension. Adds an emergency backup droplist mechanism in case you accidentally lose that post you worked oh so hard on!

To install, select all of this text (make sure to scroll down!) and copy it to your clipboard (control + C):

1// Post saver app Version 0.2
2//
3// namespace: cache
4 
5// The cache of your post will be updated every n number of seconds.
6var cache_updateSeconds = 15;
7 
8// The textarea that contains the post being written.
9var cache_textarea = null;
10 
11function cache_revert(tag)
12{
13 cache_textarea.value = unescape(cache_readCookie(tag.getAttribute("name")));
14}
15 
16function cache_insertControls()
17{
18 var tr = document.getElementById("tr-submit");
19 var div = document.createElement("div");
20 tr.insertBefore(div, null);
21 
22 var html = '<select><option>Emergency Backups</option>';
23 
24 for(var i = 1; i <= 5; i++) {
25
26 var cache = cache_readCookie("post-cache" + i);
27 
28 if(cache && cache.toString().length)
29 html += '<option onclick="cache_revert(this)" name="post-cache' + i + '">' + cache.substr(0, 15) + ' ...</option>';
30 }
31 
32 html += '</select>';
33 
34 div.innerHTML = html;
35}
36 
37function cache_delayedUpdate(textarea)
38{
39 setTimeout(function() { cache_update(textarea); }, cache_updateSeconds * 1000);
40}
41 
42function cache_update(textarea)
43{
44 if(textarea.value != "") {
45 
46 var curCacheLoc = cache_readCookie("curCacheLoc");
47 
48 cache_createCookie(curCacheLoc, escape(textarea.value));
49 }
50 
51 cache_delayedUpdate(textarea);
52}
53 
54function cache_getEditArea()
55{
56 return document.getElementsByTagName("textarea")[0];
57}
58 
59function cache_load()
60{
61 /* We must be in the forum section */
62 if(window.location.href.indexOf('forums') == -1)
63 return;
64
65 /* We must be on a page that contains post textareas */
66 if(window.location.href.indexOf('thread') == -1 && window.location.href.indexOf('edit-post') == -1 && window.location.href.indexOf('new-thread') == -1)
67 return;
68 
69 var editArea = cache_getEditArea();
70 
71 if(editArea == null)
72 return;
73 
74 cache_textarea = editArea;
75 
76 cache_insertControls();
77 
78 var curCacheLoc = cache_readCookie("curCacheLoc");
79 
80 /* Too lazy to do real string parsing */
81 if(curCacheLoc == null || curCacheLoc == "post-cache3")
82 cache_createCookie("curCacheLoc", "post-cache1");
83 else if(curCacheLoc == "post-cache1")
84 cache_createCookie("curCacheLoc", "post-cache2");
85 else if(curCacheLoc== "post-cache2")
86 cache_createCookie("curCacheLoc", "post-cache3");
87 
88 cache_delayedUpdate(textarea);
89}
90 
91doc.add_onLoad(cache_load);
92 
93// Cookies!
94// {
95 function cache_createCookie(name,value,days) {
96
97 if(days == null)
98 days = .5;
99
100 var date = new Date();
101 date.setTime(date.getTime()+(days*24*60*60*1000));
102 var expires = "; expires="+date.toGMTString();
103 
104 document.cookie = name+"="+value+expires+"; path=/";
105 }
106
107 function cache_readCookie(name) {
108 var nameEQ = name + "=";
109 var ca = document.cookie.split(';');
110 for(var i=0;i < ca.length;i++) {
111 var c = ca<i>;
112 while (c.charAt(0)==' ') c = c.substring(1,c.length);
113 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
114 }
115 return null;
116 }
117
118 function cache_eraseCookie(name) {
119 ban_createCookie(name,"",-1);
120 }
121// }

Then navigate to the extensions page and select the bottom text box with your mouse and paste (control + V). You must be logged in to navigate to this page.

Click save and enjoy!

{"name":"591558","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/174629522748c6d1fda2ba043775cc0b.png","w":713,"h":559,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/1\/7\/174629522748c6d1fda2ba043775cc0b"}591558
Changelog Version 2: <ul> <li>Upped default recache time to 15 seconds.</li> <li>Stopped cache from updating on load.</li> <li>Lowered number of post caches to three (to save cookie space).</li> <li>Lowered cookie storage time to 12 hours.</li> </ul>

HoHo
Member #4,534
April 2004
avatar

It doesn't seem to work with Konqueror :P
Though it worked fine in FF.

Quite a nice thing. I wish I had such a thing some times after pressing the wrong button after writing a post for half an hour.

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

Marco Radaelli
Member #3,028
December 2002
avatar

I haven't tried it yet, but will this be potentially convertible in a browser addon (so it can be used on other places) or it relies on A.cc-specific features to work?

LennyLen
Member #5,313
December 2004
avatar

Works fine with Opera, even though it's not needed.

ImLeftFooted
Member #3,935
October 2003
avatar

Quote:

I haven't tried it yet, but will this be potentially convertible in a browser addon (so it can be used on other places) or it relies on A.cc-specific features to work?

I've never written a FF add-on, so I wont be doing it. Its definitely possible though.

That could be nice for when you submit a post and you're not logged in. Though you can already do a refresh / repost trick there.

ReyBrujo
Moderator
January 2001
avatar

As far as I know, the crash recovery system in FF 2.0 should keep the text from textareas when you return from a crash. At least, everytime Firefox crashes, it saves my text.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

ImLeftFooted
Member #3,935
October 2003
avatar

Quote:

As far as I know, the crash recovery system in FF 2.0 should keep the text from textareas

If you accidentally press the back button, FF loses the text.

Thomas Fjellstrom
Member #476
June 2000
avatar

Konqueror doesn't have an issue with pressing back and losing the text.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

HoHo
Member #4,534
April 2004
avatar

... but it does loose text when you refresh your page :P

__________
In theory, there is no difference between theory and practice. But, in practice, there is - Jan L.A. van de Snepscheut
MMORPG's...Many Men Online Role Playing Girls - Radagar
"Is Java REALLY slower? Does STL really bloat your exes? Find out with your friendly host, HoHo, and his benchmarking machine!" - Jakub Wasilewski

Rampage
Member #3,035
December 2002
avatar

Quote:

If you accidentally press the back button, FF loses the text.

That has happened to me, but my posts are never so long that I can't remember them.

-R

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

... but it does loose text when you refresh your page :P

Then you're just STUPID. :P

Also, this won't work that well for large posts. Cookies are limited to a few KB.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

kentl
Member #2,905
November 2002

Nice work Dustin. I found a similar Greasemonkey script which works with all textboxes here.

Johan Halmén
Member #1,550
September 2001

You shouldn't spend half an hour on a post. If you need that, make a homepage instead.

IE loses my posts, Opera and Safari don't.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Years of thorough research have revealed that the red "x" that closes a window, really isn't red, but white on red background.

Years of thorough research have revealed that what people find beautiful about the Mandelbrot set is not the set itself, but all the rest.

CGamesPlay
Member #2,559
July 2002
avatar

Quote:

You shouldn't spend half an hour on a post. If you need that, make a homepage instead.

You're confusing forums where actual discussion happens and chat rooms where people fling one-liners around.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Billybob
Member #3,136
January 2003

Quote:

You shouldn't spend half an hour on a post.

Yes you should. If you're going around the net looking for helpful links, testing code, reading up some information, etc, etc all to make your post information rich, you'd be surprised how long it can take to finish a single post.

Go to: