gopherss/views/index.html

502 lines
22 KiB
HTML
Raw Permalink Normal View History

2020-10-17 18:02:52 +00:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gopherss</title>
2021-02-22 10:09:20 +00:00
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22></text><text text-anchor=%22end%22 y=%221.9em%22 x=%221.9em%22 font-size=%2250%22>10</text></svg>">
2020-11-08 19:24:55 +00:00
<meta name="apple-mobile-web-app-capable" content="yes">
<!-- <link rel="apple-touch-icon" href="static/icon.png"> -->
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link rel="manifest" href="/manifest.json">
<script>
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js');
}
</script>
2021-05-15 10:03:19 +00:00
<script src="/static/feed-item.js" defer></script>
<script src="/static/favicon.js"></script>
2020-10-17 13:30:30 +00:00
2020-10-17 18:50:13 +00:00
<script src="https://unpkg.com/vue@2.5.17/dist/vue.min.js"></script>
2021-05-15 10:24:50 +00:00
<script src="https://cdn.jsdelivr.net/npm/vue-progressbar@0.7.5/dist/vue-progressbar.min.js"></script>
2020-11-07 16:30:55 +00:00
<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>
<script src="https://unpkg.com/dayjs@1.9.5/plugin/relativeTime.js"></script>
<script>dayjs.extend(window.dayjs_plugin_relativeTime)</script>
2020-10-17 13:30:30 +00:00
2020-10-17 18:02:52 +00:00
<link rel="stylesheet" href="https://unpkg.com/hack@0.8.1/dist/hack.css">
<link rel="stylesheet" href="https://unpkg.com/hack@0.8.1/dist/dark.css">
<link rel="stylesheet" href="https://unpkg.com/hack@0.8.1/dist/dark-grey.css">
2020-10-17 18:50:13 +00:00
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@500&display=swap" rel="stylesheet">
2020-10-17 13:30:30 +00:00
2020-10-17 18:02:52 +00:00
<link rel="stylesheet" href="/static/style.css">
</head>
<body class="hack">
2020-11-18 19:45:39 +00:00
<div id="app" class="container">
<header>
<button class="feed-toggle" v-on:click="toggleFeeds">
<svg width="24" height="24" viewbox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M24 16a3.5 3.5 0 110-7 3.5 3.5 0 010 7z" fill="#212121"/><path d="M24 27.5a3.5 3.5 0 110-7 3.5 3.5 0 010 7z" fill="#212121"/><path d="M20.5 35.5a3.5 3.5 0 107 0 3.5 3.5 0 00-7 0z" fill="#212121"/></svg>
</button>
2020-10-17 18:02:52 +00:00
<h1 class="title">
Gopherss
</h1>
2020-11-18 19:45:39 +00:00
</header>
2020-10-17 13:30:30 +00:00
2020-11-18 19:45:39 +00:00
<div>
2020-10-17 18:02:52 +00:00
<div class="menu">
2020-11-08 19:38:55 +00:00
<button title="Show Read" v-on:click="toggleShowRead()">
2020-11-09 20:14:35 +00:00
<svg width="30" height="30" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 9a4 4 0 110 8 4 4 0 010-8zm0-3.5a10 10 0 019.7 7.6.8.8 0 01-1.5.3 8.5 8.5 0 00-16.4 0 .8.8 0 01-1.5-.3A10 10 0 0112 5.5z" :style="{'fill': showRead ? '#ff2e88' : '' }" fill-rule="nonzero"/></svg>
2020-11-08 19:38:55 +00:00
</button>
2020-10-17 18:02:52 +00:00
<button title="Toggle dark mode" v-on:click="toggleDarkMode()">
<svg width="30" height="30" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M12 22a10 10 0 100-20 10 10 0 000 20zm0-2V4a8 8 0 110 16z" fill="#212121" fill-rule="nonzero"/></svg>
</button>
<button title="Mark all as read" v-on:click="markAllRead()" :disabled="isBusy">
<svg width="30" height="30" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M18.8 3C20 3 21 4 21 5.3v13.4c0 1.3-1 2.3-2.2 2.3H5.3C4 21 3 20 3 18.7V5.3C3 4 4 3 5.3 3zm-3.6 5.7l-4.4 4.5-1.5-1.5a.7.7 0 00-1 1l2 2c.2.4.7.4 1 0l5-5a.8.8 0 00-1-1z" fill="#212121" fill-rule="nonzero"/></svg>
</button>
<button title="Refresh all feeds" v-on:click="refresh()" :disabled="isBusy">
<svg width="30" height="30" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><path d="M20 7.7c.3 0 .6.1.8.4a7 7 0 01-5.5 11l-.3-.1H9.4l1.3 1.3a1 1 0 01-1.3 1.5l-.1-.1-3-3a1 1 0 010-1.3v-.1l3-3a1 1 0 011.3-.1h.1v.2c.4.3.4.8 0 1.2v.1L9.4 17H15a5 5 0 004.2-7.8 1 1 0 01.8-1.5zm-5.4-5.5h.1l3 3c.4.5.4 1 .1 1.4v.1l-3 3a1 1 0 01-1.6-1.3l.1-.1L14.6 7H9a5 5 0 00-4.3 7.5l.1.2.2.6a1 1 0 01-1.8.6A7 7 0 018.8 5h5.8l-1.3-1.3a1 1 0 010-1.3v-.1a1 1 0 011.3 0z" fill="#212121" fill-rule="nonzero"/></svg>
</button>
</div>
2020-10-17 13:30:30 +00:00
2020-10-17 18:02:52 +00:00
<div class="feeds">
2020-10-17 18:50:13 +00:00
<div :class="{ strong: items.length, alert: true, 'alert-success': selectedFeed == ''}" v-on:click="loadFeed('')">
2020-10-17 19:52:23 +00:00
All ({{unread}})
2020-10-17 18:02:52 +00:00
</div>
2020-10-17 13:30:30 +00:00
2021-02-21 10:34:44 +00:00
<div v-for="feed in sortedFeeds" :class="{strong: unreadCounts[feed.ID], 'alert': true, 'alert-success': selectedFeed == feed.ID }" :data-feed="feed.FeedURL" v-on:click="loadFeed(feed.ID)">
2020-11-09 20:55:46 +00:00
<img :src="feedIcon(feed)" style="height: 16px; width: 16px;" onerror="this.style.visibility = 'hidden'" /> {{feed.Title}} ({{unreadCounts[feed.ID] || '0'}})
2021-02-21 10:29:07 +00:00
<div style="float:right">
<button title="Delete Feed" v-on:click="deleteFeed(feed)" :disabled="isBusy">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="16px" width="16px" viewBox="0 0 473 473" enable-background="new 0 0 473 473"><g><path d="M317.7 214.4l5.6-86.4h21V38h-98.4V0H132.7v38H34.3v90h21l20 305h140.5a129.6 129.6 0 00223-89.4c0-68.6-53.7-124.8-121.1-129.2zM162.7 30h53.2v8h-53.2v-8zM64.3 68h250v30h-250V68zm39 335l-18-275h208l-5.8 88a129.6 129.6 0 00-93.2 187h-91zm206 40a99.5 99.5 0 010-198.9 99.5 99.5 0 010 198.9z"/><path d="M342.2 289.4l-33 33-32.9-33-21.2 21.2 33 33-33 33 21.2 21.1 33-33 33 33 21.2-21.2-33-33 33-32.9z"/></g><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/><g/></svg>
</button>
</div>
2020-10-17 18:02:52 +00:00
</div>
2020-10-17 13:30:30 +00:00
2020-11-08 20:19:41 +00:00
<div :class="{ strong: items.length, alert: true, 'alert-success': selectedFeed == 'SAVED'}" v-on:click="loadFeed('SAVED')">
<svg viewBox="0 0 24 24" width="18" height="18" xmlns="http://www.w3.org/2000/svg"><path d="M12.8 5.6l-.8.8-.8-.8a5.4 5.4 0 00-7.6 7.6l7.9 7.9c.3.3.7.3 1 0l8-8a5.4 5.4 0 10-7.7-7.5z" style="fill: #ff2e88" fill-rule="nonzero"/></svg>
Saved ({{saved}})
</div>
2020-10-17 18:02:52 +00:00
<div class="menu">
<button title="Add New Site" v-on:click="showAddModal = true" :disabled="isBusy">
<svg width="30" height="30" viewbox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M17.8 3C19.5 3 21 4.5 21 6.3V12a6.5 6.5 0 00-8.2 1H8.6a.8.8 0 000 1.5h3.1A6.5 6.5 0 0012 21H6.3A3.3 3.3 0 013 17.7V9.4A2.2 2.2 0 103.2 5C3.7 3.9 5 3 6.2 3h11.6zm-2.5 6.5H8.7a.8.8 0 000 1.5h6.6a.8.8 0 000-1.5z" fill="#212121"/><path d="M3.8 6a1.3 1.3 0 110 2.5 1.3 1.3 0 010-2.5z" fill="#212121"/><path d="M23 17.5a5.5 5.5 0 10-11 0 5.5 5.5 0 0011 0zm-5 .5v2.5a.5.5 0 11-1 0V18h-2.5a.5.5 0 010-1H17v-2.5a.5.5 0 111 0V17h2.5a.5.5 0 010 1H18z" fill="#212121"/></svg>
</button>
</div>
2020-10-17 13:30:30 +00:00
2020-10-17 18:02:52 +00:00
<div v-show="showAddModal" class="card">
<header class="card-header">Add New Site</header>
<div class="card-content">
<div class="inner">
<fieldset class="form-group">
<label for="url">URL:</label>
<input id="url" type="text" placeholder="" class="form-control" v-model="newSiteURL">
</fieldset>
<div class="form-actions">
<button type="button" class="btn btn-primary btn-block" v-on:click="addSite(newSiteURL)" :disabled="isBusy">Add</button>
</div>
2020-10-17 13:30:30 +00:00
2020-10-17 18:02:52 +00:00
<fieldset class="form-group">
<label for="opml">Import OPML:</label>
<input id="opml" name="opml" type="file" class="form-control" v-on:change="loadOPML">
</fieldset>
<div class="form-actions">
<button type="button" class="btn btn-primary btn-block" v-on:click="importOPML()" :disabled="isBusy">Import</button>
</div>
</div>
</div>
</div>
</div>
2020-10-17 13:30:30 +00:00
2020-10-17 18:02:52 +00:00
<div class="items">
<div v-for="item in shownItems" :id="item.ID">
2020-11-09 20:38:24 +00:00
<div :class="{'alert': true, 'alert-info': !item.Read && !item.PendingRead, 'item-heading': true}" :data-feed="item.FeedHomepageURL" v-on:click="loadItem(item)">
2020-10-17 18:02:52 +00:00
<span class="feed-title">{{item.FeedTitle}}</span>
2020-11-07 16:30:55 +00:00
<span class="date" :title="item.Created">{{ dayjs(item.Created).fromNow() }}</span>
2020-11-07 16:31:28 +00:00
<h3 class="item-title">{{item.Title}} <a :href="item.URL"></a></h3>
2020-10-17 18:02:52 +00:00
</div>
2020-10-17 19:52:23 +00:00
<div class="card item-content" :data-id="item.ID" v-if="item.ID == selectedItem">
2020-10-17 18:02:52 +00:00
<div class="card-content">
2020-11-08 20:19:41 +00:00
<div class="menu">
2021-02-21 09:55:33 +00:00
<button title="Show IFrame" v-on:click="showIframe(item)" :disabled="isBusy">
2021-03-17 09:07:46 +00:00
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 426 426" ><path d="M406.8 54.2H19.2A19.2 19.2 0 000 73.4v279.2c0 10.6 8.6 19.2 19.2 19.2h387.6c10.6 0 19.2-8.6 19.2-19.2V73.4c0-10.6-8.6-19.2-19.2-19.2zM368.4 82a17.8 17.8 0 110 35.7 17.8 17.8 0 010-35.7zm-48 0a17.8 17.8 0 110 35.7 17.8 17.8 0 010-35.7zm-48 0a17.8 17.8 0 110 35.7 17.8 17.8 0 010-35.7zm115.2 251.5H38.4V141.6h349.2v191.8z" :style="{'fill': item.IframeVisible ? '#ff2e88' : '' }" fill-rule="nonzero"/></svg>
2021-02-21 09:55:33 +00:00
</button>
2020-11-08 20:19:41 +00:00
<button title="Save" v-on:click="saveItem(item)" :disabled="isBusy">
2020-11-09 20:14:35 +00:00
<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg"><path d="M12.8 5.6l-.8.8-.8-.8a5.4 5.4 0 00-7.6 7.6l7.9 7.9c.3.3.7.3 1 0l8-8a5.4 5.4 0 10-7.7-7.5z" :style="{'fill': item.Save ? '#ff2e88' : '' }" fill-rule="nonzero"/></svg>
2020-11-08 20:19:41 +00:00
</button>
</div>
2020-10-17 18:50:13 +00:00
<feed-item :item-id="item.ID" :class="{ dark: isDark }"></feed-item>
2020-10-17 18:02:52 +00:00
</div>
</div>
</div>
<div v-show="shownItems.length == 0">
<div class="no-items alert">
No Items to Show
</div>
</div>
</div>
2020-10-17 13:30:30 +00:00
2021-05-15 10:24:50 +00:00
<vue-progress-bar></vue-progress-bar>
2020-10-17 18:02:52 +00:00
</div>
2020-10-17 13:30:30 +00:00
2020-10-17 18:02:52 +00:00
<script>
function isInViewport(element) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
2021-05-15 10:24:50 +00:00
Vue.use(VueProgressBar, {
color: '#00bcd4',
failedColor: '#ff2e88',
thickness: '5px',
transition: {
speed: '1s',
opacity: '0.8s',
termination: 100
},
autoRevert: true,
location: 'top',
inverse: false
});
2020-10-17 18:02:52 +00:00
const vm = new Vue({
el: '#app',
data: {
feeds: [],
items: [],
2020-11-08 20:19:41 +00:00
savedItems: [],
2020-10-17 18:02:52 +00:00
selectedFeed: '',
selectedItem: undefined,
showAddModal: false,
newSiteURL: '',
opml: '',
isBusy: false,
2020-10-17 18:50:13 +00:00
isDark: false,
2020-11-08 19:38:55 +00:00
showRead: false,
2020-10-17 18:02:52 +00:00
},
computed: {
shownItems() {
if (this.selectedFeed === '') {
2020-11-08 20:01:45 +00:00
return this.items.filter(item => item.ID == this.selectedItem || !item.Read || item.Read === this.showRead);
2020-11-08 20:19:41 +00:00
} else if (this.selectedFeed === 'SAVED') {
return this.savedItems;
2020-10-17 18:02:52 +00:00
} else {
2020-11-08 20:01:45 +00:00
return this.items.filter(item => item.ID == this.selectedItem || item.FeedID === this.selectedFeed && (!item.Read || item.Read === this.showRead));
2020-10-17 18:02:52 +00:00
}
2020-10-17 19:52:23 +00:00
},
2021-02-21 10:34:44 +00:00
sortedFeeds() {
return this.feeds.sort((a, b) => a.Title.toLowerCase() > b.Title.toLowerCase());
},
2020-10-17 19:52:23 +00:00
unread() {
2020-11-10 15:58:02 +00:00
return this.items.filter(item => !item.Read && !item.PendingRead).length;
2020-11-07 16:31:38 +00:00
},
2020-11-08 20:19:41 +00:00
saved() {
return this.savedItems.length;
},
2020-11-07 16:31:38 +00:00
unreadCounts() {
2020-11-10 15:58:02 +00:00
return this.items.filter(item => !item.Read && !item.PendingRead).reduce((acc, item) => {
2020-11-07 16:31:38 +00:00
if (!acc[item.FeedID]) acc[item.FeedID] = 0;
acc[item.FeedID]++;
return acc;
}, {})
2020-10-17 18:02:52 +00:00
}
},
methods: {
2020-11-09 20:38:24 +00:00
setPageTitle() {
document.title = `Gopherss (${this.unread})`;
2021-02-22 09:46:07 +00:00
setFavicon(this.unread);
2020-11-09 20:38:24 +00:00
},
2020-10-17 18:02:52 +00:00
setBusy(isBusy) {
2021-05-15 10:24:50 +00:00
if (isBusy) {
this.$Progress.start();
} else {
this.$Progress.finish();
}
2020-10-17 18:02:52 +00:00
this.isBusy = isBusy;
document.body.style.cursor = isBusy ? "wait" : "";
2020-11-09 20:38:24 +00:00
this.setPageTitle();
2020-10-17 18:02:52 +00:00
},
toggleDarkMode() {
2020-10-17 18:50:13 +00:00
this.isDark = !this.isDark;
2020-10-17 18:02:52 +00:00
document.body.classList.toggle('dark');
document.body.classList.toggle('dark-grey');
},
loadFeed(feed) {
this.selectedItem = undefined;
2021-03-17 09:07:46 +00:00
this.items.forEach(item => {
item.Read = item.Read || item.PendingRead;
item.IframeVisible = false;
});
2020-10-17 18:02:52 +00:00
this.selectedFeed = feed;
2020-11-09 21:22:35 +00:00
window.location.hash = feed;
2020-10-17 18:02:52 +00:00
},
loadItem(item) {
2020-11-18 19:12:31 +00:00
this.setBusy(true);
2020-10-17 18:02:52 +00:00
if (this.selectedItem === item.ID) {
this.selectedItem = undefined;
} else {
this.selectedItem = item.ID;
if (!isInViewport(document.getElementById(this.selectedItem))) {
document.getElementById(this.selectedItem).scrollIntoView();
}
2020-11-09 20:38:24 +00:00
item.PendingRead = true;
2020-10-17 18:02:52 +00:00
fetch(`/api/read/${item.ID}`, {method: "POST"})
}
2020-11-18 19:12:31 +00:00
this.setBusy(false);
2020-10-17 18:02:52 +00:00
},
2020-11-08 20:19:41 +00:00
saveItem(item) {
this.setBusy(true);
fetch(`/api/item/${item.ID}/save`, {method: "POST"})
.then(() => {
item.Save = !item.Save;
if (item.Save) {
this.savedItems.push(item);
} else {
this.savedItems = this.savedItems.filter(i => item.ID != i.ID);
}
this.setBusy(false);
})
},
2021-02-21 09:55:33 +00:00
showIframe(item) {
2021-03-17 09:07:46 +00:00
item.IframeVisible = !item.IframeVisible;
2021-02-21 09:55:33 +00:00
document.querySelector(`feed-item[item-id='${item.ID}'`).showIframe();
},
2021-02-21 10:29:07 +00:00
deleteFeed(feed) {
if (confirm(`Are you sure you want to remove '${feed.Title}'`)) {
this.setBusy(true);
fetch(`/api/feed/${feed.ID}`, {method: "DELETE"})
.then(() => {
this.feeds = this.feeds.filter(f => f.ID != feed.ID);
this.items = this.items.filter(i => i.FeedID != feed.ID);
this.setBusy(false);
});
}
},
2020-10-17 18:02:52 +00:00
nextItem() {
let currentItem = -1;
if (this.selectedItem != undefined) {
currentItem = this.shownItems.findIndex(item => item.ID == this.selectedItem);
}
this.loadItem(this.shownItems[currentItem+1]);
},
prevItem() {
let currentItem = this.shownItems.length;
if (this.selectedItem != undefined) {
currentItem = this.shownItems.findIndex(item => item.ID == this.selectedItem);
}
this.loadItem(this.shownItems[currentItem-1]);
},
refresh() {
this.setBusy(true);
fetch(`/api/refresh`)
.then(res => res.json())
.then(items => {
this.items = items;
})
.then(() => {
this.setBusy(false);
})
.catch(err => {
console.error(err);
this.setBusy(false);
});
},
markAllRead() {
let ids = this.shownItems.filter(item => !item.Read).map(item => item.ID);
2020-11-08 19:54:44 +00:00
if (ids.length > 0 && confirm(`Are you sure you want to mark ${ids.length} items as read?`)) {
2020-11-07 16:31:38 +00:00
this.setBusy(true);
2020-11-08 19:54:44 +00:00
this.shownItems.filter(item => !item.Read).forEach(item => item.Read = true)
2020-11-07 16:31:38 +00:00
fetch(
`/api/read`,
{method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(ids)}
)
.then(() => {
this.setBusy(false);
})
.catch(err => {
console.error(err);
this.setBusy(false);
});
2020-11-07 16:31:10 +00:00
}
2020-10-17 18:02:52 +00:00
},
addSite(url) {
this.setBusy(true);
fetch(
`/api/feeds`,
{method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(url)}
)
.then(res => res.json())
.then(feed => {
if (!this.feeds.some(f => f.ID === feed.ID)) {
this.items.push(...feed.Items);
this.feeds.push(feed);
}
})
.then(() => {
this.setBusy(false);
2021-03-17 08:02:14 +00:00
this.newSiteURL = '';
2020-10-17 18:02:52 +00:00
})
.catch(err => {
console.error(err);
this.setBusy(false);
2021-03-17 08:02:14 +00:00
this.newSiteURL = '';
2020-10-17 18:02:52 +00:00
});
this.showAddModal = false;
},
loadOPML(event) {
const fReader = new FileReader();
fReader.onload = () => {
this.opml = atob(fReader.result.replace("data:text/xml;base64,", ""));
}
fReader.readAsDataURL(event.target.files[0]);
},
importOPML() {
this.setBusy(true);
fetch("/opml", {
method: "POST",
headers: {
"Content-Type": "text/xml",
},
body: this.opml
})
.then(res => res.json())
.then(feeds => {
for(let feed of feeds) {
if (!this.feeds.some(f => f.ID === feed.ID)) {
this.items.push(...feed.Items);
this.feeds.push(feed);
}
}
})
.then(() => {
this.setBusy(false);
})
.catch(err => {
console.error(err);
this.setBusy(false);
});
2020-11-08 19:38:55 +00:00
},
toggleShowRead() {
this.showRead = !this.showRead;
if (this.showRead && !this.items.some(item => item.Read)) {
this.setBusy(true);
fetch('/api/all').then(res => res.json()).then(items => this.items = items)
.then(() => {
this.setBusy(false);
})
.catch(err => {
console.error(err);
this.setBusy(false);
});
}
2020-11-09 20:55:46 +00:00
},
feedIcon(feed) {
if (feed.ImageURL) {
return feed.ImageURL;
}
return "https://s2.googleusercontent.com/s2/favicons?domain_url=" + (feed.HomepageURL || feed.FeedURL);
2020-11-18 19:45:39 +00:00
},
toggleFeeds() {
document.querySelector('.feeds').classList.toggle('show-mobile');
2020-10-17 18:02:52 +00:00
}
},
created() {
this.setBusy(true);
Promise.all([
fetch(`/api/feeds`).then(res => res.json()).then(feeds => this.feeds = feeds),
2021-03-17 09:07:46 +00:00
fetch(`/api/unread`).then(res => res.json()).then(items => this.items = items.map(item => {item.PendingRead = false; item.IframeVisible = false; return item;})),
2020-11-08 20:19:41 +00:00
fetch(`/api/saved`).then(res => res.json()).then(items => this.savedItems = items)
2020-10-17 18:02:52 +00:00
])
.then(() => {
this.setBusy(false);
2020-11-09 21:22:35 +00:00
if (window.location.hash.length > 1) {
this.loadFeed(window.location.hash.substr(1));
}
2020-10-17 18:02:52 +00:00
})
.catch(err => {
console.error(err);
this.setBusy(false);
});
},
mounted() {
this._keyListener = function(e) {
switch(e.key) {
case "j":
return this.nextItem();
case "k":
return this.prevItem();
case "m":
return this.markAllRead()
case "o":
// TODO: Open item in new tab
return
case "a":
this.showAddModal = true;
setTimeout(() => {
document.getElementById('url').focus();
}, 200)
return;
case "r":
return this.refresh()
}
};
2020-10-17 13:30:30 +00:00
let inView = true;
window.onfocus = window.onblur = window.onpageshow = window.onpagehide = function (e) {
if ({focus:1, pageshow:1}[e.type]) {
if (inView) return;
inView = true;
} else if (inView) {
inView = false;
}
};
2020-11-18 19:18:08 +00:00
// Fetch updates every 5 minutes
setInterval(() => {
if (!inView) {
fetch(`/api/unread`)
.then(res => res.json())
.then(items => {
if (!this.showRead) {
if (this.selectedItem && !items.some(i => i.ID == this.selectedItem)) {
items.unshift(this.items.find(i => i.ID == this.selectedItem));
}
this.items = items;
} else {
for (let item of items) {
if (!this.items.some(i => i.ID == item.ID)) {
this.items.unshift(item);
}
}
2020-11-18 19:18:08 +00:00
}
this.setPageTitle();
});
}
2020-11-18 19:18:08 +00:00
}, 5 * 60 * 1000);
2020-10-17 18:02:52 +00:00
document.addEventListener('keydown', this._keyListener.bind(this));
2020-10-17 18:50:13 +00:00
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
this.toggleDarkMode();
}
2020-10-17 18:02:52 +00:00
},
beforeDestroy() {
document.removeEventListener('keydown', this._keyListener);
}
});
</script>
</div>
</body>
</html>