如何跳过论坛的确认页面?

时间:2012-07-21 20:06:08

标签: javascript redirect greasemonkey

我正在为一个论坛写一个Greasemonkey脚本,如果你在你写的帖子上点击“提交”,你将被带到一个通知页面,上面写着“你的帖子已被发布”。

我试图通过完全跳过这个页面来解决这个问题。

到目前为止,我提出的唯一解决方案是:

// @include        *posting.php?mode=reply*
// ==/UserScript==
// @run-at document-start

{
location.href = document.referrer
}

这可能是一个完整的迂回方式,但它并不是我想要的。我希望完全跳过确认页面,然后立即重新加载到您刚刚访问的页面。我也尝试了history.go(-1),但没有骰子。

任何想法如何在这些方面取得成果?

2 个答案:

答案 0 :(得分:0)

使用AJAX进行发布。那么你可以避免去消息页面。只是得到回应并做任何你想做的事情。

基于jquery的ajax

   $("#submitButtonId").click(function() {

    var url = "path/to/your/script.php"; // the script where you handle the form input.

    $.ajax({
           type: "POST",
           url: url,
           data: $("#idForm").serialize(), // serializes the form's elements.
           success: function(data)
           {
               alert(data); // show response from the php script.
           }
         });

    return false; // avoid to execute the actual submit of the form.
});

答案 1 :(得分:0)

您的脚本无法正常运行的原因是您发布的代码中存在错误。 metadata block已损坏且@run-at指令位于块之外。

其他问题:

  1. 您可能应该使用location.replace()来保证确认页面不会弄乱历史记录和后退按钮。
  2. @include *posting.php?mode=reply*会不必要地降低所有Firefox的速度。这是因为Greasemonkey必须对每个URL进行,逐个字符比较。

    如果可以提供帮助,请不要使用多字符通配符启动@includes(或任何编程语言中的任何比较)。最好有多个包括这样:

    // @include     http://SITE_1/posting.php?mode=reply*
    // @include     http://SITE_2/posting.php?mode=reply*
    //etc.
    

  3. 所以,这个脚本应该对你有用:在实践中,你永远不会看到确认页面(我自己使用这种技术):

    // ==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);
    


    请注意,像Rab Nawaz's answer这样的方法可以提供更好的UI体验,但并不像他的答案所示那么简单。您需要在典型的论坛页面上捕获许多表单,按钮和链接。所有内容都不会发布到同一目的地,您将如何处理结果会因操作而异。

    location.replace()是UI平滑性与潜在大代码复杂性的良好折衷。

相关问题