Commits

Anton Afanasyev  committed 47a1e4c

initial work on supporting AutoPager-style SITEINFOs

  • Participants
  • Parent commits f1e7e2e
  • Branches extended

Comments (0)

Files changed (1)

File autopagerize.user.js

 // @exclude        http://b.hatena.ne.jp/*
 // @exclude        http://www.facebook.com/plugins/like.php*
 // @exclude        http://api.tweetmeme.com/button.js*
-// @version        0.0.66
+// @version        0.1.01
 // @updateURL      https://bitbucket.org/aasoft/autopagerize-extended/raw/tip/autopagerize.user.js
 // @icon           http://autopagerize.net/img/icons/icon_032.png
 // @grant          GM_getValue
 // ==/UserScript==
 
 
-// version: 0.0.66 2012-08-31T18:23:34+09:00
+// version: 0.1.01 2012-08-31T18:23:34+09:00
 //
-// this script based on
-// AutoPagerize http://userscripts.org/scripts/show/8551
-// thanks to swdyh.
+// this script based on AutoPagerize http://userscripts.org/scripts/show/8551 thanks to swdyh.
 //
-// Released under the GPL license
-// http://www.gnu.org/copyleft/gpl.html
+// Released under the GPL license http://www.gnu.org/copyleft/gpl.html
 //
 
 // disable paging when scrolling with LMB pressed
         expire: 24 * 60 * 60 * 1000, // daily
     },
     {
+        url:    'http://rep.teesoft.info/autopager/json',
+        expire: 24 * 60 * 60 * 1000, // daily
+    },
+    {
         url:    'http://wedata.net/databases/AutoPagerize/items.json',
         expire: 24 * 60 * 60 * 1000, // daily
     }
         return eval(GM_getValue('cacheInfo')) || {};
     //}
 }
+var pickMapFunction = function( anItem ) {
+    var nullMapper = function() { return null; };
+
+    var autopagerizeMapper = function(i) { return i.data; };
+    var autopagerMapper = function(i) { 
+        // FIXME: add support for non-regex url filters
+        if( !i.r )
+            return null;
+
+        return {
+            "url":          i.u,
+            "nextLink":     i.n,
+            "pageElement":  i.x
+        };
+    };
+
+    if( !anItem )
+        return nullMapper;
+
+    if( anItem.data )
+        return autopagerizeMapper;
+
+    if( anItem.u && anItem.x && anItem.n )
+        return autopagerMapper;
+
+    return nullMapper;
+};
 var getCacheCallback = function(res, urlInfo) {
     if (res.status != 200)  {
         return getCacheErrorCallback(urlInfo);
 
     var info;
     try {
+        var parsedDatas;
         try {
-            info = JSON.parse(res.responseText).map(function(i) { return i.data })
+            parsedDatas = JSON.parse(res.responseText);
         } catch(e) {
             log("couldnt parse json in getCacheCallback("+res + ", " + info + "). trying eval");
-            info = eval(res.responseText).map(function(i) { return i.data; });
+            parsedDatas = eval(res.responseText);
         }
+
+        var mapFn = pickMapFunction( parsedDatas[0] );
+        info = parsedDatas.map( mapFn ).filter( function(v) { return v!=null; });
     } catch(e) {
         log("getCacheCallback("+res + ", " + info + ") error:\r\n"+e);
         info = [];