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".

目前為 2016-08-17 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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>';
      }
    }
  });
}