首页 > 其他分享 >主题备份(还未完成)

主题备份(还未完成)

时间:2023-07-28 21:34:27浏览次数:37  
标签:const title articleList 备份 主题 articlesDom innerText 完成 children

image
image
image

/* 全局 */
a {
    text-decoration: none;
}
/* 导航栏 */
.top {
    height: 50px;
}
.top a {
    margin-left: 20px;
}
/* 文章列表 */
.main {
    display: flex;
    flex-direction: column;
}

.main a {
    width: max-content;
    font-size: 14px;
}

.main a:hover {
    text-decoration: underline;
    color: #ff4c00;
}

页脚html


<script type="text/javascript">
// 去除字符串中的 html 标签
function delHtmlTag(str) {
    let newStr = str.replace(/<[^>]+>/g, "");
    newStr = str.replace(/<[^>]/g, "");
    return newStr;
}
// 去除字符串中的空格
function delSpace(str) {
    return str.replace(/&nbsp;/ig, "");
}
// 获取同一天的合并文章
function getOneToManyArticles(articlesDom) {
    const articleList = [];
    for (let i = -1; i < articlesDom.length - 1; i+=6) {
        console.log(i)
        const abstract = delSpace(delHtmlTag(articlesDom[i + 3].innerText));
        const createTime = articlesDom[i + 5].innerHTML.split('\n')[0].replace('posted @ ', '');
        const viewCount = articlesDom[i + 5].children[0].innerText;
        const commentCount = articlesDom[i + 5].children[1].innerText;
        const recommendCount = articlesDom[i + 5].children[2].innerText;
        const edit = {
            label: articlesDom[i + 5].children[3].innerText,
            link: articlesDom[i + 5].children[3].href
        } 
        articleList.push(
            {
                title: articlesDom[i + 2].children[0].innerText,
                link: articlesDom[i + 2].children[0].href,
                abstract, 
                createTime,
                viewCount,
                commentCount,
                recommendCount,
                edit

            }
        )
    }
    return articleList;
}
// 获取同一天一篇的文章
function getOneToOneArticle(articlesDom) {
    
    const abstract = delSpace(delHtmlTag(articlesDom[2].innerText));
    const createTime = articlesDom[4].innerHTML.split('\n')[0].replace('posted @ ', '');
    const viewCount = articlesDom[4].children[0].innerText;
    const commentCount = articlesDom[4].children[1].innerText;
    const recommendCount = articlesDom[4].children[2].innerText;
    const edit = {
        label: articlesDom[4].children[3].innerText,
        link: articlesDom[4].children[3].href
    } 
    const article =
        {
            title: articlesDom[1].children[0].innerText,
            link: articlesDom[1].children[0].href,
            abstract, 
            createTime,
            viewCount,
            commentCount,
            recommendCount,
            edit

        };
    return article;
}
// 获取站名
function getDomainTitle() {
    const domainTitleDom = $('#Header1_HeaderTitle');
    return {
        title: domainTitleDom[0].innerText,
        link: domainTitleDom[0].href
    }
}
// 获取导航列表
function getNavList() {
    const navDomList = $('#navList li a');
    console.log(navDomList)
    const navList = [];
    for (const item of navDomList) {
        navList.push(
            {
                title: item.innerText.replace('\n', ''),
                link: item.href
            }
        );
    }
    return navList;
}
// 获取文章
function getArticleList() {
    const articleDomList = $('.day');
    const articleList = [];
    if(articleDomList && articleDomList.length) {
        for (const item of articleDomList) {
            const { className, children } = item;
            if (children.length > 6) {
                articleList.push(...getOneToManyArticles(children));
            } else {
                articleList.push(getOneToOneArticle(children));
            }
            // if (className === 'day pinned') {
            //     articleList.push(
            //         {
            //             title: 
            //         }
            //     );
            // }
  
        }
    }
    return articleList;
}
// 获取文章列表DOM
function getNewArticleListDom(articleList) {
    let articleDomList = [];
    for (const item of articleList) {
        const { title, link } = item;
        articleDomList.push(
            `<a href="${link}" target="_blank">${title}</a>`
        );
    }
    return articleDomList;
}
// 获取导航列表DOM
function getNavListDom(navList) {
    let navDomList = [];
    for (const item of navList) {
        const { title, link } = item;
        navDomList.push(
            `<a href="${link}" target="_blank">${title}</a>`
        );
    }
    return navDomList;
}
const w = window;
if (w.location.href.includes('/p/')) {
    // $('body').empty();
    $('#top_nav').remove();
    $('#header').remove();
    $('#blog_post_info_block').remove();
    $('#cnblogs_ch').remove();
    $('#under_post_card1').remove();
     $('#under_post_card2').remove();
     $('#sideBar').remove();
} else {
    // 获取整个页面的内容
    // const pageContent = $('html').html();
    // console.log(pageContent);
    const domainTitle = getDomainTitle();
    console.log(domainTitle);
    const navList = getNavList();;
    const navDomList = getNavListDom(navList);
    // 获取文章列表
    const articleList = getArticleList();
    const articleDomList = getNewArticleListDom(articleList);
    $('body').empty();
    const newBody = `
    <div class="blog_body">
        <div class="top">
            ${navDomList.join('')}
        </div>
        <div class="main">
            ${articleDomList.join('')}
        </div>
        <div class="footer">footer</div>
    </div>
    `
    $('body')[0].innerHTML = newBody;

    // console.log($('#nav_next_page'));
}


