User Script: Doesn't Work Automatically, Does Work Manually

Subscribe to User Script: Doesn't Work Automatically, Does Work Manually 7 posts, 5 voices

Wolfey Scriptwright

Recently, for use on the "Gallery" and "Favorites" sections of deviantART, I've created a script to display a submission's date below the submission itself. That script is "{deviantART} Add Submission Post Dates".

It does work if run manually (by using a bookmarklet, Javascript shell, Firebug, etc.), but not automatically; however, it will occasionally refuse to run manually as well.

I have little experience when it comes to working with Javascript, so I am not sure what is causing this. I suspect that another script on the page is (somehow) preventing mine from being run, but I can't confirm this.

If anyone could let me know what is causing this problem, as well as show how to fix it (if possible), I'd greatly appreciate it =)

 
teukkam Scriptwright

I don't know exactly why, but it works like a charm if you add this condition:


if (currentItemNode.firstChild.childNodes.length > 3 ) {
var itemDate = currentItemNode.firstChild.childNodes[3].getAttribute("title");

(and the closing curling bracket at the very end)

 
teukkam Scriptwright

Hmm, it only seems to work when you reload the page, must have something to do with caching. I also thought that a more elegant solution would be to use an XPath query to fetch only elements that have the title attribute set. I am not sure if that approach will work any better.

 
znerp Scriptwright

Can you give an example page that the script should run on? I suspect the problem may be with the galleries being loaded dynamically with Ajax (which is the case with Facebook galleries these days, and I have some experience of scripting with these), so the workaround that I tend to use is to put the entire script into a function, and then use the following line..

document.addEventListener('DOMNodeInserted', function() { window.setTimeout(scriptFunction, 5000);}, true);
Where the time delay allows the gallery to load before the script is run.

 
todd hodes User

thanks znerp, this solves the exact problem i just posted about a moment ago! :)

[re: AJAX question: call function when google maps "search" is clicked?]

 
Wolfey Scriptwright

teukkam: Thanks for the code - it helped me find out why it refused to run manually at times, so that bug is fixed now =)

It turns out that, if the section being checked has an advertisement, the script will pick that up as the first item and refuse to run. With some modifications to the line you provided, it will skip the first item (the advertisement) if it's present on the page. I've updated my script (and bookmarklet) to take care of that issue; however, the script still refuses to run automatically.

znerp: Anyone's "Gallery" or "Favorites" page will work just fine. I don't have anything on my own page at this time, so I'll provide links to one I've noticed with both:

http://laslindas.deviantart.com/gallery/

This gallery's page (its first one) doesn't have an advertisement, but all of its following pages do.

I hope this helps =)

 
imran User

ankit's script is not installing automatically :(

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel