如何写userscript的动态网站 [英] How to write userscript for a dynamic website

查看:71
本文介绍了如何写userscript的动态网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**首先,我对不起我的英文不好!

**First of all, i'm sorry for my bad english!

我想写一个userscript一些网站。 本网站更新自己每一次点击或几秒钟。 (它使用AJAX无刷新更新视图) 我userscript要追加一些HTML元素,当用户在一定的看法。 我怎样才能运行C每个视图改变我的$ C $? (阿贾克斯之后)

I am trying to write a userscript for some website. This website updates himself every click or some seconds. (it uses ajax to update the view without refreshing) My userscript have to append some html elements when the user is in certain view. How can i run my code every view change? (after ajax)

该网页有一个叫做函数则AjaxCall 发送一个Ajax请求,并根据响应翻动书页。 我想是这样的:

The page have a function called ajaxCall that sends an ajax request and changes the page according to the response. I tried something like this:

var source = window.ajaxCall;
window.ajaxCall = function(param){ 
    source(param);
    myFunc();
}

这没有工作,因为则AjaxCall 发送异步Ajax请求,那么:第一,称为源函数(Ajax请求启动),紧随其后,叫我的功能。 (前Ajax请求成功,改变视图)

this didn't work because ajaxCall sends async ajax request, so: first, the source function called (ajax request started), and immediately after it, my function called. (before the ajax request succeed and view changed)

有没有一种方法,以页面更新后立即运行我的code?

Is there a way to run my code immediately after page updates?

非常感谢你。

推荐答案

尝试使用 jQuery库

Example 1:


 $.ajax({
  url: "http://fiddle.jshell.net/favicon.png",
  beforeSend: function( xhr ) {
    xhr.overrideMimeType( "text/plain; charset=x-user-defined" );
  }
})
  .done(function( data ) {
    if ( console && console.log ) {
      console.log( "Sample of data:", data.slice( 0, 100 ) );
    }
  });

example 2:

    var jqxhr = $.ajax( "example.php" )
      .done(function() {
        alert( "success" );
      })
      .fail(function() {
        alert( "error" );
      })
      .always(function() {
        alert( "complete" );
      });

    // Perform other work here ...

    // Set another completion function for the request above
    jqxhr.always(function() {
      alert( "second complete" );
    });

这篇关于如何写userscript的动态网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