Donmai

Custom Javascript issue

Posted under General

Normally I would ask this on a more appropriate site but with my limited knowledge of programming I can only describe the problem here.

I'm trying to make a userscript that will automatically change the current url to the image, and still let me return to the posts' page:

if (history.length === 1) {
    location.assign($("#image").eq(0).attr("src"));
}

The problem with this however, is when I return to the posts' page it acts and looks differently; The shortcut keys don't work, "(vote up/down)" is changed to "(vote up/downunvote)", both "Favorite" and "Unfavorite" are visible, and the comment box is already opened. Picture examples: Normal - Abnormal

Is it something with the cookies? What can I do to stop it from doing that?

If you manually type in a image url rather than using the javascript, does the same happen?

This looks browser-specific, as the problem is that upon returning to the page, all the html is loaded correctly but danbooru's javascript isn't run again.
(also try location.href)

If I copy the image url, load that, and go back there's no problem.

The browser is Firefox. I've tried using window.onload: window.onload = function () {location.assign($("#image").eq(0).attr("src"))}; but then I can't go back, as if it's using location.replace instead of location.assign.

That filename will change and break your script when the site's javascript is updated. You'll probably want to do something like:

@require http://danbooru.donmai.us/assets/application-*.js;

to match on any filename.

1