Last active
December 19, 2015 23:29
-
-
Save davidlwatsonjr/6034818 to your computer and use it in GitHub Desktop.
Feedly Subscribe Bookmarklet
This file contains 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
javascript: (function() { | |
function getProperHref(href) { | |
if (!href.match(/^http/)) { | |
var path = (href.match(/^\//)) ? '/' : location.pathname; | |
href = 'http://' + location.hostname + path + href; | |
} | |
return href; | |
} | |
var links = document.querySelectorAll('link[rel="alternate"][type^="application/"][type$="+xml"'); | |
var feedlyURL = 'https://feedly.com/i/subscription/feed/'; | |
var feedlyExploreURL = 'https://feedly.com/i/spotlight/'; | |
if (links.length === 1) { | |
window.open(feedlyURL + getProperHref(links[0].getAttribute('href'))); | |
} | |
if (links.length > 1) { | |
var el = document.createElement('div'); | |
el.style.zIndex = 2147483646; | |
el.style.position = 'fixed'; | |
el.style.padding = '2em'; | |
el.style.top = 0; | |
el.style.backgroundColor = '#ffffcc'; | |
el.style.border = '1px solid #008000'; | |
el.style.color = '#000 '; | |
el.style.fontFamily = 'Arial, sans-serif'; | |
el.style.textAlign = 'left'; | |
el.innerHTML = 'View the following feeds in Feedly:'; | |
for (var i = 0, link; link = links[i]; i++) { | |
var title = link.getAttribute('title'); | |
var href = getProperHref(link.getAttribute('href')); | |
var previewLink = document.createElement('a'); | |
previewLink.href = feedlyURL + href; | |
previewLink.innerHTML = ((title) ? title : '') + ' - ' + href; | |
previewLink.setAttribute('target', '_blank'); | |
previewLink.style.display = 'block'; | |
previewLink.style.color = '#00c'; | |
previewLink.style.textDecoration = 'underline'; | |
el.appendChild(previewLink); | |
} | |
var close = document.createElement('a'); | |
close.innerHTML = 'Hide this box'; | |
close.href = '#'; | |
close.style.display = 'block'; | |
close.style.marginTop = '2em'; | |
close.style.color = '#00c'; | |
close.style.textDecoration = 'underline'; | |
close.onclick = function() { | |
el.style.display = 'none'; | |
return false; | |
}; | |
el.appendChild(close); | |
document.body.appendChild(el); | |
} | |
if (links.length === 0) { | |
window.open(feedlyExploreURL + getProperHref(window.location.href)); | |
} | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment