Created
October 5, 2014 06:53
-
-
Save Qofar/1bab48c03135c993353f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name feedly - SavedForLater Opener | |
// @include http://feedly.com/* | |
// @include https://feedly.com/* | |
// @version 1.0.0 | |
// @license MIT License | |
// ==/UserScript== | |
(function() { | |
var func = function() { | |
var KEY_CODE = 87; // [w] key | |
var MAX_WINDOW_OPEN = 5; // max 1000 | |
var ORDER = 'oldest'; // 'oldest' or 'newest' | |
function SavedForLaterOpener() { | |
var resHeader = 'application/json'; | |
var reqHeader = { | |
'$Authorization.feedly': '$FeedlyAuth', | |
'Content-Type': 'application/json' | |
}; | |
try { | |
var userId = streets.getUserId(); | |
var xhr = streets.service('io'); | |
// GET SavedForLater items | |
xhr.jget('!{cloud}/v3/streams/contents?streamId=user/' + encodeURIComponent(userId) + '/tag/global.saved&count=' + MAX_WINDOW_OPEN + '&ck=' + new Date().getTime() + '&ct=feedly.desktop&cv=' + feedlyApplicationVersion + '&unreadOnly=true&ranked=' + ORDER, | |
function(jsonInfo) { | |
if (jsonInfo === null || jsonInfo.items === null || jsonInfo.items.length === 0) { | |
return; | |
} | |
for (var i = 0, length = jsonInfo.items.length; i < length; i++) { | |
windowopen(jsonInfo.items[i].alternate[0].href); | |
// DELTE SavedForLater item | |
xhr.del('!{cloud}/v3/tags/' + encodeURIComponent('user/' + userId + '/tag/global.saved') + '/' + encodeURIComponent(jsonInfo.items[i].id) + '?ck=' + new Date().getTime() + '&ct=feedly.desktop', | |
function() {}, | |
function() {}, resHeader, reqHeader); | |
} | |
}, | |
function() {}, resHeader, reqHeader); | |
} catch (e) { | |
console.error('FAILED to SavedForLaterOpener:', e); | |
} | |
} | |
function windowopen(url) { | |
var a = document.createElement('a'); | |
a.target = '_blank'; | |
a.href = url; | |
var event = document.createEvent('MouseEvents'); | |
var clicktype = 0; // firefox | |
if(this.chrome) clicktype = 1; // chrome | |
event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, clicktype, null); | |
a.dispatchEvent(event); | |
return true; | |
} | |
document.addEventListener('keydown', function(e) { | |
if (e.keyCode === KEY_CODE && | |
!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey && | |
!/^input|^textarea/i.test(e.target.tagName)) { | |
SavedForLaterOpener(); | |
} | |
}, false); | |
}; | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.textContent = '(' + func.toString() + ')();'; | |
document.body.appendChild(script); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment