修改new_Rss.js为Ajax获取Rss
This commit is contained in:
@@ -1,55 +1,24 @@
|
|||||||
//定义一个函数来获取rss文件
|
$(document).ready(function() {
|
||||||
function getRSS(url) {
|
// 使用 AJAX 获取 RSS 源的内容
|
||||||
//使用fetch API来调用url
|
$.ajax({
|
||||||
fetch(url)
|
url: "https://rss.lolicon.team/?feed=rss2",
|
||||||
.then(response => response.text()) //将响应解析为文本
|
dataType: "xml",
|
||||||
.then(str => new window.DOMParser().parseFromString(str, "text/xml")) //将文本解析为XML对象
|
success: function(data) {
|
||||||
.then(data => {
|
// 解析 XML 内容并找到所有的 <item> 元素
|
||||||
//从XML对象中获取channel元素
|
$(data).find("item").each(function() {
|
||||||
const channel = data.querySelector("channel");
|
var title = $(this).find("title").text();
|
||||||
//从channel元素中获取所有item元素
|
var link = $(this).find("link").text();
|
||||||
const items = channel.querySelectorAll("item");
|
var description = $(this).find("description").text();
|
||||||
//遍历每个item元素
|
// 将解析后的内容添加到 HTML 的 <div> 元素中
|
||||||
items.forEach(item => {
|
$("#rss").append("<li class='list-news mdui-ripple mdui-ripple-white'><h3><a href='" + link + "'>" + title + "</a></h3><p>" + description + "</p></li>");
|
||||||
//从item元素中获取title和link元素的文本内容
|
//添加li标签里的class类 wow animate__animated animate__fadeInRight
|
||||||
const title = item.querySelector("title").textContent;
|
$('#rss li').addClass('wow animate__animated animate__fadeInRight');
|
||||||
const link = item.querySelector("link").textContent;
|
//删除id 为loadprogress的元素
|
||||||
const datetime = item.querySelector("pubDate").textContent;
|
$('#loadprogress').remove();
|
||||||
//在控制台打印标题和链接
|
|
||||||
console.log(title, link);
|
|
||||||
//在news.html页面上的ul元素中添加内容
|
|
||||||
document.querySelector("ul").innerHTML += `
|
|
||||||
|
|
||||||
<li class="list-news idc dnone mdui-list-item mdui-ripple mdui-shadow-12" style="backdrop-filter: blur(8px);overflow-x:hidden;padding-top: 14px;padding-bottom: 14px;">
|
|
||||||
<a href="${link}" target="_blank">
|
|
||||||
<div class="mdui-list-item-title">${title}</div>
|
|
||||||
<div class="mdui-list-item-text mdui-list-item-one-line">
|
|
||||||
<span>${datetime}</span>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
`;
|
|
||||||
// 完成后删除li中class类中的dnone
|
|
||||||
document.querySelector("li").classList.remove("dnone");
|
|
||||||
//添加li标签里的class类 wow animate__animated animate__fadeInRight
|
|
||||||
document.querySelector("li").classList.add("wow", "animate__animated", "animate__fadeInRight");
|
|
||||||
//删除id 为loadprogress的元素
|
|
||||||
document.getElementById("loadprogress").remove();
|
|
||||||
//若是没有的item元素,则在页面li添加没有内容”
|
|
||||||
if (items.length === 0) {
|
|
||||||
document.querySelector("ul").innerHTML += `
|
|
||||||
<li class="idc dnone mdui-list-item mdui-ripple mdui-shadow-12" style="backdrop-filter: blur(8px);overflow-x:hidden">
|
|
||||||
<div class="mdui-list-item-title">没有内容</div>
|
|
||||||
</li>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
});
|
||||||
|
|
||||||
//调用函数,传入rss文件的url(这里是一个示例)
|
});
|
||||||
getRSS("https://rss.lolicon.team/?feed=rss2");
|
|
||||||
|
|
||||||
|
|
||||||
@@ -358,5 +358,15 @@ body {
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
.list-news{
|
.list-news{
|
||||||
|
text-align: center;
|
||||||
|
margin: 0 auto;
|
||||||
|
margin-top: 15px;
|
||||||
|
margin-left: 15px;
|
||||||
|
max-width: 1408px;
|
||||||
|
border: 2px solid #585858;
|
||||||
border-radius: 15px;
|
border-radius: 15px;
|
||||||
|
backdrop-filter: blur(5px);
|
||||||
|
}
|
||||||
|
.list-news h3{
|
||||||
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@
|
|||||||
<!--pc text-->
|
<!--pc text-->
|
||||||
<div class="mdui-hidden-xs-down zhe " style="height:100vh">
|
<div class="mdui-hidden-xs-down zhe " style="height:100vh">
|
||||||
<div class="mdui-container">
|
<div class="mdui-container">
|
||||||
<ul class="mdui-list">
|
<ul id="rss" class="mdui-list">
|
||||||
|
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|||||||
Reference in New Issue
Block a user