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

相关推荐
祈澈菇凉18 分钟前
如何结合使用thread-loader和cache-loader以获得最佳效果?
前端
垣宇21 分钟前
Vite 和 Webpack 的区别和选择
前端·webpack·node.js
java1234_小锋24 分钟前
一周学会Flask3 Python Web开发-客户端状态信息Cookie以及加密
前端·python·flask·flask3
化作繁星27 分钟前
如何在 React 中测试高阶组件?
前端·javascript·react.js
Au_ust34 分钟前
千峰React:函数组件使用(2)
前端·javascript·react.js
爱吃南瓜的北瓜1 小时前
npm install 卡在“sill idealTree buildDeps“
前端·npm·node.js
TTc_1 小时前
记录首次安装远古时代所需的运行环境成功npm install --save-dev node-sass
前端·npm·sass
翻滚吧键盘1 小时前
npm使用了代理,但是代理软件已经关闭导致创建失败
前端·npm·node.js
烂蜻蜓1 小时前
Uniapp 设计思路全分享
前端·css·vue.js·uni-app·html
GAMESLI-GIS1 小时前
【WebGL】fbo双pass案例
前端·javascript·webgl