Feedback
ยท
Roleplay typing buffer autosave (in review)
Given that only a single character can be connected to any particular roleplay at a time, and things can happen in the interim - connections fail, tabs get closed accidentally, soforth - I propose that the typing buffer have a server-side auto-save feature akin to the way Google Docs passively saves changes periodically in realtime. I'd suggest the following implementation:
-
Server-side storage occurs as one buffer per character, per roleplay.
-
Add a Javascript variable, effectively a boolean, to store whether the input box has been changed since last buffer sync (or page load), default false. It is set true when the contents of the box changes.
-
Every thirty seconds (or however often as deemed necessary) check that variable, and if true, sync the contents of the text input box to the server. Then set the variable false.
-
On page load, check if the typing box is actually empty before opening the connection (i.e. it hasn't already been populated, say, by client-side tab restoration). If it isn't, don't load the buffer, and empty it server-side. Otherwise, populate the input box with its content.
endorsement points: 145
created: 17 March 17 at 09:20 AM (build: 8/21/2016 1:52 AM beta)
So it turns out this is fully implementable using HTML5 local storage and incredibly hacky DOM manipulation. This is functional as either a bookmarklet or directly pasted into the debugger.
WA, kill me now.
litpho_type_buffer.js
//Litphoria typing buffer saver (litpho_type_buffer.js)
//Hacky and framework-averse but functional and relatively safe
//NB: interferes with typing indicator, sue me
var litphoria_type_buffer_textarea = null; //the editbox DOM element itself to manipulate
var litphoria_type_buffer_id = null; //the id of the chat or roleplay
var litphoria_type_buffer_type = null; //whether this is a chat or a roleplay
var litphoria_type_buffer_storage = null; //the name of the HTML5 storage key value where this RP's buffer exists
var litpho_type_buffer_poll_rate = 1000; //Polling interval in ms: probably an event-driven way of doing this but while we're being hackery let's go the whole hog
//Sets all the variables we need above to get up and running
function litphoria_type_buffer_init(){
//For the love of god if there is a better way of populating these replace these lines
var split_url = window.location.href.split("/");
if(!isNaN(parseInt(split_url[4])&&(split_url[3]=="roleplay" || split_url[3]=="chat")))
{ //Half-arsed validation
litphoria_type_buffer_id = split_url[4];
litphoria_type_buffer_type = split_url[3];
litphoria_type_buffer_init_textarea();
return true;}
else {
alert("Litphoria type buffer extension failed to initialize: bad url (not a roleplay?)");
return false;} //Nope out, do not pass go, do not collect $200
}
//Awful hack the first: try to work out if the page has loaded without knowing the framework state
//Fortunately, this script literally only cares about the state of the editbox
//So we can basically run a loop until we find it
//WA I am so sorry
function litphoria_type_buffer_init_textarea(){var textarea = null;
try {
textarea = document.getElementsByTagName("li-input")[0].childNodes[1]; } //MONSTROUSITY
catch (err) //Lazy as shit but whatever
{setTimeout(litphoria_type_buffer_init_textarea,litpho_type_buffer_poll_rate);}
if(textarea != null) {litphoria_type_buffer_textarea = textarea; litphoria_type_buffer_runner();}
}
function litphoria_type_buffer_runner(){
litphoria_type_buffer_storage = "litphoria" + "/" + litphoria_type_buffer_type + "/" + litphoria_type_buffer_id + "/buffer";
litphoria_type_buffer_textarea.value = localStorage.getItem(litphoria_type_buffer_storage);
setInterval(litphoria_type_buffer,litpho_type_buffer_poll_rate);
}
function litphoria_type_buffer(){
document.getElementsByTagName("li-typing-indicator")[0].childNodes[0].innerHTML = "";
if(litphoria_type_buffer_textarea.value!=localStorage.getItem(litphoria_type_buffer_storage)){
localStorage.setItem(litphoria_type_buffer_storage,litphoria_type_buffer_textarea.value);
//This is so incredibly tacked on
document.getElementsByTagName("li-typing-indicator")[0].childNodes[0].innerHTML += " [Buffer Saved] ";}
}
litphoria_type_buffer_init();
Got something to say?
Why don't you register and participate?
Litphoria has a unique community feedback system, where the community decides what profile options are available, and what order new features are developed.
I want my voice heard!
tell me more!