Userscripts.org - Preview Posts

By JoeSimmons Last update Aug 9, 2013 — Installed 572 times.

Compatibility Issue

in
Subscribe to Compatibility Issue 6 posts, 2 voices



IzzySoft Scriptwright

I just wanted to improve my emoticons script (current version works for UserStyles.Org only) to be used here at UserScripts.Org as well - but somehow it breaks your preview script, and I have no idea why. I pasted the code to PasteBin.Ca in the hope you may find out, and help me to solve this issue.

In short: It adds a div to the end of the one holding the textarea (to be more precise, to the next parent div having an ID so I can get it). Any help is appreciated - I don't want to break your script with my emoticons, since I think yours is more important 8-)

 
JoeSimmons Script's Author

Ok I'll have a look at it. And could you give any more information about what happens? Anything in the error console? How exactly does it break it? Does the preview button show at all? Is it still in the DOM (check with Firebug)?

 
IzzySoft Scriptwright

Preview button shows up fine - but clicking it doesn't make anything happen (not even the button changes). Submit button however works. Nothing in the error console I could clearly attach to it - except that there's an error on every keypress (not sure if it was there before):
Error: 'JavaScript component does not have a method named: "handleEvent"' when calling method: [nsIDOMEventListener::handleEvent] = NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED
Just checked again (with my script disabled) - that error still is there, repeated on each and every keypress. But with my script disabled, Preview works.

Edit:Just to clearify on your question: Your code gets inserted, as it looks like (all visible elements show up). Just the JS which should be executed onClick of the button does not run. My code gets inserted as well, and works as expected (except for the side effect to your code). I will play with it a bit further in parallel (just have to get back my code from the pastebin - which site is unfortunately blocked by the proxy of the company I work for, grrr...).

 
IzzySoft Scriptwright

Nevermind - found it! I already assumed the flaw before: My code was just appending to the parent DIVs innerHTML with all its stuff (well, this part was based on another script to get me started). I just reworked that a bit to use the proper DOM manipulation (i.e. not "parent.innerHTML += '

'", but instead "parent.appendChild(...)". Looks the same - but the major difference is it does no longer break your code :p

Great - so now I will update my script here, so we can have the emoticons available at this USO as well as on the other USO (UserStyles.Org + UserScripts.Org). EXCITED

Sorry for bothering you with this, Joe - and thank you very much for your fast response and willingness to help! In case you want to give the "final" result a try: It is script 48785, and I will update it within the next minutes (though still far from the final version - it needs some other changes and cleanup as well, right now it is more or less "quick and dirty").
BEER

 
JoeSimmons Script's Author

Oh cool. Yeah innerHTML seems to break listeners. I will give it a try.

 
IzzySoft Scriptwright

Well, to be honest: I was lazy again. I just added the other div around it using appendChild - but the code then still gets appended to that div using innerHTML. That's one of the things I mentioned for cleanup ASHAMED.

I just published the update, so you may go ahead to give it a shot. In case you miss something: Comments and suggestions are always welcome! Thank you again!

P.S.: I just published another update: Some more cleanup, commenting the code, improving the ALT/TITLE attributes, giving the elements IDs (to be referenced for manipulation e.g. by CSS). So in case you already downloaded the script for investigation, you may want to update. Now I just need to make it work on the "Edit post" as well, as I see...