[DEV] Auto-Save for post/pm (javascsript only)

A place for Extension Authors to post and receive feedback on Extensions still in development. No Extensions within this forum should be used within a live environment!
Get Involved
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: Extensions Development rules

IMPORTANT FOR NEEDED EVENTS!!!
If you need an event for your extension please read this for the steps to follow to request the event(s)
Post Reply
ntvy95
Registered User
Posts: 69
Joined: Wed Jun 10, 2015 12:58 pm

[DEV] Auto-Save for post/pm (javascsript only)

Post by ntvy95 » Tue Jul 14, 2015 3:28 am

Download / Repository: GitHub

How to use: The default time interval is 5 seconds, it means that every 5 seconds, the editing posts / pms will be auto-saved once. You type your words in forum editor then every 5 seconds, your post will be saved into HTML5 local storage of the browser. If you click on Insert Auto Saved Post / Insert Auto Saved PM then you will retrieve your post at the time 5 seconds before.

Image
Image
(and one more screenshot for Insert Auto Saved PM that I am currently not be able to upload it)

From http://diveintohtml5.info/storage.html:
So what is HTML5 Storage? Simply put, it’s a way for web pages to store named key/value pairs locally, within the client web browser. Like cookies, this data persists even after you navigate away from the web site, close your browser tab, exit your browser, or what have you.
It does not work when the browser does not support data caching: No error or warning occurs, it is just that the data is not saved.

Remeber that, if you seriously want to retrive your post by clicking on Insert Auto Saved Post / Insert Auto Saved PM, DO IT QUICKLY IN 5 SECONDS. Or else, your post will be lost due to the auto-save mechanism.

Some modifications to extension you may want to do: You can edit the saving time interval in:
[ROOT]\ext\ntvy95\autosave\styles\prosilver\template\event
In both ext_quickreply_editor_buttons_custom_tags_before.html and posting_editor_buttons_custom_tags_before.html, find:

Code: Select all

}, 5000);
5000 here is 5s, it means that every 5 seconds the post is being saved once. You can change it into any number you want.

Other notes:

I have made this extension based on this suggestion:
cYbercOsmOnauT wrote:Wouldn't it be better to solve this kind of stuff without the db but locally by using LocalStorage of the modern browsers? http://www.jstorage.info/
For auto-saving posts into database, please visit Post Crash Protection extension.

I am pretty sure that it will work with QuickReply extension but not the default one.
Last edited by ntvy95 on Mon Mar 05, 2018 12:41 pm, edited 7 times in total.

User avatar
LordOfFlies
Registered User
Posts: 63
Joined: Tue Jul 14, 2015 6:55 am
Name: Matěj Štágl
Contact:

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by LordOfFlies » Tue Jul 14, 2015 6:57 am

Hi and thanks for nice extension.

Can you explain me this?
You can play around the Insert Auto Saved Post or Insert Auto Saved PM button on the editor a little to understand how it works.
I don´t really understand how your extension works.

User avatar
LordOfFlies
Registered User
Posts: 63
Joined: Tue Jul 14, 2015 6:55 am
Name: Matěj Štágl
Contact:

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by LordOfFlies » Tue Jul 14, 2015 7:03 am

Hi, could you make this abbc3 compactible? Thanks.

User avatar
cYbercOsmOnauT
Registered User
Posts: 362
Joined: Wed Jun 16, 2004 8:22 am
Location: Goettingen, Germany
Name: Tekin Birdüzen

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by cYbercOsmOnauT » Tue Jul 14, 2015 8:19 am

Thumbs up! Here some more suggestions:

https://github.com/ntvy95/koutogima/blo ... efore.html

Why don't you use jQuery in the lines 12 & 13?
In line 19 (same in 21) you select the message node to get its value. You do this every five seconds. Thats not needed. Select the message node once at the start and use this object to get/set the value.

I would prefer using a position below the message textarea so that the selectors always have a hit. posting_editor_message_after would be my choice. And the JS would look something like this

Code: Select all

var copy,
  message_node = $('#message'),
  message_text;
