endless summer on dsbd

    @@ -162,7 +162,7 @@ var c = Math.floor(Math.random() * a.length); var d = Math.floor(Math.random() * (a[c].max - a[c].min + 1)) + a[c].min; if (d < oldest_id) { - return choice(); + return getRandom(); } console.log([d, a[c].year, a[c].max, a[c].min, c]); return d;
  • /*
     * @title endless summer on dsbd 
     * @description promotion version
     * @include http://www.tumblr.com/*
     * @license reblog commons license ( cc by 3.0 )
     */ 
    
    (function () {
      var now_url = location.href;
      var oldest_id = 264102; // http://ku.tumblr.com/post/264102
      var latest_id = get_latest_id(document);
      latest_id = (latest_id > 20000000000) ? latest_id : 20000000000;
      console.log('latest_id: ' + latest_id);
    
      var State = true;
      var HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
      var BASE_REMAIN_HEIGHT = 10000;
      var loading = false;
    
      var last_element = get_next_elements(document).pop();
      if (!last_element) {
        return error();
      }
      insert_point = last_element.nextSibling;
      insert_parent = last_element.parentNode;
    
      next_page_load();
    
      window.addEventListener('scroll', function () {
        if (loading) return;
        var remain = document.documentElement.scrollHeight - window.innerHeight - window.pageYOffset;
        if (State && remain < BASE_REMAIN_HEIGHT) {
          next_page_load();
        }
      }, false);
    
      function next_page_load() {
        loading = true;
        var next = get_next(now_url);
        history.pushState("", "", next);
        console.log('next: ' + next);
        var x = new XMLHttpRequest();
        x.onload = function () {
          if (x.status <= 200 && x.status < 300) {
            load(x);
          } else {
            error();
            next_page_load();
          }
        };
        x.open('GET', next, true);
        x.send(null);
      }
    
      function load(x) {
        var html = x.responseText.replace(/<script(?:[ \t\r\n][^>]*)?>[\S\s]*?<\/script[ \t\r\n]*>|<\/?(?:i?frame|html|script|object)(?:[ \t\r\n][^<>]*)?>/gi, ' ');
        var htmlDoc;
        if (document.implementation.createHTMLDocument) {
          htmlDoc = document.implementation.createHTMLDocument('hogehoge')
        } else {
          htmlDoc = document.cloneNode(false);
          if (htmlDoc) {
            htmlDoc.appendChild(htmlDoc.importNode(document.documentElement, false));
          } else {
            htmlDoc = document.implementation.createDocument(null, 'html', null);
          }
        }
        var range = document.createRange();
        range.selectNodeContents(document.documentElement);
        htmlDoc.documentElement.appendChild(range.createContextualFragment(html));
        var docs = get_next_elements(htmlDoc);
        if (!docs.length) {
          error();
          return next_page_load();
        }
        target_rewrite(docs);
        img_cache(docs);
        docs = docs.map(function (doc) {
          return insert_parent.insertBefore(document.importNode(doc, true), insert_point);
        });
        loading = false;
      }
    
      function get_next_elements(doc) {
        var r = doc.evaluate('id("posts")/li[starts-with(@id,"post_")]', doc, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
        for (var i = 0, l = r.snapshotLength, res = new Array(l); i < l; i++) res[i] = r.snapshotItem(i);
        return res;
      }
    
      function target_rewrite(docs) {
        docs.forEach(function (doc) {
          var as = doc.getElementsByTagName('a');
          for (var i = 0, l = as.length; i < l; i++) {
            var a = as[i],
              _a = a.getAttribute('href');
            if (_a && !/^javascript:/.test(_a) && !/^#/.test(_a)) a.setAttribute('target', '_blank');
          }
        });
      }
    
      function img_cache(docs) {
        docs.forEach(function (doc) {
          var is = doc.getElementsByTagName('img');
          for (var i = 0, l = is.length; i < l; i++) {
            img = new Image();
            img.src = is[i].src;
          }
        });
      }
    
      function error() {
        return console.log('error');
        State = false;
      }
    
      function terminate() {
        return console.log('terminate');
        State = false;
      }
    
      function get_latest_id(doc) {
        return doc.evaluate('number(substring-after(id("posts")/li[starts-with(@id,"post_")]/@id,"post_"))', doc, null, XPathResult.NUMBER_TYPE, null).numberValue;
      }
    
      function get_next(url) {
        var rumdom_id = getRandom();
        return /(?:\/dashboard|(?:\/blog\/[-\w]+)?\/show\/\w+|\/blog\/[-\w]+)/.exec(url)[0] + '/2?offset=' + rumdom_id;
      }
    
      function getRandom() {
        var a = [{
          'year': '2007',
          'min': 765,
          'max': 22716604,
          'url': 'http://kagurazakaundergroundresistance.tumblr.com/post/22716604'
        }, {
          'year': '2008',
          'min': 22716605,
          'max': 67666062,
          'url': 'http://kagurazakaundergroundresistance.tumblr.com/post/67666062'
        }, {
          'year': '2009',
          'min': 67666063,
          'max': 309781568,
          'url': 'http://kagurazakaundergroundresistance.tumblr.com/post/309781568'
        }, {
          'year': '2010',
          'min': 309781569,
          'max': 2542121207,
          'url': 'http://kagurazakaundergroundresistance.tumblr.com/post/2542121207'
        }, {
          'year': '2011',
          'min': 2542121208,
          'max': 15080900593,
          'url': 'http://kagurazakaundergroundresistance.tumblr.com/post/15080900593'
        }, {
          'year': 'now',
          'min': 15080900593,
          'max': latest_id,
          'url': 'http://kagurazakaundergroundresistance.tumblr.com/post/19893333892'
        }];
        var c = Math.floor(Math.random() * a.length);
        var d = Math.floor(Math.random() * (a[c].max - a[c].min + 1)) + a[c].min;
        if (d < oldest_id) {
          return getRandom();
        }
        console.log([d, a[c].year, a[c].max, a[c].min, c]);
        return d;
      }
    })()
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2014/09/01 20:21:47 - 2014-09-01
  2. 2014/09/01 20:11:42 - 2014-09-01
  3. 2014/09/01 20:01:27 - 2014-09-01
  4. 2014/09/01 20:00:29 - 2014-09-01
  5. 2013/09/02 18:28:47 - 2013-09-02
  6. 2013/09/02 18:28:23 - 2013-09-02
  7. 2013/07/26 10:38:44 - 2013-07-26
  8. 2013/07/25 18:03:31 - 2013-07-25
  9. 2013/07/25 17:53:31 - 2013-07-25
  10. 2013/07/25 17:22:09 - 2013-07-25
  11. 2013/07/02 00:50:56 - 2013-07-02
  12. 2013/06/16 01:32:17 - 2013-06-16
  13. 2013/05/31 14:38:33 - 2013-05-31
  14. 2013/05/31 01:13:54 - 2013-05-31
  15. 2012/06/05 09:30:02 - 2012-06-05
  16. 2012/06/05 09:22:53 - 2012-06-05
  17. 2012/04/02 23:08:12 - 2012-04-02
  18. 2012/04/02 22:19:07 - 2012-04-02
  19. 2012/04/02 10:16:54 - 2012-04-02
  20. 2012/04/02 09:24:37 - 2012-04-02
  21. 2012/04/02 09:01:39 - 2012-04-02
  22. 2012/04/01 02:24:15 - 2012-04-01
  23. 2012/04/01 00:53:16 - 2012-04-01
  24. 2012/03/31 18:53:11 - 2012-03-31
  25. 2012/03/31 18:15:25 - 2012-03-31
  26. 2012/03/31 16:35:18 - 2012-03-31