Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions userscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@

function shouldTranslateEl(el) {
const blockIds = [
"readme",
"file-name-editor-breadcrumb", "StickyHeader" // fix repo详情页文件路径breadcrumb
"readme",
"file-name-editor-breadcrumb", "StickyHeader" // fix repo详情页文件路径breadcrumb
];
const blockClass = [
"CodeMirror",
Expand All @@ -120,6 +120,14 @@
"PRIVATE_TreeView-item", // 文件树
"repo", // 项目名称
];
/**
* 过滤dom属性
* key是属性,val是对应值(会转为正则匹配,所以不需要完全一致,包含一部分特定文字就可以)
*/
const attrMap = [
// 仓库语言,不需要翻译
{ key: 'data-ga-click', val: 'language stats search click' },
]
const blockTags = ["CODE", "SCRIPT", "LINK", "IMG", "svg", "TABLE", "PRE"];
const blockItemprops = ["name"];

Expand Down Expand Up @@ -149,8 +157,23 @@
}
}
}

// 过滤属性
let some = attrMap.some(x => {
let itemprops = el.getAttribute(x.key);
if (itemprops) {
// 转换为正则表达式(将目标字符串中的特殊字符进行转义。)
const reg = new RegExp(x.val.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'g');
// 匹配
return itemprops.match(reg)
}
})
// 要忽略的只要有一个满足就不翻译
if (some) { return false }

}


return true;
}

Expand Down Expand Up @@ -200,8 +223,8 @@
}
}
if(reTrans) {
traverseElement(document.body);
translateTime();
traverseElement(document.body);
translateTime();
}
});

Expand Down