diff --git a/css/screen.css b/css/screen.css index 7c14659..cd9a860 100644 --- a/css/screen.css +++ b/css/screen.css @@ -165,6 +165,7 @@ canvas { list-style-type: none; margin: 0; padding: 0; + word-wrap: break-word; } #list p { @@ -188,6 +189,7 @@ canvas { #list li { position: relative; + min-height: 3em; } .red #list li { border-bottom: 1px solid #c0392b; } @@ -199,7 +201,7 @@ canvas { content: ""; position: absolute; right: 7px; - top: 0.1em; + top: 0; font-weight: 100; font-size: 3em; font-family: "Entypo"; @@ -248,6 +250,7 @@ canvas { font-weight: normal; margin: 0; padding: 0; + display: none; } #full .wrapper { @@ -278,9 +281,28 @@ canvas { padding: 0; } +#full article header p:nth-child(1) { + float: left; +} + +#full article header p:nth-child(2) { + float: right; +} + +#full article header p:nth-child(3) { + clear: both; +} + +#full .article { + clear: both; + padding-top: 1em; + padding-bottom: 3em; + font-size: 1.3em; +} + #full footer.bar { margin: auto 0 0 0; - position: relative; + position: fixed; height: 3.8em; } diff --git a/index.html b/index.html index feaa4f4..ff6889e 100644 --- a/index.html +++ b/index.html @@ -94,8 +94,8 @@

-

+

