const footer = () => { let currentHref = location.href let html = ` ` $("body").insertAdjacentHTML("beforeend", html) } const header = (right, center = "", left = ``) => { let html = `
${left}
${center}
${right}
` $("body").insertAdjacentHTML("afterbegin", html) _(".header .icon-fanhui").click(v => { history.back() }) } const item = (father, data) => { (typeof father == "string" ? $(father) : father).insertAdjacentHTML("beforeend",data.maps(v => { return `
  • ${v.title}
    ${v.time}
    ${v.view}W+
  • ` })) } const query = name =>{ var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r!=null)return decodeURIComponent(r[2]); return null; } const stripIndents = (template, ...expressions) => { let result = template.reduce((prev, next, i) => { let expression = expressions[i - 1]; return prev + expression + next; }); result = result.replace(/\n[^\S\n]*/g, '\n'); result = result.trim(); return result; } const innerMaps = (father, data, callback) => { $(father).insertAdjacentHTML("afterbegin", data.maps((v,i) => { return callback(v,i) })) } const $ = className => { return document.querySelector(className) } const _ = className => { return document.querySelectorAll(className) } // prototype 原型 // js给我们提供的一个方法,通过这个方法作为入口, // 我们可以直接对js进行修改 Array.prototype.maps = function (callback) { let result = [] for (let i = 0; i < this.length; i++) { result.push(callback(this[i], i, this)) } return result.toString().replaceAll(",", "") } NodeList.prototype.click = function (callback) { this.forEach((v,i) => v.onclick = () => callback(v,i)) } NodeList.prototype.scroll = function (callback) { this.forEach((v,i) => v.onscroll = () => callback(v,i)) }