function imgcopy(){
<!-- IF not S_PRIVMSGS -->
  copy = $.jStorage.get('post_text', "");
<!-- ELSE -->
  copy = $.jStorage.get('pm_text', "");
<!-- ENDIF -->
  message_text = message.val() + copy;
  message.val(message_text);
  message.focus();
  return false;
}
setInterval(function() 
{
<!-- IF not S_PRIVMSGS -->
  $.jStorage.set('post_text', message.val());
<!-- ELSE -->
  $.jStorage.set('pm_text', message.val());
<!-- ENDIF -->
}, 5000);
phpBB-installation and reparation. Prof. PHP coding with function guarantee. Just contact me at: t.birduezen@web-coding.eu.
Ex-German Support Team Member | phpBB Development Environment

User avatar
ViolaF
Registered User
Posts: 1452
Joined: Tue Aug 14, 2012 11:52 pm

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by ViolaF » Tue Jul 14, 2015 10:16 pm

what is, when the browser crashes?
then all is lost, or?
other question, this part-of-ext have the same credit as PCP?

User avatar
draky
Registered User
Posts: 247
Joined: Tue Dec 10, 2002 2:04 pm
Location: France
Name: Gilles W.
Contact:

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by draky » Tue Jul 14, 2015 10:25 pm

You can save draft if you are afraid of browser crashing ;)

ntvy95
Registered User
Posts: 69
Joined: Wed Jun 10, 2015 12:58 pm

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by ntvy95 » Wed Jul 15, 2015 1:53 am

LordOfFlies wrote:Hi and thanks for nice extension.

Can you explain me this?
You can play around the Insert Auto Saved Post or Insert Auto Saved PM button on the editor a little to understand how it works.
I don´t really understand how your extension works.
I have updated my first post.
LordOfFlies wrote:Hi, could you make this abbc3 compactible? Thanks.
I will take a look at it when I have time. (I am now busy) :D
cYbercOsmOnauT wrote:Thumbs up! Here some more suggestions:

https://github.com/ntvy95/koutogima/blo ... efore.html

Why don't you use jQuery in the lines 12 & 13?
In line 19 (same in 21) you select the message node to get its value. You do this every five seconds. Thats not needed. Select the message node once at the start and use this object to get/set the value.

I would prefer using a position below the message textarea so that the selectors always have a hit. posting_editor_message_after would be my choice. And the JS would look something like this

Code: Select all

var copy,
  message_node = $('#message'),
  message_text;
function imgcopy(){
<!-- IF not S_PRIVMSGS -->
  copy = $.jStorage.get('post_text', "");
<!-- ELSE -->
  copy = $.jStorage.get('pm_text', "");
<!-- ENDIF -->
  message_text = message.val() + copy;
  message.val(message_text);
  message.focus();
  return false;
}
setInterval(function() 
{
<!-- IF not S_PRIVMSGS -->
  $.jStorage.set('post_text', message.val());
<!-- ELSE -->
  $.jStorage.set('pm_text', message.val());
<!-- ENDIF -->
}, 5000); 
Thank you very much for your suggestion (to be honest, I am new to these kinds of things). :) I will look at it when I have more time. :D
ViolaF wrote:what is, when the browser crashes?
then all is lost, or?
other question, this part-of-ext have the same credit as PCP?
I have updated the first post the authors I have based on.
I am not sure if your post is still being stored after the browser crashes. In that case, you can use PCP for 60s autosave time interval in conjunction with this extension.

The time interval like 60s or 5s of course can be changed to fit your forum's situation.
draky wrote:You can save draft if you are afraid of browser crashing ;)
I have updated this extension so that it can work with PCP.

User avatar
cYbercOsmOnauT
Registered User
Posts: 362
Joined: Wed Jun 16, 2004 8:22 am
Location: Goettingen, Germany
Name: Tekin Birdüzen

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by cYbercOsmOnauT » Wed Jul 15, 2015 11:24 am

LocalStorage is not deleted on Reboot, Browser closing or crash. AFAIK Firefox saves them inside a local sqlite file.
phpBB-installation and reparation. Prof. PHP coding with function guarantee. Just contact me at: t.birduezen@web-coding.eu.
Ex-German Support Team Member | phpBB Development Environment

User avatar
ViolaF
Registered User
Posts: 1452
Joined: Tue Aug 14, 2012 11:52 pm

Re: [DEV] Auto-Save for post/pm (javascsript only)

Post by ViolaF » Wed Jul 15, 2015 12:17 pm

normally many people, also i use always ccleaner min. 3 times a day and more to delete
the so-named "compact databases" from all browsers. then it is up and away, or?

Post Reply

Return to “Extensions in Development”