I'm writing a Greasemonkey script for a forum where, if you hit "Submit" on a post you've written, you will be taken to a notification page saying 'Your post has been posted".
I'm trying to get around this by skipping this page entirely.
So far the only solution I've come up with is:
// @include *posting.php?mode=reply*
// ==/UserScript==
// @run-at document-start
{
location.href = document.referrer
}
It's probably a complete roundabout way, but it's not quite what I was looking for. I'm hoping to skip the confirmation page entirely and just reload back to the page you were just at immediately. I've tried history.go(-1)
as well, but no dice.
Any ideas how to achieve something along those lines?
The reason your script did not work well, is there are errors in the code you posted. The metadata block is corrupt and the @run-at
directive is outside of the block.
Additional issues:
location.replace()
to keep the confirmation page from cluttering up the history and the back button.@include *posting.php?mode=reply*
will slow all of Firefox down unnecessarily. This is because Greasemonkey will have to do a deep, character-by character comparison of every URL.
Don't start @includes
(or just about any comparison in any programming language) with a multi-char wildcard if you can help it. Better to have multiple includes like so:
// @include http://SITE_1/posting.php?mode=reply*
// @include http://SITE_2/posting.php?mode=reply*
//etc.
So, this script should work well enough for you: In practice, you'll never see the confirmation page (I use this technique myself) :
// ==UserScript==
// @name Whatever
// @include http://SITE_1/posting.php?mode=reply*
// @include http://SITE_2/posting.php?mode=reply*
// @include http://SITE_3/posting.php?mode=reply*
// @run-at document-start
// ==/UserScript==
location.replace (document.referrer);
Note that approaches like Rab Nawaz's answer can give a better UI experience, but it is not as simple as his answer shows. You need to capture many forms, buttons, and links -- on a typical forum page. Everything does not post to the same destination, and how you would handle the results varies wildly depending on the action.
The location.replace()
is a good tradeoff of UI smoothness against potentially large code complexity.