|
|
|
@ -17,7 +17,7 @@ function hashParam(key, val) { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// 创建书源规则容器对象
|
|
|
|
|
// 创建源规则容器对象
|
|
|
|
|
function Container() { |
|
|
|
|
let ruleJson = {}; |
|
|
|
|
|
|
|
|
@ -36,7 +36,7 @@ function showTab(tabName) { |
|
|
|
|
$(`.tabtitle>*[name=${tabName}]`).className += ' this'; |
|
|
|
|
hashParam('tab', tabName); |
|
|
|
|
} |
|
|
|
|
// 书源列表列表标签构造函数
|
|
|
|
|
// 源列表列表标签构造函数
|
|
|
|
|
function newRule(rule) { |
|
|
|
|
return `<label for="${rule.sourceUrl}"><input type="radio" name="rule" id="${rule.sourceUrl}"><div>${rule.sourceName}<br>${rule.sourceUrl}</div></label>`; |
|
|
|
|
} |
|
|
|
@ -71,7 +71,7 @@ function HttpPost(url, data) { |
|
|
|
|
}) |
|
|
|
|
}).then(res => res.json()).catch(err => console.error('Error:', err)); |
|
|
|
|
} |
|
|
|
|
// 将书源表单转化为书源对象
|
|
|
|
|
// 将源表单转化为源对象
|
|
|
|
|
function rule2json() { |
|
|
|
|
let RuleJSON = Container(); |
|
|
|
|
// 转换base
|
|
|
|
@ -86,7 +86,7 @@ function rule2json() { |
|
|
|
|
RuleJSON.enabled = RuleJSON.enabled == '' || String(RuleJSON.enabled).toLocaleLowerCase().replace(/^\s*|\s*$/g, '') == 'true'; |
|
|
|
|
return RuleJSON; |
|
|
|
|
} |
|
|
|
|
// 将书源对象填充到书源表单
|
|
|
|
|
// 将源对象填充到源表单
|
|
|
|
|
function json2rule(RuleEditor) { |
|
|
|
|
let RuleJSON = Container(); |
|
|
|
|
// 转换base
|
|
|
|
@ -214,23 +214,23 @@ $('.menu').addEventListener('click', e => { |
|
|
|
|
if (okData.find(x => x.sourceUrl == item.sourceUrl)) { } |
|
|
|
|
else { $(`#RuleList #${item.sourceUrl}+*`).className += 'isError'; } |
|
|
|
|
}); |
|
|
|
|
failMsg = '\n推送失败的书源将用红色字体标注!'; |
|
|
|
|
failMsg = '\n推送失败的源将用红色字体标注!'; |
|
|
|
|
} |
|
|
|
|
alert(`批量推送书源到「阅读3.0APP」\n共计: ${RuleSources.length} 条\n成功: ${okData.length} 条\n失败: ${RuleSources.length - okData.length} 条${failMsg}`); |
|
|
|
|
alert(`批量推送源到「阅读3.0APP」\n共计: ${RuleSources.length} 条\n成功: ${okData.length} 条\n失败: ${RuleSources.length - okData.length} 条${failMsg}`); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
alert(`批量推送书源到「阅读3.0APP」成功!\n共计: ${RuleSources.length} 条`); |
|
|
|
|
alert(`批量推送源到「阅读3.0APP」成功!\n共计: ${RuleSources.length} 条`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
alert(`批量推送书源失败!\nErrorMsg: ${json.errorMsg}`); |
|
|
|
|
alert(`批量推送源失败!\nErrorMsg: ${json.errorMsg}`); |
|
|
|
|
} |
|
|
|
|
}).catch(err => { alert(`批量推送书源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
}).catch(err => { alert(`批量推送源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
thisNode.setAttribute('class', ''); |
|
|
|
|
})(); |
|
|
|
|
return; |
|
|
|
|
case 'pull': |
|
|
|
|
showTab('书源列表'); |
|
|
|
|
showTab('源列表'); |
|
|
|
|
(async () => { |
|
|
|
|
await HttpGet(`/getRssSources`).then(json => { |
|
|
|
|
if (json.isSuccess) { |
|
|
|
@ -239,12 +239,12 @@ $('.menu').addEventListener('click', e => { |
|
|
|
|
RuleSources.forEach(item => { |
|
|
|
|
$('#RuleList').innerHTML += newRule(item); |
|
|
|
|
}); |
|
|
|
|
alert(`成功拉取 ${RuleSources.length} 条书源`); |
|
|
|
|
alert(`成功拉取 ${RuleSources.length} 条源`); |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
alert(`批量拉取书源失败!\nErrorMsg: ${json.errorMsg}`); |
|
|
|
|
alert(`批量拉取源失败!\nErrorMsg: ${json.errorMsg}`); |
|
|
|
|
} |
|
|
|
|
}).catch(err => { alert(`批量拉取书源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
}).catch(err => { alert(`批量拉取源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
thisNode.setAttribute('class', ''); |
|
|
|
|
})(); |
|
|
|
|
return; |
|
|
|
@ -259,7 +259,7 @@ $('.menu').addEventListener('click', e => { |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 'conver': |
|
|
|
|
showTab('编辑书源'); |
|
|
|
|
showTab('编辑源'); |
|
|
|
|
$('#RuleJsonString').value = JSON.stringify(rule2json(), null, 4); |
|
|
|
|
break; |
|
|
|
|
case 'initial': |
|
|
|
@ -273,7 +273,7 @@ $('.menu').addEventListener('click', e => { |
|
|
|
|
redo() |
|
|
|
|
break; |
|
|
|
|
case 'debug': |
|
|
|
|
showTab('调试书源'); |
|
|
|
|
showTab('调试源'); |
|
|
|
|
let wsOrigin = (hashParam('domain') || location.origin).replace(/^.*?:/, 'ws:').replace(/\d+$/, (port) => (parseInt(port) + 1)); |
|
|
|
|
let DebugInfos = $('#DebugConsole'); |
|
|
|
|
function DebugPrint(msg) { DebugInfos.value += `\n${msg}`; DebugInfos.scrollTop = DebugInfos.scrollHeight; } |
|
|
|
@ -281,7 +281,7 @@ $('.menu').addEventListener('click', e => { |
|
|
|
|
HttpPost(`/saveRssSources`, saveRule).then(sResult => { |
|
|
|
|
if (sResult.isSuccess) { |
|
|
|
|
let sKey = DebugKey.value ? DebugKey.value : '我的'; |
|
|
|
|
$('#DebugConsole').value = `书源《${saveRule[0].sourceName}》保存成功!使用搜索关键字“${sKey}”开始调试...`; |
|
|
|
|
$('#DebugConsole').value = `源《${saveRule[0].sourceName}》保存成功!使用搜索关键字“${sKey}”开始调试...`; |
|
|
|
|
let ws = new WebSocket(`${wsOrigin}/sourceDebug`); |
|
|
|
|
ws.onopen = () => { |
|
|
|
|
ws.send(`{"tag":"${saveRule[0].sourceUrl}", "key":"${sKey}"}`); |
|
|
|
@ -307,9 +307,9 @@ $('.menu').addEventListener('click', e => { |
|
|
|
|
(async () => { |
|
|
|
|
let saveRule = [rule2json()]; |
|
|
|
|
await HttpPost(`/saveRssSources`, saveRule).then(json => { |
|
|
|
|
alert(json.isSuccess ? `书源《${saveRule[0].sourceName}》已成功保存到「阅读3.0APP」` : `书源《${saveRule[0].sourceName}》保存失败!\nErrorMsg: ${json.errorMsg}`); |
|
|
|
|
alert(json.isSuccess ? `源《${saveRule[0].sourceName}》已成功保存到「阅读3.0APP」` : `源《${saveRule[0].sourceName}》保存失败!\nErrorMsg: ${json.errorMsg}`); |
|
|
|
|
setRule(saveRule[0]); |
|
|
|
|
}).catch(err => { alert(`保存书源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
}).catch(err => { alert(`保存源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
thisNode.setAttribute('class', ''); |
|
|
|
|
})(); |
|
|
|
|
return; |
|
|
|
@ -376,7 +376,7 @@ $('.tab3>.titlebar').addEventListener('click', e => { |
|
|
|
|
let fileJson = JSON.parse(fileText); |
|
|
|
|
let newSources = []; |
|
|
|
|
newSources.push(...fileJson); |
|
|
|
|
if (window.confirm(`如何处理导入的书源?\n"确定": 覆盖当前列表(不会删除APP源)\n"取消": 插入列表尾部(自动忽略重复源)`)) { |
|
|
|
|
if (window.confirm(`如何处理导入的源?\n"确定": 覆盖当前列表(不会删除APP源)\n"取消": 插入列表尾部(自动忽略重复源)`)) { |
|
|
|
|
localStorage.setItem('RssSources', JSON.stringify(RuleSources = newSources)); |
|
|
|
|
$('#RuleList').innerHTML = '' |
|
|
|
|
RuleSources.forEach(item => { |
|
|
|
@ -391,10 +391,10 @@ $('.tab3>.titlebar').addEventListener('click', e => { |
|
|
|
|
$('#RuleList').innerHTML += newRule(item); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
alert(`成功导入 ${newSources.length} 条书源`); |
|
|
|
|
alert(`成功导入 ${newSources.length} 条源`); |
|
|
|
|
} |
|
|
|
|
catch (err) { |
|
|
|
|
alert(`导入书源文件失败!\n${err}`); |
|
|
|
|
alert(`导入源文件失败!\n${err}`); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
@ -412,13 +412,13 @@ $('.tab3>.titlebar').addEventListener('click', e => { |
|
|
|
|
case 'Delete': |
|
|
|
|
let selectRule = $('#RuleList input:checked'); |
|
|
|
|
if (!selectRule) { |
|
|
|
|
alert(`没有书源被选中!`); |
|
|
|
|
alert(`没有源被选中!`); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
if (confirm(`确定要删除选定书源吗?\n(同时删除APP内书源)`)) { |
|
|
|
|
if (confirm(`确定要删除选定源吗?\n(同时删除APP内源)`)) { |
|
|
|
|
let selectRuleUrl = selectRule.id; |
|
|
|
|
let deleteSources = RuleSources.filter(item => item.sourceUrl == selectRuleUrl); // 提取待删除的书源
|
|
|
|
|
let laveSources = RuleSources.filter(item => !(item.sourceUrl == selectRuleUrl)); // 提取待留下的书源
|
|
|
|
|
let deleteSources = RuleSources.filter(item => item.sourceUrl == selectRuleUrl); // 提取待删除的源
|
|
|
|
|
let laveSources = RuleSources.filter(item => !(item.sourceUrl == selectRuleUrl)); // 提取待留下的源
|
|
|
|
|
HttpPost(`/deleteRssSources`, deleteSources).then(json => { |
|
|
|
|
if (json.isSuccess) { |
|
|
|
|
let selectNode = document.getElementById(selectRuleUrl).parentNode; |
|
|
|
@ -429,13 +429,13 @@ $('.tab3>.titlebar').addEventListener('click', e => { |
|
|
|
|
todo(); |
|
|
|
|
} |
|
|
|
|
console.log(deleteSources); |
|
|
|
|
console.log(`以上书源已删除!`) |
|
|
|
|
console.log(`以上源已删除!`) |
|
|
|
|
} |
|
|
|
|
}).catch(err => { alert(`删除书源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
}).catch(err => { alert(`删除源失败,无法连接到「阅读3.0APP」!\n${err}`); }); |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case 'ClrAll': |
|
|
|
|
if (confirm(`确定要清空当前书源列表吗?\n(不会删除APP内书源)`)) { |
|
|
|
|
if (confirm(`确定要清空当前源列表吗?\n(不会删除APP内源)`)) { |
|
|
|
|
localStorage.setItem('RssSources', JSON.stringify(RuleSources = [])); |
|
|
|
|
$('#RuleList').innerHTML = '' |
|
|
|
|
} |
|
|
|
|