898 lines
38 KiB
HTML
Raw Normal View History

2022-10-18 22:39:32 -04:00
<style>
#rssView {
padding: 20px 20px 0 20px;
2022-10-18 22:39:32 -04:00
height: calc(100% - 20px);
}
#rssContentView {
display: table;
width: 100%;
height: calc(100% - 30px);
2022-10-18 22:39:32 -04:00
vertical-align: top;
}
#rssFeedFixedHeaderDiv .dynamicTableHeader,
#rssArticleFixedHeaderDiv .dynamicTableHeader {
cursor: default;
}
.alignRight {
float: right;
}
.unreadArticle {
color: var(--color-text-blue);
2022-10-18 22:39:32 -04:00
}
#rssFetchingDisabled {
color: var(--color-text-red);
2022-10-18 22:39:32 -04:00
font-style: italic;
margin-bottom: 10px;
}
#centerRssColumn {
margin: 0 10px 0 10px;
}
#leftRssColumn,
#centerRssColumn,
#rightRssColumn {
float: left;
/* should be 20 px but due to rounding differences some browsers don't render that properly */
width: calc((100% - 21px) / 3);
2022-10-18 22:39:32 -04:00
border: none;
}
#rightRssColumn {
overflow: auto;
}
#rssFeedTableDiv,
#rssArticleTableDiv {
height: calc(100vh - 180px);
}
#rssTorrentDetailsName {
background-color: var(--color-background-blue);
2022-10-18 22:39:32 -04:00
padding: 0;
color: var(--color-text-white);
2022-10-18 22:39:32 -04:00
}
#rssTorrentDetailsDate {
background-color: var(--color-background-default);
2022-10-18 22:39:32 -04:00
}
#rssDetailsView {
height: calc(100vh - 135px);
overflow: auto;
}
#rssButtonBar {
overflow: hidden;
height: 30px;
}
#rssButtonBar button {
padding: 4px 6px;
}
#rssButtonBar button img {
margin: 0 5px -3px 0;
}
2022-10-18 22:39:32 -04:00
#rssContentView table {
width: 100%;
}
#rssDescription {
width: 100%;
border: none;
}
2022-10-18 22:39:32 -04:00
</style>
<div id="rssView">
<div id="rssTopBar">
<div id="rssFetchingDisabled" class="invisible">
Fetching of RSS feeds is disabled now! You can enable it in application settings.
2022-10-18 22:39:32 -04:00
</div>
<div id="rssButtonBar">
<button type="button" id="newSubscriptionButton" onclick="qBittorrent.Rss.addRSSFeed()">
<img alt="New subscription" src="images/list-add.svg" width="16" height="16">New subscription
</button>
<button type="button" id="markReadButton" onclick="qBittorrent.Rss.markSelectedAsRead()">
<img alt="Mark items read" src="images/task-complete.svg" width="16" height="16">Mark items read
</button>
<button type="button" id="updateAllButton" onclick="qBittorrent.Rss.refreshAllFeeds()">
<img alt="Update all" src="images/view-refresh.svg" width="16" height="16">Update all
</button>
<button type="button" id="rssDownloaderButton" class="alignRight" onclick="qBittorrent.Rss.openRssDownloader()">
<img alt="RSS Downloader..." src="images/downloading.svg" width="16" height="16">RSS Downloader...
</button>
2022-10-18 22:39:32 -04:00
</div>
</div>
<div id="rssContentView">
<div id="leftRssColumn">
<div id="rssFeedFixedHeaderDiv" class="dynamicTableFixedHeaderDiv">
2022-10-18 22:39:32 -04:00
<table class="dynamicTable unselectable">
<thead>
<tr class="dynamicTableHeader"></tr>
</thead>
</table>
</div>
<div id="rssFeedTableDiv" class="dynamicTableDiv">
2022-10-18 22:39:32 -04:00
<table class="dynamicTable unselectable">
<thead>
<tr class="dynamicTableHeader"></tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div id="centerRssColumn">
<div id="rssArticleFixedHeaderDiv" class="dynamicTableFixedHeaderDiv">
2022-10-18 22:39:32 -04:00
<table class="dynamicTable unselectable">
<thead>
<tr class="dynamicTableHeader"></tr>
</thead>
</table>
</div>
<div id="rssArticleTableDiv" class="dynamicTableDiv">
2022-10-18 22:39:32 -04:00
<table class="dynamicTable unselectable">
<thead>
<tr class="dynamicTableHeader"></tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
<div id="rightRssColumn">
<div id="rssDetailsView"></div>
</div>
</div>
</div>
<ul id="rssFeedMenu" class="contextMenu">
<li><a href="#update"><img src="images/view-refresh.svg" alt="Update"> Update</a></li>
<li><a href="#markRead"><img src="images/task-complete.svg" alt="Mark items read"> Mark items read</a></li>
<li class="separator"><a href="#rename"><img src="images/edit-rename.svg" alt="Rename..."> Rename...</a></li>
<li><a href="#edit"><img src="images/edit-rename.svg" alt="Edit feed URL..."> Edit feed URL...</a></li>
<li><a href="#delete"><img src="images/edit-clear.svg" alt="Delete"> Delete</a></li>
<li class="separator"><a href="#newSubscription"><img src="images/list-add.svg" alt="New subscription..."> New subscription...</a></li>
<li><a href="#newFolder"><img src="images/folder-new.svg" alt="New folder..."> New folder...</a></li>
<li class="separator"><a href="#updateAll"><img src="images/view-refresh.svg" alt="Update all feeds"> Update all feeds</a></li>
<li class="separator"><a href="#copyFeedURL" id="CopyFeedURL"><img src="images/edit-copy.svg" alt="Copy feed URL"> Copy feed URL</a></li>
2022-10-18 22:39:32 -04:00
</ul>
<ul id="rssArticleMenu" class="contextMenu">
<li><a href="#Download"><img src="images/downloading.svg" alt="Download torrent"> Download torrent</a></li>
<li><a href="#OpenNews"><img src="images/application-url.svg" alt="Open news URL"> Open news URL</a></li>
2022-10-18 22:39:32 -04:00
</ul>
<script>
"use strict";
2022-10-18 22:39:32 -04:00
window.qBittorrent ??= {};
window.qBittorrent.Rss ??= (() => {
2022-10-18 22:39:32 -04:00
const exports = () => {
return {
init: init,
unload: unload,
load: load,
showRssFeed: showRssFeed,
showDetails: showDetails,
updateRssFeedList: updateRssFeedList,
refreshAllFeeds: refreshAllFeeds,
moveItem: moveItem,
addRSSFeed: addRSSFeed,
markSelectedAsRead: markSelectedAsRead,
openRssDownloader: openRssDownloader,
rssFeedTable: rssFeedTable
};
};
const serverSyncRssDataInterval = 1500;
2022-10-18 22:39:32 -04:00
let feedData = {};
let pathByFeedId = new Map();
let feedRefreshTimer = -1;
const rssFeedTable = new window.qBittorrent.DynamicTable.RssFeedTable();
const rssArticleTable = new window.qBittorrent.DynamicTable.RssArticleTable();
2022-10-18 22:39:32 -04:00
const init = () => {
const pref = window.parent.qBittorrent.Cache.preferences.get();
2022-10-18 22:39:32 -04:00
if (!pref.rss_processing_enabled)
$("rssFetchingDisabled").removeClass("invisible");
2022-10-18 22:39:32 -04:00
// recalculate heights
const nonPageHeight = $("rssTopBar").getBoundingClientRect().height
+ $("desktopHeader").getBoundingClientRect().height
+ $("desktopFooterWrapper").getBoundingClientRect().height + 20;
$("rssDetailsView").style.height = "calc(100vh - " + nonPageHeight + "px)";
2022-10-18 22:39:32 -04:00
const nonTableHeight = nonPageHeight + $("rssFeedFixedHeaderDiv").getBoundingClientRect().height;
$("rssFeedTableDiv").style.height = "calc(100vh - " + nonTableHeight + "px)";
$("rssArticleTableDiv").style.height = "calc(100vh - " + nonTableHeight + "px)";
2022-10-18 22:39:32 -04:00
$("rssContentView").style.height = "calc(100% - " + $("rssTopBar").getBoundingClientRect().height + "px)";
2022-10-18 22:39:32 -04:00
const rssFeedContextMenu = new window.qBittorrent.ContextMenu.RssFeedContextMenu({
targets: ".rssFeedContextMenuTarget",
menu: "rssFeedMenu",
2022-10-18 22:39:32 -04:00
actions: {
update: (el) => {
const feedsToUpdate = new Set();
for (const rowId of rssFeedTable.selectedRows) {
const selectedPath = rssFeedTable.getRow(rowId).full_data.dataPath;
for (const row of rssFeedTable.getRowValues()) {
if ((row.full_data.dataPath.slice(0, selectedPath.length) === selectedPath) && (row.full_data.dataUid !== ""))
feedsToUpdate.add(row);
}
};
2022-10-18 22:39:32 -04:00
feedsToUpdate.forEach((feed) => refreshFeed(feed.full_data.dataUid));
},
markRead: markSelectedAsRead,
rename: (el) => {
moveItem(rssFeedTable.getRow(rssFeedTable.selectedRows[0]).full_data.dataPath);
},
edit: (el) => {
const data = rssFeedTable.getRow(rssFeedTable.selectedRows[0]).full_data;
editUrl(data.dataPath, data.dataUrl);
2022-10-18 22:39:32 -04:00
},
delete: (el) => {
const selectedDatapaths = rssFeedTable.selectedRows
.filter((rowID) => rowID !== "0")
.map((rowID) => rssFeedTable.getRow(rowID).full_data.dataPath);
2022-10-18 22:39:32 -04:00
// filter children
const reducedDatapaths = selectedDatapaths.filter((path) =>
2022-10-18 22:39:32 -04:00
selectedDatapaths.filter((innerPath) => path.slice(0, innerPath.length) === innerPath).length === 1
);
removeItem(reducedDatapaths);
},
newSubscription: addRSSFeed,
newFolder: addFolder,
updateAll: refreshAllFeeds
},
offsets: {
x: -16,
y: -57
}
});
rssFeedContextMenu.addTarget($("rssFeedTableDiv"));
2022-10-18 22:39:32 -04:00
// deselect feed when clicking on empty part of table
$("rssFeedTableDiv").addEventListener("click", (e) => {
2022-10-18 22:39:32 -04:00
rssFeedTable.deselectAll();
rssFeedTable.deselectRow();
});
$("rssFeedTableDiv").addEventListener("contextmenu", (e) => {
if (e.target.nodeName === "DIV") {
2022-10-18 22:39:32 -04:00
rssFeedTable.deselectAll();
rssFeedTable.deselectRow();
rssFeedContextMenu.updateMenuItems();
}
});
new ClipboardJS("#CopyFeedURL", {
2022-10-18 22:39:32 -04:00
text: () => {
let joined = "";
for (const rowID of rssFeedTable.selectedRows) {
const row = rssFeedTable.getRow(rowID);
if (row.full_data.dataUid !== "")
joined += `${row.full_data.dataUrl}\n`;
}
2022-10-18 22:39:32 -04:00
return joined.slice(0, -1);
}
});
rssFeedTable.setup("rssFeedTableDiv", "rssFeedFixedHeaderDiv", rssFeedContextMenu);
2022-10-18 22:39:32 -04:00
const rssArticleContextMenu = new window.qBittorrent.ContextMenu.RssArticleContextMenu({
targets: ".rssArticleElement",
menu: "rssArticleMenu",
2022-10-18 22:39:32 -04:00
actions: {
Download: (el) => {
let dlString = "";
for (const rowID of rssArticleTable.selectedRows)
dlString += `${rssArticleTable.getRow(rowID).full_data.torrentURL}\n`;
2022-10-18 22:39:32 -04:00
showDownloadPage([dlString]);
},
OpenNews: (el) => {
for (const rowID of rssArticleTable.selectedRows)
window.open(rssArticleTable.getRow(rowID).full_data.link);
2022-10-18 22:39:32 -04:00
}
},
offsets: {
x: -16,
y: -57
}
});
rssArticleTable.setup("rssArticleTableDiv", "rssArticleFixedHeaderDiv", rssArticleContextMenu);
2022-10-18 22:39:32 -04:00
updateRssFeedList();
load();
};
const unload = () => {
clearTimeout(feedRefreshTimer);
feedRefreshTimer = -1;
2022-10-18 22:39:32 -04:00
};
const load = () => {
feedRefreshTimer = setTimeout(() => {
updateRssFeedList();
load();
}, serverSyncRssDataInterval);
2022-10-18 22:39:32 -04:00
};
const addRSSFeed = () => {
let path = "";
2022-10-18 22:39:32 -04:00
if (rssFeedTable.selectedRows.length !== 0) {
const row = rssFeedTable.getRow(rssFeedTable.selectedRows[0]);
if (row.full_data.dataUid === "") {
2022-10-18 22:39:32 -04:00
path = row.full_data.dataPath;
}
else {
const lastIndex = row.full_data.dataPath.lastIndexOf("\\");
2022-10-18 22:39:32 -04:00
if (lastIndex !== -1)
path = row.full_data.dataPath.slice(0, lastIndex);
}
}
new MochaUI.Window({
id: "newFeed",
icon: "images/qbittorrent-tray.svg",
title: "Please type a RSS feed URL",
loadMethod: "iframe",
contentURL: "newfeed.html?path=" + encodeURIComponent(path),
2022-10-18 22:39:32 -04:00
scrollbars: false,
resizable: false,
maximizable: false,
width: 350,
height: 100
2022-10-18 22:39:32 -04:00
});
};
const addFolder = () => {
let path = "";
2022-10-18 22:39:32 -04:00
if (rssFeedTable.selectedRows.length !== 0) {
const row = rssFeedTable.getRow(rssFeedTable.selectedRows[0]);
if (row.full_data.dataUid === "") {
2022-10-18 22:39:32 -04:00
path = row.full_data.dataPath;
}
else {
const lastIndex = row.full_data.dataPath.lastIndexOf("\\");
2022-10-18 22:39:32 -04:00
if (lastIndex !== -1)
path = row.full_data.dataPath.slice(0, lastIndex);
}
}
new MochaUI.Window({
id: "newFolder",
icon: "images/qbittorrent-tray.svg",
title: "Please choose a folder name",
loadMethod: "iframe",
contentURL: "newfolder.html?path=" + encodeURIComponent(path),
2022-10-18 22:39:32 -04:00
scrollbars: false,
resizable: false,
maximizable: false,
width: 350,
height: 100
});
};
const showRssFeed = (path) => {
rssArticleTable.clear();
let rowCount = 0;
const childFeeds = new Set();
for (const row of rssFeedTable.getRowValues()) {
if ((row.full_data.dataPath.slice(0, path.length) === path) && (row.full_data.dataUid !== ""))
childFeeds.add(row.full_data.dataUid);
}
2022-10-18 22:39:32 -04:00
let visibleArticles = [];
for (const feedEntry in feedData) {
if (childFeeds.has(feedEntry)) {
2022-10-18 22:39:32 -04:00
visibleArticles.append(feedData[feedEntry]
.map((a) => {
a.feedUid = feedEntry;
return a;
}));
}
2022-10-18 22:39:32 -04:00
}
// filter read articles if "Unread" feed is selected
if (path === "")
2022-10-18 22:39:32 -04:00
visibleArticles = visibleArticles.filter((a) => !a.isRead);
visibleArticles.sort((e1, e2) => new Date(e2.date) - new Date(e1.date))
.each((torrentEntry) => {
rssArticleTable.updateRowData({
rowId: rowCount++,
name: torrentEntry.title,
link: torrentEntry.link,
torrentURL: torrentEntry.torrentURL,
feedUid: torrentEntry.feedUid,
dataId: torrentEntry.id,
isRead: torrentEntry.isRead
});
});
$("rssDetailsView").getChildren().each(c => c.destroy());
2022-10-18 22:39:32 -04:00
rssArticleTable.updateTable(false);
};
const showDetails = (feedUid, articleID) => {
markArticleAsRead(pathByFeedId.get(feedUid), articleID);
$("rssDetailsView").getChildren().each(c => c.destroy());
const article = feedData[feedUid].filter((article) => article.id === articleID)[0];
2022-10-18 22:39:32 -04:00
if (article) {
$("rssDetailsView").append((() => {
const torrentName = document.createElement("p");
torrentName.textContent = article.title;
torrentName.id = "rssTorrentDetailsName";
2022-10-18 22:39:32 -04:00
return torrentName;
})());
$("rssDetailsView").append((() => {
const torrentDate = document.createElement("div");
torrentDate.id = "rssTorrentDetailsDate";
2022-10-18 22:39:32 -04:00
const torrentDateDesc = document.createElement("b");
torrentDateDesc.textContent = "Date: ";
2022-10-18 22:39:32 -04:00
torrentDate.append(torrentDateDesc);
const torrentDateData = document.createElement("span");
torrentDateData.textContent = new Date(article.date).toLocaleString();
2022-10-18 22:39:32 -04:00
torrentDate.append(torrentDateData);
return torrentDate;
})());
// Place in iframe with sandbox attribute to prevent js execution
const torrentDescription = document.createRange().createContextualFragment('<iframe sandbox id="rssDescription"></iframe>');
$("rssDetailsView").append(torrentDescription);
document.getElementById("rssDescription").srcdoc = '<html><head><link rel="stylesheet" type="text/css" href="css/style.css"></head><body>' + article.description + "</body></html>";
2022-10-18 22:39:32 -04:00
// calculate height to fill screen
document.getElementById("rssDescription").style.height =
"calc(100% - " + document.getElementById("rssTorrentDetailsName").offsetHeight + "px - "
+ document.getElementById("rssTorrentDetailsDate").offsetHeight + "px - 5px)";
2022-10-18 22:39:32 -04:00
}
};
const updateRssFeedList = () => {
new Request.JSON({
url: "api/v2/rss/items",
method: "get",
2022-10-18 22:39:32 -04:00
noCache: true,
data: {
withData: true
},
onSuccess: (response) => {
// flatten folder structure
const flattenedResp = [];
const recFlatten = (current, name = "", depth = 0, fullName = "") => {
for (const child in current) {
if (!Object.hasOwn(current, child))
continue;
const currentFullName = fullName ? (fullName + "\\" + child) : child;
2022-10-18 22:39:32 -04:00
if (current[child].uid !== undefined) {
current[child].name = child;
current[child].isFolder = false;
current[child].depth = depth;
current[child].fullName = currentFullName;
flattenedResp.push(current[child]);
}
else {
flattenedResp.push({
name: child,
isFolder: true,
depth: depth,
fullName: currentFullName
});
recFlatten(current[child], child, depth + 1, currentFullName);
}
}
};
recFlatten(response);
// check if rows matches flattened response
const rssFeedRows = [...rssFeedTable.getRowValues()];
2022-10-18 22:39:32 -04:00
let match = false;
// subtract 'unread' row
if ((rssFeedRows.length - 1) === flattenedResp.length) {
2022-10-18 22:39:32 -04:00
match = true;
for (let i = 0; i < flattenedResp.length; ++i) {
if (((flattenedResp[i].uid ? flattenedResp[i].uid : "") !== rssFeedRows[i + 1].full_data.dataUid)
|| (flattenedResp[i].fullName !== rssFeedRows[i + 1].full_data.dataPath)
|| (flattenedResp[i].url !== rssFeedRows[i + 1].full_data.dataUrl)) {
2022-10-18 22:39:32 -04:00
match = false;
break;
}
}
}
if (match) {
// partial refresh
// update status
let statusDiffers = false;
for (let i = 0; i < flattenedResp.length; ++i) {
const oldStatus = rssFeedRows[i + 1].full_data.status;
let status = "default";
2022-10-18 22:39:32 -04:00
if (flattenedResp[i].hasError)
status = "hasError";
2022-10-18 22:39:32 -04:00
if (flattenedResp[i].isLoading)
status = "isLoading";
2022-10-18 22:39:32 -04:00
if (flattenedResp[i].isFolder)
status = "isFolder";
2022-10-18 22:39:32 -04:00
if (oldStatus !== status) {
statusDiffers = true;
rssFeedTable.updateRowData({
rowId: i + 1,
status: status
});
}
}
if (statusDiffers)
rssFeedTable.updateIcons();
// get currently opened feed
let openedFeedPath = undefined;
if (rssFeedTable.selectedRows.length !== 0) {
const lastSelectedRow = rssFeedTable.selectedRows.at(-1);
openedFeedPath = rssFeedTable.getRow(lastSelectedRow).full_data.dataPath;
2022-10-18 22:39:32 -04:00
}
// check if list of articles differs
let needsUpdate = false;
flattenedResp.filter((r) => !r.isFolder)
.each((r) => {
let articlesDiffer = true;
if (r.articles.length === feedData[r.uid].length) {
articlesDiffer = false;
for (let i = 0; i < r.articles.length; ++i) {
if (feedData[r.uid][i].id !== r.articles[i].id)
articlesDiffer = true;
}
}
if (articlesDiffer) {
// update unread count
const oldUnread = feedData[r.uid].map((art) => !art.isRead).filter((v) => v).length;
const newUnread = r.articles.map((art) => !art.isRead).filter((v) => v).length;
const unreadDifference = newUnread - oldUnread;
2022-10-18 22:39:32 -04:00
// find all parents (and self) and add unread difference
for (const row of rssFeedTable.getRowValues()) {
if (r.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath)
row.full_data.unread += unreadDifference;
}
2022-10-18 22:39:32 -04:00
needsUpdate = true;
// update data
feedData[r.uid] = r.articles;
// if feed that is open changed, reload
if ((openedFeedPath !== undefined) && (r.fullName.slice(0, openedFeedPath.length) === openedFeedPath))
2022-10-18 22:39:32 -04:00
showRssFeed(r.fullName);
}
else {
// calculate read difference and update feed data
let readDifference = 0;
let readChanged = false;
for (let i = 0; i < r.articles.length; ++i) {
const oldRead = feedData[r.uid][i].isRead ? 1 : 0;
const newRead = r.articles[i].isRead ? 1 : 0;
2022-10-18 22:39:32 -04:00
feedData[r.uid][i].isRead = r.articles[i].isRead;
readDifference += oldRead - newRead;
if (readDifference !== 0)
readChanged = true;
}
// if read on article changed
if (readChanged) {
needsUpdate = true;
// find all items that contain this rss feed and add read difference
for (const row of rssFeedTable.getRowValues()) {
if (r.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath)
row.full_data.unread += readDifference;
}
2022-10-18 22:39:32 -04:00
// if feed that is opened changed update dynamically
if ((openedFeedPath !== undefined) && (r.fullName.slice(0, openedFeedPath.length) === openedFeedPath)) {
2022-10-18 22:39:32 -04:00
for (let i = 0; i < r.articles.length; ++i) {
for (const row of rssArticleTable.getRowValues()) {
if ((row.full_data.feedUid === r.uid) && (row.full_data.dataId === r.articles[i].id)) {
row.full_data.isRead = r.articles[i].isRead;
break;
}
}
2022-10-18 22:39:32 -04:00
}
}
}
}
});
if (needsUpdate) {
rssFeedTable.updateTable(true);
rssArticleTable.updateTable(true);
}
}
else {
// full refresh
rssFeedTable.clear();
rssArticleTable.clear();
2022-10-18 22:39:32 -04:00
feedData = {};
pathByFeedId = new Map();
// Unread entry at top
rssFeedTable.updateRowData({
rowId: 0,
name: "Unread",
2022-10-18 22:39:32 -04:00
unread: 0,
status: "unread",
2022-10-18 22:39:32 -04:00
indentation: 0,
dataUid: "",
dataUrl: "",
dataPath: ""
2022-10-18 22:39:32 -04:00
});
let rowCount = 1;
for (const dataEntry of flattenedResp) {
2022-10-18 22:39:32 -04:00
if (dataEntry.isFolder) {
rssFeedTable.updateRowData({
rowId: rowCount,
name: dataEntry.name,
unread: 0,
status: "isFolder",
2022-10-18 22:39:32 -04:00
indentation: dataEntry.depth,
dataUid: "",
dataUrl: "",
2022-10-18 22:39:32 -04:00
dataPath: dataEntry.fullName
});
}
else {
let status = "default";
2022-10-18 22:39:32 -04:00
if (dataEntry.hasError)
status = "hasError";
2022-10-18 22:39:32 -04:00
if (dataEntry.isLoading)
status = "isLoading";
2022-10-18 22:39:32 -04:00
rssFeedTable.updateRowData({
rowId: rowCount,
name: dataEntry.name,
unread: 0,
status: status,
indentation: dataEntry.depth,
dataUid: dataEntry.uid,
dataUrl: dataEntry.url,
dataPath: dataEntry.fullName
});
// calculate number of unread
const numberOfUnread = dataEntry.articles.map((art) => !art.isRead).filter((v) => v).length;
2022-10-18 22:39:32 -04:00
// find all items that contain this rss feed and add unread count
for (const row of rssFeedTable.getRowValues()) {
if (dataEntry.fullName.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath)
row.full_data.unread += numberOfUnread;
}
2022-10-18 22:39:32 -04:00
pathByFeedId.set(dataEntry.uid, dataEntry.fullName);
feedData[dataEntry.uid] = dataEntry.articles;
}
++rowCount;
}
rssFeedTable.updateTable(false);
rssFeedTable.updateIcons();
}
}
}).send();
};
const refreshFeed = (feedUid) => {
// set icon to loading
for (const row of rssFeedTable.getRowValues()) {
2022-10-18 22:39:32 -04:00
if (row.full_data.dataUid === feedUid)
row.full_data.status = "isLoading";
}
2022-10-18 22:39:32 -04:00
rssFeedTable.updateIcons();
new Request({
url: "api/v2/rss/refreshItem",
method: "post",
2022-10-18 22:39:32 -04:00
data: {
itemPath: pathByFeedId.get(feedUid)
},
onFailure: (response) => {
if (response.status === 409)
alert(response.responseText);
}
}).send();
};
const refreshAllFeeds = () => {
for (const feedEntry in feedData) {
if (!Object.hasOwn(feedData, feedEntry))
continue;
2022-10-18 22:39:32 -04:00
refreshFeed(feedEntry);
}
2022-10-18 22:39:32 -04:00
};
const moveItem = (oldPath) => {
new MochaUI.Window({
id: "renamePage",
icon: "images/qbittorrent-tray.svg",
title: "Please choose a new name for this RSS feed",
loadMethod: "iframe",
contentURL: "rename_feed.html?oldPath=" + encodeURIComponent(oldPath),
scrollbars: false,
resizable: false,
maximizable: false,
width: 350,
height: 100
});
};
const editUrl = (path, url) => {
new MochaUI.Window({
id: "editFeedURL",
icon: "images/qbittorrent-tray.svg",
title: "Please type a RSS feed URL",
loadMethod: "iframe",
contentURL: new URI("editfeedurl.html").setData("path", path).setData("url", url).toString(),
2022-10-18 22:39:32 -04:00
scrollbars: false,
resizable: false,
maximizable: false,
width: 350,
height: 100
});
};
const removeItem = (paths) => {
const encodedPaths = paths.map((path) => encodeURIComponent(path));
new MochaUI.Window({
id: "confirmFeedDeletionPage",
icon: "images/qbittorrent-tray.svg",
title: "Deletion confirmation",
loadMethod: "iframe",
contentURL: "confirmfeeddeletion.html?paths=" + encodeURIComponent(encodedPaths.join("|")),
2022-10-18 22:39:32 -04:00
scrollbars: false,
resizable: false,
maximizable: false,
width: 350,
height: 70
});
};
const markItemAsRead = (path) => {
// feed data mark as read
for (const feedID in feedData) {
2022-10-18 22:39:32 -04:00
if (pathByFeedId.get(feedID).slice(0, path.length) === path)
feedData[feedID].each((el) => el.isRead = true);
}
2022-10-18 22:39:32 -04:00
// mark rows as read
for (const row of rssArticleTable.getRowValues())
row.full_data.isRead = true;
2022-10-18 22:39:32 -04:00
// find all children and set unread count to 0
for (const row of rssFeedTable.getRowValues()) {
if ((row.full_data.dataPath.slice(0, path.length) === path) && (path !== row.full_data.dataPath))
row.full_data.unread = 0;
}
2022-10-18 22:39:32 -04:00
// find selected row
let rowId, prevUnreadCount;
for (const row of rssFeedTable.getRowValues()) {
2022-10-18 22:39:32 -04:00
if (row.full_data.dataPath === path) {
rowId = row.full_data.rowId;
prevUnreadCount = row.full_data.unread;
}
}
2022-10-18 22:39:32 -04:00
// find all parents (and self) and subtract previous unread count
for (const row of rssFeedTable.getRowValues()) {
if (path.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath)
row.full_data.unread -= prevUnreadCount;
}
2022-10-18 22:39:32 -04:00
rssArticleTable.updateTable(false);
rssFeedTable.updateTable(true);
// send request
new Request({
url: "api/v2/rss/markAsRead",
method: "post",
2022-10-18 22:39:32 -04:00
data: {
itemPath: path
},
onFailure: (response) => {
if (response.status === 409)
alert(response.responseText);
}
}).send();
};
const markArticleAsRead = (path, id) => {
// find row
let rowId, name, uid, unread;
for (const row of rssFeedTable.getRowValues()) {
2022-10-18 22:39:32 -04:00
if (row.full_data.dataPath === path) {
rowId = row.full_data.rowId;
name = row.full_data.dataPath;
uid = row.full_data.dataUid;
unread = row.full_data.unread;
}
}
2022-10-18 22:39:32 -04:00
// update feed data
let prevReadState = true;
feedData[uid].each((article) => {
if (article.id === id) {
prevReadState = article.isRead;
article.isRead = true;
}
});
if (!prevReadState) {
// find all items that contain this feed and subtract 1
for (const row of rssFeedTable.getRowValues()) {
if (path.slice(0, row.full_data.dataPath.length) === row.full_data.dataPath)
row.full_data.unread -= 1;
}
2022-10-18 22:39:32 -04:00
rssFeedTable.updateTable(true);
new Request({
url: "api/v2/rss/markAsRead",
method: "post",
2022-10-18 22:39:32 -04:00
data: {
itemPath: path,
articleId: id
},
onFailure: (response) => {
if (response.status === 409)
alert(response.responseText);
}
}).send();
}
};
const markSelectedAsRead = () => {
const selectedDatapaths = rssFeedTable.selectedRows
.map((sRow) => rssFeedTable.getRow(sRow).full_data.dataPath);
2022-10-18 22:39:32 -04:00
// filter children
const reducedDatapaths = selectedDatapaths.filter((path) =>
2022-10-18 22:39:32 -04:00
selectedDatapaths.filter((innerPath) => path.slice(0, innerPath.length) === innerPath).length === 1
);
reducedDatapaths.each((path) => markItemAsRead(path));
};
const openRssDownloader = () => {
const id = "rssdownloaderpage";
2022-10-18 22:39:32 -04:00
new MochaUI.Window({
id: id,
icon: "images/qbittorrent-tray.svg",
title: "Rss Downloader",
loadMethod: "xhr",
contentURL: "views/rssDownloader.html",
2022-10-18 22:39:32 -04:00
maximizable: false,
width: loadWindowWidth(id, 800),
height: loadWindowHeight(id, 650),
onResize: window.qBittorrent.Misc.createDebounceHandler(500, (e) => {
2022-10-18 22:39:32 -04:00
saveWindowSize(id);
}),
2022-10-18 22:39:32 -04:00
resizeLimit: {
"x": [800, 2500],
"y": [500, 2000]
2022-10-18 22:39:32 -04:00
}
});
};
return exports();
})();
Object.freeze(window.qBittorrent.Rss);
</script>