Subscribed unsubscribe Subscribe Subscribe

枕を欹てて聴く

香炉峰の雪は簾を撥げて看る

LDR で Pinを読む(超簡易)

LDR Greasemonkey

fuba/ldr-enhanced-pin · GitHub
をみて, すごい! とか やりたい! とか思ったのですが, 自分はpinがfeedっぽく見れたらいいので簡易なものを.

inspired from http://twitter.com/VoQn/status/1063396310 — Gist
直接install this script

Shift+Pでpinがfeedっぽくでる.
LDR Full Feedとか一応効きますが, ボタンは効かないと思うので, 気になる人は
LDR Full Feedの430行目近くの

  var reg = /gm_fullfeed_widget_(\d+)/;

の regを

  var reg = /gm_fullfeed_widget_(.+)/;

にするといいです.

// ==UserScript==
// @name LDR Pin Feed
// @namespace http://d.hatena.ne.jp/Constellation/
// @description show pin items as feed
// @author Constellation
// @include http://fastladder.com/reader/*
// @include http://reader.livedoor.com/reader/*
// ==/UserScript==
(function(win){
  //Configuration
location.href = 'javascript:(' + function() {
  var KEY = 'P';
 
  var base = {
    ads: null,
    gm: true,
    subscribe_id: "gm_pinned_items",
    last_stored_on: "",
    channel:{
      error_count: "0",
      link: location.href,
      description: "my pinned items",
      image: "/img/icon/pin.gif",
      title: "Pinned items",
      feedlink: "/api/pin/all",
      subscribers_count: "1",
      expires: (new Date).getTime()/1000,
    },
    items: []
  }
 
  function format(pin){
    base.items = pin.pins.map(function(pin, index){
      return {
        "enclosure":"",
        "link": pin.url,
        "enclosure_type":null,
        "author":"",
        "body": "",
        "created_on": pin.created_on,
        "modified_on": "",
        "id": index+0.1234567,//小数ならかぶらない+ボタンも有効になる
        "title": pin.title,
        "category":null
      }
    });
    return base
  }
  function GM_main(){
    gm_print_feed(format(pin));
  }
 
  //ほぼprint_feedから持ってくるが, pin描画に適応
  var before_reading = "";
  function gm_print_feed(feed){
    invoke_hook('BEFORE_PRINTFEED', feed);
    var subscribe_id = feed.subscribe_id;
    State.last_feed = feed;
    State.last_items = {};
    State.requested = false;
    before_reading = State.now_reading;
    State.now_reading = subscribe_id;
    var Now = (new Date - 0)/1000;
    var output = $(print_feed.target);
    var channel = feed.channel;
    var items = feed.items;
 
    var item_formatter = new ItemFormatter().compile();
    var feed_formatter = new FeedFormatter().compile();
    var item_count = 0;
    var item_f = function(v){
      item_count++;
      State.last_items["_"+v.id] = v;
      var widgets = entry_widgets.process(feed, v);
      return item_formatter(v,{
        relative_date : (v.created_on) ? (Now-v.created_on).toRelativeDate() : tl('Unknown date'),
        item_count : item_count,
        widgets : widgets,
        pin_active : pin.has(v.link) ? "pin_active" : "",
        pinned : pin.has(v.link) ? "pinned" : "",
        loop_context : [
          (item_count == 1) ? "first" : "",
          (item_count % 2) ? "odd" : "even",
          (item_count == size) ? "last" : "",
          (item_count != 1 && item_count != size) ? "inner" : ""
        ].join(" ")
      });
 
    };
 
    var subscribe_info = subs_item(subscribe_id, feed);
    var size = items.length;
 
    var first_write_num = LDR_VARS.PrintFeedFirstNum;
    var widgets = channel_widgets.process(feed, items);
    output.innerHTML = feed_formatter(
      feed, channel, subscribe_info, {
        ads_expire : null,
        widgets: widgets,
        items : function(){
          return items.slice(0, first_write_num).map(item_f).join("")
        }
      }
    );
    fix_linktarget();
 
    State.writer && State.writer.cancel();
    State.writer2 && State.writer2.cancel();
    function DIV(text){
      var div = document.createElement("div");
      div.innerHTML = text;
      fix_linktarget(div);
      return div;
    }
 
    // 遅延描画
    function push_item(){
      var num = LDR_VARS.PrintFeedNum;
      var delay = LDR_VARS.PrintFeedDelay;
      var delay2 = LDR_VARS.PrintFeedDelay2;
 
      var writer = function(){
        var remain_items = items.slice(writed,writed + num).map(item_f).join("");
        writed += num
        if(more.className){
          more.className = "hide";
          more.innerHTML = "";
        }
        State.writer2 = (function(){
          more.appendChild(DIV(remain_items))
          more.className = "";
        }).later(10)();
        if(writed < size){
          State.writer = writer.later(delay2)();
        }
      };
      State.writer = writer.later(delay)();
    }
    if(items.length > first_write_num){
      var more = $N("div",{"class":"more"});
      more.innerHTML = "描画中";
      output.appendChild(more);
      var writed = first_write_num;
      push_item();
    }
 
    Control.scroll_top();
    Control.del_scroll_padding();
    print_feed.target = "right_body";
    invoke_hook('AFTER_PRINTFEED', feed);
  }
 
  var id = setTimeout(function(){
    id && clearTimeout(id);
    if(typeof Keybind != 'undefined' && get_next && get_prev){
      // native 書き換え.
      var get_next_orig = get_next;
      get_next = function(){
        if(State.now_reading == 'gm_pinned_items'){
          State.now_reading = before_reading;
        }
        return get_next_orig();
      }
      var get_prev_orig = get_prev;
      get_prev = function(){
        if(State.now_reading == 'gm_pinned_items'){
          State.now_reading = before_reading;
        }
        return get_prev_orig();
      }
      Keybind.add(KEY, GM_main)
    } else {
      id = setTimeout(arguments.callee, 100);
    }
  }, 0);
 
}.toString() + ')()';
})(this.unsafeWindow || this);