Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Sept 21, 2010 18:56:13 GMT -8
How would i insert stuff into the posting page. I am trying to write a code for someone but i don't know how to do it. What i am trying to do is have it so that on the posting page and the quick reply there is automatically ubbc. I just need to know how to insert the info into the textarea...
|
|
|
Post by Wormopolis on Sept 21, 2010 22:23:53 GMT -8
automatic UBBC?
the textarea where someone types the messge is best found by:
document.postForm.message.value
so if you want to force something in there, just set the value
document.postForm.message.value="Hello";
however if you want to preserve what is already there, and encapsulate it, then you want to treate it like a variable:
document.postForm.message.value = "[b][i][size=3]" + document.postForm.message.value + "[/size][/i][/b]"
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Sept 22, 2010 13:39:16 GMT -8
And how would i get that to work on the quick reply? oh and also how would i insert <br />'s?
|
|
|
Post by Wormopolis on Sept 23, 2010 16:31:32 GMT -8
Quick reply is a bit trickier to find since PB doesnt give it a linkable name. usually if you do a document.getElementsByTagName('textarea') and scan backwards from the last one, you can find it quickly. it also has the name "message", but the form it is contained in doesnt have a name to reference.
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Sept 24, 2010 13:03:09 GMT -8
ok this code might be a bit out for me...i still don't understand what you said...about the scanning backwards
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Sept 24, 2010 16:57:09 GMT -8
ok this code might be a bit out for me...i still don't understand what you said...about the scanning backwards Using getElementsByTagName('textarea') will return a list of all the text areas on the page. What Wormo is saying is since the quick reply area is at the bottom of the page you would reach it faster by testing from the end of the list rather than the beginning. As I'm sure you're aware , looping, although the most stable way of identifying the element you seek when that element cannot be directly addressed, is the slowest method so using the fact that quick reply is by default always at bottom allows you to speed up your code. As for the nameless form used for the quick reply you can use a DOM Level0 property of which I suspect many newer coders are not aware. Every element within a form has a property named form that holds a reference to the form it is associated with so once you locate the text area all you need to do is look at the form property of that text area to gain reference to the nameless form.
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Sept 24, 2010 17:40:30 GMT -8
ok....i am sick and not able to think well...also i am starting to realize that i can't code well and really don't understand it when people try to explain so can i turn this into a request? Can you make a code that inserts something into the reply area and has two <br>s in between the front and back?
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Sept 24, 2010 21:21:03 GMT -8
You would need to define what the nature of the "automatic UBBC" is...
If it's to add some some kind of styling to whatever the user types then it obviously would need to hook the submission event so it would know when user has completed whatever she was typing.
On the other hand, if it's to insert some kind of UBBC prior to when the user starts typing that would be a different code.
And if your intent is to blindside the user while they are typing then that would require a different code
|
|
|
Post by Wormopolis on Sept 24, 2010 22:25:16 GMT -8
As for the nameless form used for the quick reply you can use a DOM Level0 property of which I suspect many newer coders are not aware. Every element within a form has a property named form that holds a reference to the form it is associated with so once you locate the text area all you need to do is look at the form property of that text area to gain reference to the nameless form. which is an awesome way of getting the form AFTER you found the element, but notso useful to FIND the element. I dont know why they didnt just give that form the name "quickreply" or something...
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Sept 25, 2010 4:35:04 GMT -8
You would need to define what the nature of the "automatic UBBC" is... If it's to add some some kind of styling to whatever the user types then it obviously would need to hook the submission event so it would know when user has completed whatever she was typing. On the other hand, if it's to insert some kind of UBBC prior to when the user starts typing that would be a different code. And if your intent is to blindside the user while they are typing then that would require a different code It would be nice if the UBBC showed up BEFORE they typed anything...
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Sept 25, 2010 21:46:21 GMT -8
which is an awesome way of getting the form AFTER you found the element, but notso useful to FIND the element. I dont know why they didnt just give that form the name "quickreply" or something... getElementsByName('message')[0].form I know we've already broached this topic but my feeling is anybody coding for Proboards should already know that message is a one of Proboards' native names and should not be creating an element with a name that conflicts with that, but we don't live in an ideal world...
Walker of Nights, you do realize that by adding the UBBC prior to typing that leaves it susceptible to changes made by the user. You also still haven't given a concrete example of how you wish this inserted UBBC to be used but here's the code you asked for. <script type="text/javascript"> (function(){ var UBBCstart = '[size=3]\n', UBBCEnd = '\n[/size]' var f=document.forms,l=f.length,tA,a for(a=l-1;a>=0;a--){ if(f[a].elements['action'] && f[a].elements['action'].value=='post2'){ f[a].name = (f[a].name || 'quickForm'); tA = f[a].elements['message']; if(!/preview/i.test(pb_action)) tA.value += UBBCstart+ UBBCEnd; break; } } })() </script> Once you rethink your request it'll become clearer that there is more to coding than simply fulfilling a concept, all the plausible angles of "what ifs" has to be considered and accounted for. The above code makes no such attempts since inadequate details were provided
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Sept 26, 2010 4:32:59 GMT -8
ok, I want the UBBC added prior to typing. Have you seen how the greasemonkey code works for the posting template? This code: forum.sz-ex.com/index.cgi?board=gmscripts&action=display&thread=7612&page=1. It adds the UBBC like this [startubbc] | [/endubbc] The | is were your mouse is once it adds it. It would be nice if the code worked like that. Is that what you are asking? I don't know what you are asking for....
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Sept 26, 2010 10:40:24 GMT -8
ok, I want the UBBC added prior to typing. Have you seen how the greasemonkey code works for the posting template? This code: forum.sz-ex.com/index.cgi?board=gmscripts&action=display&thread=7612&page=1. It adds the UBBC like this [startubbc] | [/endubbc] The | is were your mouse is once it adds it. It would be nice if the code worked like that. Is that what you are asking? I don't know what you are asking for.... That GM script you referenced indirectly lets me know that the intended use of the script is to wrap whatever the user types in a superset of UBBC tags rather than inserting something that the user can optionally fill-in in addition to whatever they originally wanted to type. In that case as I said before it would be better to add that superset AFTER the user has finished typing because having it there before the user even types one letter means the user could screw it up by backspacing, deleting,etc. over the automatically inserted UBBC (unless your intent is to give that option to delete which still leaves the possibility that it occurs by mistake). If you still want it inserted prior to typing then setting the position of the caret is pretty easy in all browsers except IE (but not impossible: see this code and this code for working examples)
|
|
Nightwalker
Full Member
Everything Happens at Night
Posts: 138
Nightwalker said 0 great things
|
Post by Nightwalker on Sept 26, 2010 13:10:58 GMT -8
Ok it would be ok if the ubbc was put in AFTER you submitted the post...
Does the above code work for if i wanted it to be there before?
|
|
Bones
Code Helper
Posts: 131
Bones said 0 great things
|
Post by Bones on Sept 28, 2010 8:10:44 GMT -8
The above code simply inserts the data before the user starts typing but that ignores the dangers I spoke of. It also doesn't take into account when the user quotes instead of just reply, a "good" code would take that into account to avoid wrapping quotes in the automatic UBBC since it is meant to personally style the user's typing not someone else's (one of the "what ifs" I also mentioned)
|
|