addRequestFilter と addResponseFilter
http://userscripts.org/scripts/diff/8551/86848
@@ -9,7 +9,7 @@ // ==/UserScript== // // auther: swdyh http://d.hatena.ne.jp/swdyh/ -// version: 0.0.36 2009-03-08T14:43:37+09:00 +// version: 0.0.37 2009-05-07T13:52:56+09:00 // // this script based on // GoogleAutoPager(http://la.ma.la/blog/diary_200506231749.htm) and @@ -21,7 +21,7 @@ // var URL = 'http://userscripts.org/scripts/show/8551' -var VERSION = '0.0.36' +var VERSION = '0.0.37' var DEBUG = false var AUTO_START = true var CACHE_EXPIRE = 24 * 60 * 60 * 1000 @@ -236,6 +236,7 @@ self.requestLoad.apply(self, [res]) } } + AutoPager.requestFilters.forEach(function(i) { i(opt) }, this) this.showLoading(true) GM_xmlhttpRequest(opt) } @@ -254,6 +255,10 @@ return } + AutoPager.responseFilters.forEach(function(i) { + i(res, this.requestURL) + }, this) + if (res.finalUrl) { this.requestURL = res.finalUrl } @@ -398,6 +403,8 @@ } AutoPager.documentFilters = [] +AutoPager.requestFilters = [] +AutoPager.responseFilters = [] AutoPager.filters = [] function Counter() {} @@ -634,6 +641,18 @@ if (info.length > 0) { info = info.filter(function(i) { return ('url' in i) }) info.sort(function(a, b) { return (b.url.length - a.url.length) }) + + var r_keys = ['url', 'nextLink', 'insertBefore', 'pageElement'] + info = info.map(function(i) { + var item = {} + r_keys.forEach(function(key) { + if (i[key]) { + item[key] = i[key] + } + }) + return item + }) + cacheInfo[url] = { url: url, expire: new Date(new Date().getTime() + CACHE_EXPIRE), @@ -692,6 +711,12 @@ window.AutoPagerize.addDocumentFilter = function(f) { AutoPager.documentFilters.push(f) } + window.AutoPagerize.addResponseFilter = function(f) { + AutoPager.responseFilters.push(f) + } + window.AutoPagerize.addRequestFilter = function(f) { + AutoPager.requestFilters.push(f) + } var ev = document.createEvent('Events') ev.initEvent('GM_AutoPagerizeLoaded', false, true)