</script>

标签:const,title,articleList,备份,主题,articlesDom,innerText,完成,children
From: https://www.cnblogs.com/qmzbe/p/17588938.html

相关文章

  • CDNDrive 第一个版本发布 & 布客新知第二次备份完成
    CDNDrive第一个版本发布,新适配五个图床https://github.com/apachecn/CDNDrive另外,布客新知第二次备份完成TutorialsPoint:http://it-ebooks.flygon.net/tutorialspoint-cdndrive/计算机电子书2019:http://it-ebooks.flygon.net/it-ebooks-2019-cdndrive/知识星球:http://it-ebooks.f......
  • 达梦备份恢复技术分享
        随着IT科技的发展,数据逐渐成为社会和企业的核心资产,面对纷繁复杂的社会环境,供应链风险随时可能发生,国产化势在必行,DM数据库作为国产化数据库代表,正在行业中变得越来越流行,达梦作为国产数据库的佼佼者,深受传统行业和广大金融客户的喜爱。它有着40年深厚的技术沉淀,相信......
  • CTFer成长记录——CTF之Web专题·bugku—备份是个好习惯
    一、题目链接https://ctf.bugku.com/challenges/detail/id/83.html?id=83二、解法步骤  打开网站,发现是一串字符串:    解码:[空密码]/[EmptyString],无结果。题目提示“备份是个好习惯”,那么尝试访问index.php.bak和index.php.swp,这两个文件,看看存不存在。于是在index.......
  • SqlServer备份数据库语句
    Declare@DataStrNVARCHAR(200)set@DataStr=convert(NVARCHAR(19),getdate(),120)set@DataStr=REPLACE(@DataStr,':','_')set@DataStr=REPLACE(@DataStr,'','_')set@DataStr=REPLACE(@DataStr,'-','......
  • pg_basebackup备份、恢复
    pg_basebackup备份、恢复详细方案1、pg_basebackup备份命令介绍pg_basebackuptakesabasebackupofarunningPostgreSQLserver.Usage:pg_basebackup[OPTION]...Optionscontrollingtheoutput:-D,--pgdata=DIRECTORYreceivebasebackupintodirectory-F,......
  • pg_probackup备份
    一、概述pg_probackup是一个管理PostgreSQL数据库集群备份和恢复的实用程序。它旨在执行PostgreSQL实例的定期备份,能够在数据库发生故障时恢复服务器。二、备份优势全量备份:全量备份会将数据库集下所有的数据文件进行备份增量备份:增量备份备份的是上一次备份之后发生改变的......
  • shell定时备份数据库
    摘要讲解如何使用shell每天定时编写数据库一、要求每天凌晨2:30备份数据库db1到/data/backup/db备份开始和备份结束能够给出相应的提示信息备份后的文件要求以备份时间为文件名,并打包成.tar.gz的形式,比如:2021-03-12_230201.tar.gz在备份的同时,检查是否有10天前备份的数......
  • .Net6基于layui和ztree完成树形选择器添加和反填和修改
    以责任科室为例存储两个值ResponsibleDepartment和AoId,ResponsibleDepartment:是科室名称,AoId是科室Id添加:<divclass="layui-form-itemlayui-form-text"><labelclass="layui-form-label">责任科室</label><divclass="layui-inpu......
  • pgsql备份工具:pg_rman在Linux下的安装、设置与使用
    https://blog.csdn.net/Absurdreal/article/details/128872628?spm=1001.2101.3001.6650.8&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-8-128872628-blog-128017299.235%5Ev38%5Epc_relevant_sort&depth_1-utm_sou......
  • 如何美化 BlackLowKey 主题
    孩子比较傻,折腾了半天才整出来,在这里记一下。往[页面定制CSS代码]里写东西就行了以下是几个示例:body{background-image:url(https://example.com/bg.png);background-color:#1f1e33; background-position:topcenter; background-repeat:no-repeat;......