Skip to content

Commit

Permalink
bulk delete rss feature
Browse files Browse the repository at this point in the history
  • Loading branch information
cdhigh committed Apr 10, 2024
1 parent f72a19b commit 1840399
Show file tree
Hide file tree
Showing 16 changed files with 658 additions and 433 deletions.
59 changes: 47 additions & 12 deletions application/static/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ function PopulateMyCustomRss() {
hamb_arg = [];
//汉堡按钮弹出菜单代码
var fTpl = "{0}('{1}','{2}')";
var fTplAll = "{0}(event,'{1}','{2}','{3}',{4})"; //id,title,url,isfulltext
hamb_arg.push({klass: 'btn-F', title: i18n.translator, icon: 'icon-translate', act: "/translator/" + id.replace(':', '__')});
hamb_arg.push({klass: 'btn-D', title: i18n.share, icon: 'icon-share', act: fTpl.format('StartShareRss', id, title)});
hamb_arg.push({klass: 'btn-A', title: i18n.delete, icon: 'icon-delete', act: fTpl.format('DeleteCustomRss', id, title)});
hamb_arg.push({klass: 'btn-A', title: i18n.deleteCtrlNoConfirm, icon: 'icon-delete',
act: fTplAll.format('DeleteCustomRss', id, title, url, isfulltext)});
row_str.push(AddHamburgerButton(hamb_arg));
row_str.push('</div>');
//console.log(row_str.join(''));
Expand Down Expand Up @@ -474,12 +476,12 @@ function AskForSubscriptionInfo(id, account){
modal.open();
}

//用户点击了删除自定义RSS按钮
function DeleteCustomRss(rssid, title) {
if (!confirm(i18n.areYouSureDelete.format(title))) {
//用户点击了删除自定义RSS按钮,如果按住ctrl键再点击删除,则不需要确认
function DeleteCustomRss(event, rssid, title, url, isfulltext) {
if (!event.ctrlKey && !confirm(i18n.areYouSureDelete.format(title))) {
return;
}

$.post("/customrss/delete", {id: rssid}, function (data) {
if (data.status == "ok") {
for (var idx = 0; idx < my_custom_rss_list.length; idx++) {
Expand All @@ -489,6 +491,9 @@ function DeleteCustomRss(rssid, title) {
}
}
PopulateMyCustomRss();
$('#title_to_add').val(title);
$('#url_to_add').val(url);
$('#isfulltext').prop('checked', isfulltext);
} else if (data.status == i18n.loginRequired) {
window.location.href = '/login';
} else {
Expand All @@ -497,12 +502,41 @@ function DeleteCustomRss(rssid, title) {
});
}

//一次性删除所有的自定义RSS
function RemoveAllCustomRss() {
$.post("/customrss/delete", {id: '#all_custom_rss#'}, function (data) {
if (data.status == "ok") {
my_custom_rss_list.length = 0;
PopulateMyCustomRss();
$('#title_to_add').val('');
$('#url_to_add').val('');
$('#isfulltext').prop('checked', false);
} else if (data.status == i18n.loginRequired) {
window.location.href = '/login';
} else {
alert(resp.status);
}
});
return false;
}

//用户点击了添加自定义RSS按钮
function AddCustomRss() {
var title_to_add = $('#title_to_add');
var isfulltext = $('#isfulltext');
var url_to_add = $('#url_to_add');
$.post("/customrss/add", {title: title_to_add.val(), fulltext: isfulltext.prop('checked'), url: url_to_add.val()},
let title_to_add = $('#title_to_add');
let isfulltext = $('#isfulltext');
let url_to_add = $('#url_to_add');
let title = title_to_add.val();
let url = url_to_add.val();
if ((title == '#removeall#') && !url) {
let msg = i18n.areYouSureRemoveAll + '\n' + i18n.areYouSureRemoveAll + '\n' + i18n.areYouSureRemoveAll;
if (confirm(msg)) {
return RemoveAllCustomRss();
} else {
return false;
}
}

$.post("/customrss/add", {title: title, url: url, fulltext: isfulltext.prop('checked')},
function (data) {
if (data.status == "ok") {
my_custom_rss_list.unshift({title: data.title, url: data.url, 'id': data.id, isfulltext: data.isfulltext});
Expand Down Expand Up @@ -672,11 +706,12 @@ function OpenUploadRecipeDialog() {
modal.close();
//更新本地数据
delete data.status;
let language = data.language;
let lang = data.language;
let title = data.title;
my_uploaded_recipes.unshift(data);
PopulateLibrary('');
ShowSimpleModalDialog('<h2>{0}</h2><p>{1}</p>'.format(i18n.congratulations,
i18n.recipeUploadedTips.format(LanguageName(language))));
ShowSimpleModalDialog('<h2>{0}</h2><p>{1}<hr/>{2}<br/>{3}</p>'.format(i18n.congratulations,
i18n.recipeUploadedTips, i18n.title + ': ' + title, i18n.language + ': ' + (LanguageName(lang))));
} else if (data.status == i18n.loginRequired) {
window.location.href = '/login';
} else {
Expand Down
37 changes: 24 additions & 13 deletions application/static/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,23 @@ function ReportInvalid(title, feedurl, dbId) {
});
}

//xml的转义函数
function escapeXml(xmlStr) {
return xmlStr.replace(/[<>&'"]/g, function(char) {
switch (char) {
case '<': return '&lt;';
case '>': return '&gt;';
case '&': return '&amp;';
case "'": return '&apos;';
case '"': return '&quot;';
default: return char;
}
});
}

//将内容全部下载到本地一个xml文件内
function DownAllRssToFile() {
var title, url, ftext, cat, rssd, fmtdate, nowdate;
var title, url, ftext, cat, rssd, fmtdate, nowdate, lang;
var elementA = document.createElement('a');
var aTxt = new Array();
aTxt.push("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
Expand All @@ -383,24 +397,21 @@ function DownAllRssToFile() {
aTxt.push("</head>");
aTxt.push("<body>");
for (var i = 0; i < g_SharedRss.length; i++) {
title = g_SharedRss[i].t;
url = g_SharedRss[i].u;
title = title.replace(/<[^<>]+?>/g,'');
cat = g_SharedRss[i].c;
if (g_SharedRss[i].f == "false") {
ftext = "0";
} else {
ftext = "1";
}
aTxt.push(" <outline type=\"rss\" text=\"" + title + "\" xmlUrl=\"" + url + "\" isFulltext=\"" + ftext + "\" category=\"" + cat + "\" />");
title = escapeXml(g_SharedRss[i].t);
url = escapeXml(g_SharedRss[i].u);
cat = escapeXml(g_SharedRss[i].c);
lang = g_SharedRss[i].l || '';
ftext = (g_SharedRss[i].f == "false") ? "no" : "yes";
aTxt.push(' <outline type="rss" text="{0}" title="{0}" xmlUrl="{1}" isFulltext="{2}" category="{3}" language="{4}" />'
.format(title, url, ftext, cat, lang));
}
aTxt.push("</body>");
aTxt.push("</opml>");
aTxt.push("</opml>\n");

nowdate = new Date();
fmtdate = "KindleEar_library_" + nowdate.getFullYear() + "_" + ((nowdate.getMonth() + 1)) + "_" + nowdate.getDate() + ".xml";

elementA.setAttribute("href", "data:text/plain;charset=utf-8," + aTxt.join("\n"));
elementA.setAttribute("href", "data:text/plain;charset=utf-8," + encodeURIComponent(aTxt.join("\n")));
elementA.setAttribute("download", fmtdate);
elementA.style.display = 'none';
document.body.appendChild(elementA);
Expand Down
7 changes: 5 additions & 2 deletions application/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<script type="text/javascript">
var i18n = {
delete: '{{_("Delete")|safe}}',
deleteCtrlNoConfirm: '{{_("Delete (Ctrl for no confirm)")|safe}}',
viewSrc: '{{_("View Source Code")|safe}}',
subscriSep: '{{_("Subscribe (Deliver Separately)")|safe}}',
subscribe: '{{_("Subscribe")|safe}}',
Expand All @@ -28,6 +29,7 @@
fulltext: '{{_("Fulltext")|safe}}',
share: '{{_("Share")|safe}}',
areYouSureDelete: '{{_("Are you sure to delete ({0})?")|safe}}',
areYouSureRemoveAll: '{{_("Are you sure to REMOVE ALL CUSTOM RSS?")|safe}}',
shareLinksHappiness: '{{_("Share links, share happiness")|safe}}',
category: '{{_("Category")|safe}}',
language: '{{_("Language")|safe}}',
Expand All @@ -51,7 +53,7 @@
chooseRecipeFile: '{{_("Choose a recipe file to upload")|safe}}',
congratulations: '{{_("Congratulations")|safe}}',
thanks: '{{_("Thanks")|safe}}',
recipeUploadedTips: '{{_("Your recipe has been uploaded, and it can be found in the Library section. If you dont see it, please make sure to switch to the correct language ({0}).")|safe}}',
recipeUploadedTips: '{{_("Your recipe has been uploaded, and it can be found in the Library section. If you dont see it, please make sure to switch to the correct language.")|safe}}',
recipeDeleted: '{{_("Your recipe have been deleted.")|safe}}',
kindleifySelection: '{{_("Kindleify Selection")|safe}}',
verify: '{{_("Verify")|safe}}',
Expand Down Expand Up @@ -94,7 +96,8 @@
abbrEmb: '{{_("Emb")|safe}}',
testEmailOk: '{{_("The test email has been successfully sent to the following addresses. Please check your inbox or spam folder to confirm its delivery. Depending on your email server, there may be a slight delay.")|safe}}',
translating: '{{_("Translating...")|safe}}',
configOk: '{{_("The configuration validation is correct.")|safe}}'
configOk: '{{_("The configuration validation is correct.")|safe}}',
title: '{{_("Title")|safe}}'
};
</script>
{% block javascript_inhead %}
Expand Down
2 changes: 1 addition & 1 deletion application/templates/my.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</div>
<div class="pure-u-1-6">
<div class="upload-recipe">
<button class="upload-recipe-btn" title="{{_('Upload your custom recipe')}}"onclick="OpenUploadRecipeDialog()"><i class="iconfont icon-upload"></i></button>
<button class="upload-recipe-btn" title="{{_('Upload custom recipe')}}"onclick="OpenUploadRecipeDialog()"><i class="iconfont icon-upload"></i></button>
</div>
</div>
<div class="pure-u-3-6">
Expand Down
2 changes: 1 addition & 1 deletion application/templates/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</div>
<div class="pure-control-group">
<label><em class="required">*</em> {{_("Kindle E-mail")}}</label>
<input type="email" name="kindle_email" value="{{user.kindle_email}}" placeholder="{{_('Seperated by comma')}}" class="pure-u-1 pure-u-sm-1-2" required multiple= />
<input type="email" name="kindle_email" value="{{user.kindle_email}}" placeholder="{{_('Seperated by comma')}}" class="pure-u-1 pure-u-sm-1-2" required multiple />
</div>
<div class="pure-control-group">
<label>{{_("Time zone")}}</label>
Expand Down
Loading

0 comments on commit 1840399

Please sign in to comment.