当前位置 : 主页 > 网络编程 > JavaScript >

web页面清理代码

来源:互联网 收集:自由互联 发布时间:2021-06-28
用来清理页面,特别是想要打印页面时 /***使用说明*按F12打开调试工具,切换到source窗口下,切换到snippets选项卡,将代码复制进去* 将你要删除的元素的选择符放到deleteList里面,然后
用来清理页面,特别是想要打印页面时
/**
*使用说明
*按F12打开调试工具,切换到source窗口下,切换到snippets选项卡,将代码复制进去
* 将你要删除的元素的选择符放到deleteList里面,然后运行代码片
**/
var deleteList = [".__bg_gif",".qr_code_pc","[data-id='2827']","[data-id='96874']"];

deleteList.map(deleteElement);

function deleteElement(selector){
    let tobeDeleteArray = document.querySelectorAll(selector);
    tobeDeleteArray.forEach(function(item){
        item.parentElement.removeChild(item);
    });
    tobeDeleteArray = null;
}
InfoQ文章详情页面清理
var deleteList = [".top-bar-promo","#topInfo",".header",
".author_general",".sh_t","#psa-note",
".article_page_right","[title='Sumo']",".related_editorial",
".related",".nocontent",".gray_section_related",".comment_here",".comments",
".all_comments","#footer",".newsletter ",".title_canvas img",".bottom-banner-content",
".noOfComments"];
deleteList.map(deleteElement);

function deleteElement(selector){
    let tobeDeleteArray = document.querySelectorAll(selector);
    tobeDeleteArray.forEach(function(item){
        item.parentElement.removeChild(item);
    });
    tobeDeleteArray = null;
}

//清除背景
let wrapper = document.querySelector("#wrapper");
wrapper.style.background = "none";

//居中
let text_content_container = document.querySelector(".text_content_container");
text_content_container.style.margin = "0 auto";
text_content_container.style.float = "none";

let title_canvas = document.querySelector(".title_canvas h1");
title_canvas.style.textAlign = "center";
上一篇:vue 路由的填坑之路
下一篇:for与each
网友评论