diff --git a/js/App.js b/js/App.js index c874b84..d2cb11e 100644 --- a/js/App.js +++ b/js/App.js @@ -7,6 +7,20 @@ function App() { if(!color) color = "red"; this.setColor(color); this.fontChange(); + + var _this = this; + + window.onkeydown = function(e) { + if(e.keyCode == 39) { + _this.showNext(); + } else if(e.keyCode == 37) { + _this.showPrevious(); + } else if(e.keyCode == 13) { + _this.openInBrowser(); + } else if(e.keyCode == 82) { + _this.reload(); + } + } }; App.prototype.authenticate = function() { @@ -14,11 +28,11 @@ App.prototype.authenticate = function() { }; App.prototype.after_login = function(backend) { - + /* var request = window.navigator.mozApps.getSelf(); request.onsuccess = function() { $("#version").innerHTML = request.result.manifest.version; - } + }*/ var _this = this; @@ -182,8 +196,10 @@ App.prototype.populateList = function() { html_str += ""; html_str += ""; html_str += "

" + article.feed_title + "

"; - html_str += "

" + article.title + "

"; - if(article.excerpt) html_str += "

" + article.excerpt + "

"; + var content = article.content.stripHTML(); + if(content.replace(/^\s+|\s+$/g,'').length == 0) content = article.title; + html_str += "

" + content + "

"; + //if(article.excerpt) html_str += "

" + article.excerpt + "

"; html_str += "
"; } @@ -274,9 +290,9 @@ App.prototype.showFull = function(article, slide_back) { $(page_id + " .date").innerHTML = (new Date(parseInt(article.updated, 10) * 1000)).toLocaleString(); - var title = $(page_id + " .title"); - title.innerHTML = article.title; - title.href = article.link; + var link = $(page_id + " .link"); + link.innerHTML = article.link; + link.href = article.link; $(page_id + " .feed_title").innerHTML = article.feed_title; @@ -284,7 +300,9 @@ App.prototype.showFull = function(article, slide_back) { if(article.author && article.author.length > 0) $(page_id + " .author").innerHTML = "– " + article.author; - $(page_id + " .article").innerHTML = article.content; + var content = article.content; + if(content.replace(/^\s+|\s+$/g,'').length == 0) content = article.title; + $(page_id + " .article").innerHTML = content.urlify(); $$(page_id + " .article a").forEach(function(o, i) { o.target = "_blank"; }); @@ -325,6 +343,10 @@ App.prototype.showPrevious = function() { } }; +App.prototype.openInBrowser = function() { + $("#full .link").click(); +}; + App.prototype.setCurrentRead = function() { var article = this.unread_articles[this.currentIndex]; if(!article) return; // happens if we're not on a full article site diff --git a/js/Login.js b/js/Login.js index 72a9490..bc05ba8 100644 --- a/js/Login.js +++ b/js/Login.js @@ -17,19 +17,6 @@ Login.prototype.is_logged_in = function() { Login.prototype.log_in = function() { this.app.changeToPage("#login"); - $("#login form").backend.forEach(function(o, i) { - o.addEventListener("change", function(e) { - if(e.target.checked) { - if(e.target.value == "OwnCloud") { - $("#url").placeholder = "http://example.com/owncloud/"; - } else if(e.target.value == "Pond") { - $("#url").placeholder = "http://example.com/pond/"; - } else { - $("#url").placeholder = "http://example.com/tt-rss/"; - } - } - }); - }); $("#login form").addEventListener('submit', this.authenticate.bind(this)); }; @@ -38,11 +25,10 @@ Login.prototype.authenticate = function(e) { e.preventDefault(); e.stopPropagation(); - var backend = "TinyTinyRSS"; - if($("#login form").backend[1].checked) backend = "OwnCloud"; - else if($("#login form").backend[2].checked) backend = "Pond"; + var backend = "Pond"; - var server_url = $("#url").value; + var server_url = window.location.href.split("#")[0].replace(/\/FeedMonkey\//, ''); + console.log(server_url) var user = $("#un").value; var password = $("#pw").value; diff --git a/js/OwnCloud.js b/js/OwnCloud.js deleted file mode 100644 index 15776f1..0000000 --- a/js/OwnCloud.js +++ /dev/null @@ -1,254 +0,0 @@ -function OwnCloud(app, server_url, user_pass_btoa) { - this.app = app; - this.server_url = server_url; - this.session_id = user_pass_btoa; - this.feeds = {}; - var feeds = localStorage.feeds; - if(feeds) this.feeds = JSON.parse(feeds); - - window.addEventListener("offline", this.onoffline.bind(this)); - window.addEventListener("online", this.ononline.bind(this)); -} - -OwnCloud.prototype.onoffline = function() { - // Do nothing -}; - -OwnCloud.prototype.ononline = function() { - - ["read", "unread", "starred", "unstarred"].forEach(function(type) { - var articles = localStorage[type + "_articles"]; - if(articles) { - var callback = function(ok) { if(ok) localStorage[type + "_articles"] = null } - this.call("setArticles" + type.capitalize(), [JSON.parse(articles), callback]); - } - }); -}; - -OwnCloud.prototype.doOperation = function(method, operation, new_options, callback) { - if(!navigator.onLine) { - callback(null); - return; - } - - var url = this.server_url + "/index.php/apps/news/api/v1-2/" + operation; - var options = {}; - - for (var key in new_options) { - options[key] = new_options[key]; - } - - if(method == "GET" || method == "HEAD") { - var a = []; - for(var key in options) { - a.push(key + "=" + options[key]); - } - url += "?" + a.join("&"); - } - - var xhr = new XMLHttpRequest({mozSystem: true}); - xhr.onreadystatechange = function() { - if(xhr.readyState == 4) { - if(xhr.status == 200) { - if(callback) - callback(JSON.parse(xhr.responseText)); - } else { - if(xhr.status != 0) alert("error: " + xhr.status + " " + xhr.statusText); - if(callback) callback(null); - } - } - } - xhr.open(method, url, true); - xhr.withCredentials = true; - xhr.setRequestHeader('Authorization', 'Basic ' + this.session_id); - var body = JSON.stringify(options); - xhr.send(body); -} - -OwnCloud.prototype.reload = function(callback) { - var _this = this; - this.getFeeds(function() { _this.getUnreadFeeds(callback); }); -}; - -OwnCloud.prototype.getUnreadFeeds = function(callback, skip) { - if(skip) { - skip = skip[skip.length - 1].id; - } - - var options = { - batchSize: 700, - offset: skip || 0, - type: 3, - id: 0, - getRead: false - }; - - var _this = this; - this.doOperation("GET", "items", options, function(data) { - - var items = data.items; - - function isFeedAvailable(o) { - return !!_this.feeds[o.feedId]; - } - - if(items.every(isFeedAvailable)) { - callback(items.map(_this.normalize_article, _this)); - } else { - _this.getFeeds(function() { - callback(items.map(_this.normalize_article, _this)); - }); - } - }); -}; - - -OwnCloud.prototype.toString = function() { - return "OwnCloud" -}; - -OwnCloud.prototype.getFeeds = function(callback) { - var _this = this; - this.doOperation("GET", "feeds", {}, function(data) { - - _this.feeds = {}; - for (var i = 0; i < data.feeds.length; i++) { - var feed = data.feeds[i]; - _this.feeds[feed.id] = feed; - } - - localStorage.feeds = JSON.stringify(_this.feeds); - callback(); - }); -}; - -OwnCloud.prototype.setArticlesRead = function(articles, callback) { - - var options = { - items: articles.map(function(o) { return o.id; }), - }; - - if (navigator.onLine) { - this.doOperation("PUT", "items/read/multiple", options, callback); - } else { - this.append("read_articles", articles); - } -} - -OwnCloud.prototype.setArticleRead = function(article, callback) { - this.setArticlesRead([article], callback); -} - -OwnCloud.prototype.setArticlesUnread = function(articles, callback) { - - var options = { - items: articles.map(function(o) { return o.id; }), - }; - - if (navigator.onLine) this.doOperation("PUT", "items/unread/multiple", options, callback); - else { - this.append("unread_articles", articles); - } -}; - -OwnCloud.prototype.setArticleUnread = function(article, callback) { - this.setArticlesUnread([article], callback); -} - -OwnCloud.prototype.setArticlesStarred = function(articles, callback) { - - var options = { - items: articles.map(function(o) { return { feedId: o.feed_id, guidHash: o.guid_hash }; }) - }; - - if (navigator.onLine) { - this.doOperation("PUT", "items/star/multiple", options, callback); - } else { - this.append("starred_articles", articles); - } -}; - -OwnCloud.prototype.setArticleStarred = function(article, callback) { - this.setArticlesStarred([article], callback); -} - -OwnCloud.prototype.setArticlesUnstarred = function(articles, callback) { - - var options = { - items: articles.map(function(o) { return { feedId: o.feed_id, guidHash: o.guid_hash }; }) - }; - - if (navigator.onLine) { - this.doOperation("PUT", "items/unstar/multiple", options, callback); - } else { - this.append("unstarred_articles", articles); - } -}; - -OwnCloud.prototype.setArticleUnstarred = function(articles, callback) { - this.setArticlesUnstarred([articles], callback); -} - -OwnCloud.prototype.normalize_article = function(article) { - var feed = this.feeds[article.feedId]; - var feed_title = ""; - if(feed) { - feed_title = feed.title; - } - - return { - id: article.id, - guid_hash: article.guidHash, - title: article.title, - content: article.body, - feed_title: feed_title, - feed_id: article.feedId, - excerpt: article.body.stripHTML().substring(0, 100), - updated: article.pubDate, - link: article.link, - marked: article.starred, - unread: article.unread - } -}; - -OwnCloud.prototype.logOut = function() { - this.doOperation("logout"); - localStorage.feeds = null; -}; - -OwnCloud.prototype.getFeedFor = function(o) { - return this.feeds[o.feedId]; -}; - -OwnCloud.prototype.append = function(key, array) { - - var tmp = localStorage[key]; - - if (typeof tmp !== "undefined") tmp = JSON.parse(tmp); - else tmp = []; - - tmp.concat(options.items); - localStorage[key] = JSON.stringify(tmp); -}; - -OwnCloud.login = function(server_url, user, password, callback) { - - var url = server_url + "/index.php/apps/news/api/v1-2/version"; - - var xhr = new XMLHttpRequest({mozSystem: true}); - xhr.onreadystatechange = function() { - if(xhr.readyState == 4) { - if(xhr.status == 200) { - callback(JSON.parse(xhr.responseText)) - } else { - alert("error: " + xhr.status + " " + xhr.statusText) - } - } - } - - xhr.open("GET", url, true); - xhr.withCredentials = true; - var auth = btoa(user + ':' + password); - xhr.setRequestHeader('Authorization', 'Basic ' + auth); - xhr.send(); -} diff --git a/js/Pond.js b/js/Pond.js index 501494c..1c424a6 100644 --- a/js/Pond.js +++ b/js/Pond.js @@ -193,7 +193,7 @@ Pond.prototype.setArticleUnstarred = function(articles, callback) { } Pond.prototype.logOut = function() { - this.doOperation("auth/sessions/" + this.session_token ); + this.doOperation("DELETE", "auth/sessions/" + this.session_token ); localStorage.feeds = null; } diff --git a/js/TinyTinyRSS.js b/js/TinyTinyRSS.js deleted file mode 100644 index 4479f49..0000000 --- a/js/TinyTinyRSS.js +++ /dev/null @@ -1,183 +0,0 @@ -function TinyTinyRSS(app, server_url, session_id) { - this.app = app; - this.server_url = server_url; - this.session_id = session_id; - - window.addEventListener("offline", this.onoffline.bind(this)); - window.addEventListener("online", this.ononline.bind(this)); -} - -TinyTinyRSS.prototype.onoffline = function() { - // Do nothing -}; - -TinyTinyRSS.prototype.ononline = function() { - - ["read", "unread", "starred", "unstarred"].forEach(function(type) { - var articles = localStorage[type + "_articles"]; - if(articles) { - var callback = function(ok) { if(ok) localStorage[type + "_articles"] = null } - this.call("setArticles" + type.capitalize(), [JSON.parse(articles), callback]); - } - }); -}; - -TinyTinyRSS.prototype.doOperation = function(operation, new_options, callback) { - if(!navigator.onLine) { - callback(null); - return; - } - - var url = this.server_url + "/api/"; - var options = { - sid: this.session_id, - op: operation - }; - - for (var key in new_options) { - options[key] = new_options[key]; - } - - var xhr = new XMLHttpRequest({mozSystem: true}); - xhr.onreadystatechange = function() { - if(xhr.readyState == 4) { - if(xhr.status == 200) { - if(callback) - callback(JSON.parse(xhr.responseText).content); - } else { - if(xhr.status != 0) alert("error: " + xhr.status + " " + xhr.statusText); - if(callback) callback(null); - } - } - } - xhr.open("POST", url, true); - xhr.send(JSON.stringify(options)); -} - -TinyTinyRSS.prototype.reload = function(callback) { - this.getUnreadFeeds(callback, []); -}; - -TinyTinyRSS.prototype.getUnreadFeeds = function(callback, skip) { - skip = skip.length; - var options = { - show_excerpt: false, - view_mode: "unread", - show_content: true, - feed_id: -4, - skip: skip || 0 - }; - - this.doOperation("getHeadlines", options, callback); -} - -TinyTinyRSS.prototype.setArticlesRead = function(articles, callback) { - - var options = { - article_ids: articles.map(function(o) { return o.id }).join(","), - mode: 0, - field: 2 - }; - - if (navigator.onLine) { - this.doOperation("updateArticle", options, callback); - } else { - this.append("read_articles", articles); - } -}; - -TinyTinyRSS.prototype.setArticleRead = function(article, callback) { - this.setArticlesRead([article], callback); -}; - - -TinyTinyRSS.prototype.setArticlesUnread = function(articles, callback) { - - var options = { - article_ids: articles.map(function(o) { return o.id }).join(","), - mode: 1, - field: 2 - }; - - if (navigator.onLine) { - this.doOperation("updateArticle", options, callback); - } else { - this.append("unread_articles", articles); - } -}; - -TinyTinyRSS.prototype.setArticleUnread = function(article, callback) { - this.setArticlesUnread([article], callback); -}; - -TinyTinyRSS.prototype.setArticlesStarred = function(articles, callback) { - - var options = { - article_ids: articles.map(function(o) { return o.id }).join(","), - mode: 1, - field: 0 - }; - - if (navigator.onLine) { - this.doOperation("updateArticle", options); - } else { - this.append("starred_articles", articles); - } -}; - -TinyTinyRSS.prototype.setArticleStarred = function(article, callback) { - this.setArticlesStarred([article], callback); -}; - -TinyTinyRSS.prototype.setArticlesUnstarred = function(articles, callback) { - - var options = { - article_ids: articles.map(function(o) { return o.id}).join(","), - mode: 0, - field: 0 - }; - - if (navigator.onLine) { - this.doOperation("updateArticle", options, callback); - } else { - this.append("unstarred_articles", articles); - } -}; - -TinyTinyRSS.prototype.setArticleUnstarred = function(article, callback) { - this.setArticlesUnstarred([article], callback); -}; - -TinyTinyRSS.prototype.append = function(key, array) { - - var tmp = localStorage[key]; - - if (typeof tmp !== "undefined") tmp = JSON.parse(tmp); - else tmp = []; - - tmp.concat(options.items); - localStorage[key] = JSON.stringify(tmp); -}; - -TinyTinyRSS.prototype.logOut = function() { - this.doOperation("logout"); -}; - -TinyTinyRSS.login = function(server_url, user, password, callback) { - - var url = server_url + "/api/"; - var options = {op: "login", user: user, password: password}; - - var xhr = new XMLHttpRequest({mozSystem: true}); - xhr.onreadystatechange = function() { - if(xhr.readyState == 4) { - if(xhr.status == 200) { - callback(JSON.parse(xhr.responseText).content) - } else { - alert("error: " + xhr.status + " " + xhr.statusText) - } - } - } - xhr.open("POST", url, true); - xhr.send(JSON.stringify(options)); -} diff --git a/js/application.js b/js/application.js index 5e38312..ebacb08 100644 --- a/js/application.js +++ b/js/application.js @@ -63,5 +63,10 @@ String.prototype.capitalize = function() { return this.charAt(0).toUpperCase() + this.slice(1); } +String.prototype.urlify = function() { + var exp = /[^\>](https?:\/\/[^\s\<]*)/ig; + return this.replace(exp," $1"); +} + if(!window.app) window.app = new App();