FeedlyTool mini Save For Later

Display "Save for Later" count. This is the edition that was limited to Save For Later feature Chrome extension of "FeedlyTool".

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name            FeedlyTool mini Save For Later
// @version         0.0.2
// @author          kik0220
// @namespace       https://sites.google.com/site/feedlytool/
// @description     Display "Save for Later" count. This is the edition that was limited to Save For Later feature Chrome extension of "FeedlyTool".
// @description:ja  「Save for Later」の件数を表示します。これはChrome拡張「FeedlyTool」のSave For Later機能に限定したものです。
// @icon            http://feedlytool.kk22.jp/icon.png
// @match           http://feedly.com/*
// @match           https://feedly.com/*
// @exclude         http://feedly.com/#welcome
// @exclude         https://feedly.com/#welcome
// @grant           GM_addStyle
// @grant           GM_xmlhttpRequest
// @connect         cloud.feedly.com
// @copyright       2013+, kik0220
// ==/UserScript==

var accessToken = '';
var userId = '';
var lastLocation = '';
var currentDir = '';
var customCSS = [
  '#feedlyTool_savedTab_count { float: right; font-size: 10px; opacity: 0.75; }',
  '#savedtab_label { float: left; }'
].join('');

GM_addStyle(customCSS);
document.addEventListener("DOMSubtreeModified", getCookie, false);
document.body.addEventListener("DOMSubtreeModified", function (e) {
  if (lastLocation != document.location.href) {
    lastLocation = document.location.href;
    getSaved();
  }
}, false);

function getCookie(){
  if(document.location.href.indexOf('/i/welcome') > -1){return;}
  var all = document.cookie;
  if(all === null){return;}
  all = all.split(';');
  for(var i = 0; i < all.length; i++){
    var cookie = all[i];
    if(cookie.indexOf('feedly.session=') < 0){continue;}
    var json;
    try{
      json = JSON.parse(cookie.replace('feedly.session=', ''));
      accessToken = json.feedlyToken;
      userId = json.feedlyId;
    } catch(e) {return;}
    document.removeEventListener("DOMSubtreeModified", getCookie, false);
    setTimeout(getSaved(), 3000);
    return;
  }
}

function getSaved(){
  if(!accessToken||!userId){return;}
  GM_xmlhttpRequest({
    method: 'GET',
    url: 'https://cloud.feedly.com/v3/markers/tags',
    headers: { 'Authorization': 'OAuth '+accessToken },
    onload: function(res) {
      if(res.status !== 200){return;}
      var response = JSON.parse(res.responseText);
      var count = response.taggedEntries['user/'+userId+'/tag/global.saved'].length;
      var target = document.getElementById('feedlyTool_savedTab_count');
      var targetParent = document.getElementById('savedtab');
      if(target){
        target.innerText = count;
      } else if(targetParent) {
        targetParent.innerHTML += '<div id="feedlyTool_savedTab_count">'+ count +'</div>';
      }
    }
  });
}