Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Jul 16, 2011 18:25:04 GMT -8
Browsers Tested: firefox 3.6.18, IE 9, Chrome 12.072.122 Description: This code is geared toward people like RPG posters who need to invest a good amount of time an thought into creating a single post. The process can take hours if not days to get the wording right and usually involves saving multiple drafts for later refinement. With this code those saved drafts are accessible whenever that moment of inspiration hits by allowing drafts to be saved to your inbox then just as easily restored at the point where you left off. With code installed a new "Finish Later" button is added to the posting form which will send what you've written so far to your PM inbox, when you're ready just go to your inbox and click on the draft to continue where you left off. <script type="text/javascript"> <!-- (function(opts){ //Post Draft (GLOBAL FOOTER) if(pb_username == 'Guest')return; var f,g,j,k,m if((f=document.postForm)){ if(f.to && /Draft:/.test(f.subject.value) && /post=0 time=\d+\]/.test(f.message.value) && /^pm(send|preview)/.test(pb_action)){ m=RegExp.$1; switch(m){ case "preview": j = f.subject.parentNode.parentNode.parentNode.firstChild; j.insertRow(1).insertCell(-1); j.rows[0].getElementsByTagName('b')[0].innerHTML = "Save Post Draft"; j.rows[1].cells[0].colspan=2; j.rows[1].cells[0].className = "windowbg"; j.rows[1].cells[0].innerHTML = '<center>Click the Save Draft button to continue or use your browser\'s BACK button to return to previous page' +'<br><input type="submit" onclick="document.postForm.nextaction.value=\'post\';" value="Save Draft" ></center>'; for(k = 2; k<j.rows.length;k++) j.rows[k].style.display = "none"; k = f; while(f=f.previousSibling) if(f.nodeName=='TABLE' && f.className=='bordercolor' && /action=viewprofile/.test(f.innerHTML)){ f.style.display = "none"; }else if(f.nodeName == 'A' && f.className == 'nav'){f.nextSibling.data = f.nextSibling.data.replace(/Preview Personal Message/,"Confirm Save Draft"); break;} break; case "send": j = f.subject.parentNode.parentNode.parentNode; j.rows[0].getElementsByTagName('b')[0].innerHTML = "Load Post Draft"; j=f.subject.form.previousSibling; while(j=j.previousSibling){if(j.href && /action=pm/.test(j.href)){j.innerHTML="Post Drafts";j.nextSibling.data=" ::Load Draft";break}} f.message.value = f.message.value.replace(/^\[quote\]/,'').replace(/\[\/quote\]\[\/quote\]$/,''); m = f.message.value.match(/\[quote author=\w+ board=(\w+)(?:&icon=(\w+))? thread=(\d+) post=0 time=\d+\]/); f.message.value = f.message.value.replace(m[0],''); f.subject.value = f.subject.value.split('Draft:')[1]; f.to.parentNode.parentNode.style.display="none"; f.id.disabled = f.view.disabled = f.to.disabled = true; f.action.value = "post2"; f.subject.parentNode.insertBefore(document.createElement('span'),f.subject).innerHTML = '<input type="hidden" name="board" value="'+m[1]+'" ><input type="hidden" name="icon" value="'+ (m[2]?m[2]:'xx') +'" > <img border="0" width="1" height="1" src="/?action=pmview&view=1&id='+f.id.value+'" />'; //lazy, force standard icon if(Number(m[3]))f.subject.previousSibling.innerHTML += '<input type="hidden" name="thread" value="'+m[3]+'" >'; for(g=f.elements.length-1;g>0;g=g-1) if(f.elements[g].value == "Send Personal Message") {f.elements[g].value = "Post " + (m[2]?"Reply":"Message");break;} } }//else if(f.board){ j = f.elements[f.elements.length-1]; j = j.parentNode.insertBefore(document.createElement('span'),j); j.innerHTML = '<input type="button" value="Finish Later" id="draftbutton">' j.lastChild.onclick = function(){ if(this.form.message.value && this.form.subject.value){ this.form.action.value = "pmsend2"; this.form.nextaction.value = "preview"; this.form.subject.value = "Draft:" + this.form.subject.value.replace(/^((Draft|Re):)+/i,'') this.form.id.removeAttribute('disabled'); this.form.to.removeAttribute('disabled'); this.form.message.value = '[quote author='+pb_username +' board=' + this.form.board.value + (this.form.icon?'&icon=' + this.form.icon.value:'') + ' thread=' +(this.form.thread?this.form.thread.value:0) + ' post=0 time=' + (""+(+new Date)).substr(0,10) + ']' + this.form.message.value + '[/quote]'; this.form.submit() //info: submit handlers bypassed here }else alert('Cannot save\nMake sure subject and message are filled in') } j = j.appendChild(document.createElement('span')); if(!f.to)j.innerHTML += '<input type="hidden" name="to" value="'+pb_username+'" disabled="disabled" >' if(!f.id)j.innerHTML += '<input type="hidden" name="id" value="" disabled="disabled" > '; } }else if(/^(pm(view)?)/.test(pb_action)){ switch(RegExp.$1){ case "pm": if(/\bview=1/.test(location.href) || !/\bview=/.test(location.href)){ for(f = document.pmForm.elements,g=0;g<f.length;g++){ if(/^delete-/.test(f[g].name) && (k = f[g].parentNode.parentNode) && /Draft:/.test(k.cells[2].innerHTML)){ k.cells[1].getElementsByTagName('img')[0].src = opts.drafticon; j = k.cells[2].getElementsByTagName('a')[0]; j.innerHTML = j.innerHTML.replace(/(Draft:)+/,''); j.href = "/?action=pmsend&to="+pb_username+"&view=1&q"+"uote="+f[g].name.split('-')[1]; if(/&user=(\w+)/.test(k.cells[3].getElementsByTagName('a')[0].href) && RegExp.$1 != pb_username){ j.onclick = function(){pb_bubble=1; if(!confirm('This draft was created by a different account, do you wish to proceed?')){ setTimeout("pb_bubble=0;",0); return false;}} }else j.onclick = function(){pb_bubble=1; return true;} k.cells[2].onclick = function(){if(!pb_bubble){var a = this.getElementsByTagName('a')[0]; if(a.onclick())location.href = a.href;}} } } } case "pmview": } } })({drafticon:"http://i52.tinypic.com/34q8dwl.gif"}); // --> </script> Updates:- Jul, 18, 2011 -
- put warning if about to use a draft which was created by another account (remote possibility)
- fixed cell click on PM listing page which didn't direct to resume posting page like the link click did.
- Aug, 2, 2011 - Added a workaround to mark a draft as read once used.
- Oct 13, 2012 - Addressed conflict with codes that hid SUBJECT or TO field (such as the code on Wormo's site that gives PM distribution lists in a textarea) . Also escaped unintentional quote entity in redirected urls
|
|
|
Post by Wormopolis on Jul 16, 2011 22:13:27 GMT -8
much better then the idea I had of using a board to store all the drafts. I was also going to incorporate a rememberance system that gave them a list of all the drafts they currently had going and provide a quick list to get back to them (should they fall to later pages)
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Jul 18, 2011 8:21:01 GMT -8
much better then the idea I had of using a board to store all the drafts. I was also going to incorporate a rememberance system that gave them a list of all the drafts they currently had going and provide a quick list to get back to them (should they fall to later pages) I thought of the memory system as well but it didn't fit in with the primary objective of keeping that data device independent, by that I mean you could start writing a post on your home computer, save a draft and then pickup where you left off on a totally different computer or device. If that data was saved locally then it would not be available on that other computer (admittedly not operation critical), the trade-off is if your draft happens to be on page 3 then you'll need to locate it the same way you need to locate an old PM.
|
|
|
Post by Streamstrider on Jul 18, 2011 12:57:24 GMT -8
I really like the idea for this. There have been so many times in which I've copied my unfinished post into a PM to myself, but sometimes it just seems to be a hassle. Is this code ready for testing?
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Jul 18, 2011 13:56:39 GMT -8
Great work i do have a question though. When you actually post the post you still have a new message in your inbox. Any way to fix that? just a suggestion.
|
|
|
Post by Wormopolis on Jul 18, 2011 21:08:35 GMT -8
I really like the idea for this. There have been so many times in which I've copied my unfinished post into a PM to myself, but sometimes it just seems to be a hassle. Is this code ready for testing? all codes in submission area are available for use, with the caveat that there might be more bugs then regular releases. basically, give it a try and report back anything you find out of the ordinary or suggestions you may have for refinement.
|
|
|
Post by Streamstrider on Jul 18, 2011 21:33:04 GMT -8
Alright. I'll be opening up a forum soon, so I'll give it a shot then. I'll let you know how it goes. XD
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Jul 23, 2011 23:45:28 GMT -8
Great work i do have a question though. When you actually post the post you still have a new message in your inbox. Any way to fix that? just a suggestion. Since there is no way I know of to mark a single PM as read except by viewing then it would have to be manually marked as read when viewing inbox or a two-step process reinserted in the code (you'll see I inadvertently left the remnants of the "pmview" switch statement in there), first step goes to pmview then second step to resuming post, either way it's going to be an extra click
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Aug 2, 2011 19:43:49 GMT -8
I thnk I've come up with a solution to the unread pm problem, I've added the red to this line:
f.subject.parentNode.insertBefore(document.createElement('span'),f.subject).innerHTML = '<input type="hidden" name="board" value="'+m[1]+'" ><input type="hidden" name="icon" value="'+ (m[2]?m[2]:'xx') +'" > <img border="0" width="1" height="1" src="/?action=pmview&view=1&id='+f.id.value+'" />';
This however needs further testing in a broad range of browsers to see if it holds up as [CB] as well as being TOS compliant.
|
|
|
Post by Streamstrider on Sept 4, 2011 18:56:30 GMT -8
We are currently testing this code on my forum here, and I will let you know if there are any problems.
I do have one thought, however. When it returns you to posting the reply, is there any way possible to keep the previous posts of the topic below the reply area? (When you post a reply, all the prior posts on the page are usually listed below the posting form.) I am using Firefox, the most recent version I believe.
|
|
|
Post by Streamstrider on Sept 25, 2011 16:24:48 GMT -8
Currently the code is not working. I'm not sure if it's a conflict with another code or what. XD Link is in previous post.
|
|
|
Post by Wormopolis on Dec 25, 2011 1:36:45 GMT -8
verifying that it didnt work here on WC either... but that could be because I have MANY code that could conflict
|
|