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

相关推荐
xifangge202523 分钟前
基于 JavaScript 实现 CNC 数控切削参数与螺纹公差纯前端核算引擎
开发语言·前端·javascript
wangruofeng1 小时前
2026 Web 技术选型指南,AI 时代如何选择适合项目的技术栈
前端·aigc·ai编程
honkun61 小时前
vue 表格组件 vxe-table 修改滚动条样式,修改滚动条样式,统一宽度、颜色与自动隐藏
前端·javascript·vue.js
爱勇宝1 小时前
研究数字孪生的这半年,做了个 Demo,也有了一些新想法
前端·程序员
不可能片场1 小时前
工程实践 一个缓存把选片从十分钟压到一分钟
前端·electron
前端小万1 小时前
探索副业五个月,最终以放弃告终
前端·后端·面试
FRing032 小时前
JavaScript入门到精通二十四(正则表达式、元字符、修饰符)
开发语言·前端·javascript·正则表达式
葡萄城技术团队2 小时前
在 SpreadJS 里新增右键菜单,把业务动作放到用户手边
前端
大明二代2 小时前
从 RAG 到有记忆的 Agent:Mastra Memory 与 PostgreSQL 实战
前端·javascript·人工智能
deli0072 小时前
代码截图一键出 PNG 实测:3 种窗口风格,长行超 95 字符会被裁
前端