Skip to content

Commit

Permalink
perf: 优化miniprogramHack
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaviilee committed Oct 22, 2024
1 parent 15607a8 commit 18776e4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
18 changes: 8 additions & 10 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,18 @@ export function miniprogramHack() {
document.addEventListener('DOMContentLoaded', function() {
// 检查 html 标签是否有 wechat-miniprogram 类
if (document.documentElement.classList.contains('wechat-miniprogram')) {
// 获取所有的 a 标签
var links = document.getElementsByTagName('a');

// 为每个链接添加点击事件监听器
Array.from(links).forEach(function(link) {
link.addEventListener('click', function(event) {
var href = this.getAttribute('href');
// 为整个 document 添加一个点击事件监听器
document.addEventListener('click', function(event) {
// 检查被点击的元素是否是一个链接
if (event.target.tagName === 'A') {
var href = event.target.getAttribute('href');

// 检查是否是相对链接
var isRelative = !href.startsWith('http://') && !href.startsWith('https://') && !href.startsWith('//');

// 检查是否是jx3box.com域名
var isJx3boxDomain = /jx3box\.com/.test(href);

// 检查是否是jx3.xoyo.com域名
var isJx3Domain = /jx3\.xoyo\.com/.test(href);

Expand All @@ -435,13 +433,13 @@ export function miniprogramHack() {
// 阻止默认行为
event.preventDefault();
}
});
}
});
}
});

}


export default {
resolveImagePath,
checkImageLoad,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jx3box/jx3box-common",
"version": "8.4.0",
"version": "8.4.1",
"description": "JX3BOX公共基础模块",
"main": "main.js",
"repository": {
Expand Down

0 comments on commit 18776e4

Please sign in to comment.