vuepress-----24、侧边栏广告位

Header中导入js

复制代码
module.exports = [
  ["script", { charset: "utf-8", src: "/js/custom.js" }],//加载右侧菜单栏图片
]

.vuepress/public/js/custom.js

复制代码
/*
if(top.location!==self.location){
	top.location.href=self.location.href;
}
if(document.location.host != "hliedu.com" 
	&& location.href.indexOf('http') >-1 
	&& location.href.indexOf('localhost')==-1){
	location.replace('https://book.hliedu.com/')
}
	*/
window.aCallFun = function(elem, args) {
  if(elem[0] && elem[0].src){
    var reg = /(http:\/\/|https:\/\/)(.*?)\/{1}(.*)/i;
    var url = elem[0].src || elem[0].getAttribute('src');
    var host = url.replace(reg,"$2");
    
    if(host.indexOf('baidu')>-1 || host.indexOf('weibo')>-1 || host.indexOf('sina')>-1|| host.indexOf('hliedu.com')>-1 || host.indexOf('http')===-1){
        return true;
    }else{
        return false;
    }
  }else if(elem[0].id && elem[0].id.indexOf('cproIframe')>-1){
    return false;
  }else{
    return true;
  }
}
window.f = Element.prototype.appendChild;
Element.prototype.appendChild = function() {
    var flag = window.aCallFun.call(this, arguments);
    if(flag === true){
        return window.f.apply(this, arguments);
    }else{
        // return window.f.apply(this, arguments);
    }
};

var _hrefs = "https://www.aliyun.com/minisite/goods?taskPkg=1111ydsrwb&pkgSid=11811&userCode=goqhbyn3";
function vueSidebarShow() {
	var windowWidth = document.body.clientWidth || window.innerWidth;
	if(windowWidth > 760){
		loadSidebar(_hrefs);
	}
}

//添加图片到侧边栏
function loadSidebar(hrefTxt) {
	var sidebars = document.getElementsByClassName("sidebar");	var divNode = document.createElement("div");divNode.setAttribute("style" , "text-align: center; padding: 10px;");divNode.innerHTML = '<a href="' + hrefTxt + '" target="_blank"><img src="/img/sidebar_280140.png"></a>';
	console.log(sidebars)
	sidebars[0].insertBefore(divNode , sidebars[0].childNodes[0]);
	var e = document.getElementsByClassName("hide");if(e[1])e[1].remove();
}

//页面延时一秒
setTimeout("vueSidebarShow()",1000)

更新时间: 2023年12月7日星期四下午4点10分

本文转自 https://docs.xiaoshaozi.site

相关推荐
三十_A18 分钟前
如何正确实现圆角渐变边框?为什么 border-radius 对 border-image 不生效?
前端·css·css3
小满zs33 分钟前
Next.js第十三章(缓存组件)
前端
前端老宋Running1 小时前
“受控组件”的诅咒:为什么你需要 React Hook Form + Zod 来拯救你的键盘?
前端·javascript·react.js
风止何安啊1 小时前
拿捏 React 组件通讯:从父子到跨组件的「传功秘籍」
前端·react.js·面试
懒得不想起名字1 小时前
将flutter打成aar包嵌入到安卓
前端
Highcharts.js1 小时前
官方文档|Angular 框架集成 Highcharts Dashboards
前端·javascript·angular.js·highcharts·看板·使用文档·dashboards
韭菜炒大葱1 小时前
React 新手村通关指南:状态、组件与魔法 UI 🧙‍♂️
前端·javascript·react.js
天天扭码2 小时前
深入MCP本质——编写自定义MCP Server并通过Cursor调用
前端·mcp
1024肥宅3 小时前
JavaScript性能与优化:手写实现关键优化技术
前端·javascript·面试
一字白首3 小时前
Vue 项目实战,从注册登录到首页开发:接口封装 + 导航守卫 + 拦截器全流程
前端·javascript·vue.js