APIs

Filters

別のGreasemonkey Scriptから、AutoPagerizeの動作の途中に処理を挟むことができる。

Filter 実行タイミング 引数 用途
addDocumentFilter 次のページを読み込んで Document 作成した完了直後で、 Document からpageElement を切り出す前であり、「さらに次のページ」の URL 取得前 htmlDoc ( GM_xmlhttpRequest で取得したソースを元に作成した Document オブジェクト), this.requestURL (次のページとして取得した URL ), this.info (使用している SITEINFO ) nextLink, pageElement の取得の補助、 SITEINFO の動的な変更など
addFilter 次のページの pageElement を挿入後 pageElement ( htmlDoc から getElementsByXPath ( this.info.pageElement , htmlDoc で切り出した) 要素の配列。要素自身だと間違われやすいがあくまで配列) 継ぎ足しした部分を他の Script から操作したい場合など
addRequestFilter 次ページ取得のリクエストを送信する直前 GM_XHR用リクエストオプション リクエストのURLやオプションを変更する
addResponseFilter 次ページ取得のレスポンス取得時 レスポンス、URL レスポンスの内容を変更する

launchAutoPager

AutoPagerizeにsitoinfoを渡して実行させることができる。
引数はsitoinfoを格納した配列。

Sample

// ==UserScript==
// @name           pop alt
// @namespace      http://ss-o.net/
// @include        http://*
// ==/UserScript==
(function () {
  function pop_alt(doc) {
    var imgs = doc.getElementsByTagName('img');
    for (var i = 0, len = imgs.length, img; i < len; i++) {
      if (!(img = imgs[i]).hasAttribute('title') && img.alt) {
        img.setAttribute('title', img.alt);
      }
    }
  }
  pop_alt(document);
  if (window.AutoPagerize) {
    boot();
  } else {
    window.addEventListener('GM_AutoPagerizeLoaded',boot,false);
  }
  function boot() {
    window.AutoPagerize.addFilter(function(docs){
      docs.forEach(pop_alt);
    });
  }
})();

Sample (used AutoPagerize_DOMNodeInserte)

// ==UserScript==
// @name           pop alt
// @namespace      http://ss-o.net/
// @include        http://*
// ==/UserScript==
(function () {
  function pop_alt(doc) {
    var imgs = doc.getElementsByTagName('img');
    for (var i = 0, len = imgs.length, img; i < len; i++) {
      if (!(img = imgs[i]).hasAttribute('title') && img.alt) {
        img.setAttribute('title', img.alt);
      }
    }
  }
  pop_alt(document);
  document.body.addEventListener('AutoPagerize_DOMNodeInserted',function(evt){
    pop_alt(evt.target);
  },false);
})();

Links

changed April 7, 2011 delete history edit