parent
06cede50cd
commit
502f62c128
@ -1,66 +1,84 @@
|
|||||||
import box from "./box.js";
|
import box from "./box.js";
|
||||||
|
|
||||||
let init = () => {
|
let init = () => {
|
||||||
let URLObj = new URL(location.href);
|
let URLObj = new URL(location.href);
|
||||||
console.log(URLObj);
|
console.log(URLObj);
|
||||||
if (document.querySelector("#readme table tbody")) {
|
if (document.querySelector("#readme table tbody")) {
|
||||||
box.styleConfig();
|
//载入自定义组件样式
|
||||||
box.customElement();
|
box.styleConfig();
|
||||||
|
//载入自定义组件
|
||||||
|
box.customElement();
|
||||||
|
|
||||||
let audio_player = new Audio();
|
let audio_player = new Audio();
|
||||||
audio_player.setAttribute("autoplay", "true");
|
audio_player.setAttribute("autoplay", "true");
|
||||||
document
|
document
|
||||||
.querySelector("#readme table tbody")
|
.querySelector("#readme table tbody")
|
||||||
.addEventListener("click", (event) => {
|
.addEventListener("click", (event) => {
|
||||||
//console.log(event.target)
|
//console.log(event.target)
|
||||||
// console.log(event.target.nodeType)
|
// console.log(event.target.nodeType)
|
||||||
// console.log(event.target.nodeName);
|
// console.log(event.target.nodeName);
|
||||||
let parentElement = event.target.parentElement;
|
let parentElement = event.target.parentElement;
|
||||||
if (parentElement && parentElement.nodeName === "TR") {
|
if (parentElement && parentElement.nodeName === "TR") {
|
||||||
if (parentElement.firstElementChild === event.target) {
|
if (parentElement.firstElementChild === event.target) {
|
||||||
//使用搜索引擎查询发音
|
//使用搜索引擎查询发音
|
||||||
box.goToSearchPronounce(event.target.innerText);
|
box.goToSearchPronounce(event.target.innerText);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
let audio_url = null;
|
let audio_url = null;
|
||||||
if (event.target.nodeName === "TD") {
|
if (event.target.nodeName === "TD") {
|
||||||
let aTag = event.target.querySelector("a");
|
let aTag = event.target.querySelector("a");
|
||||||
if (aTag) {
|
if (aTag) {
|
||||||
audio_url = aTag.getAttribute("href");
|
audio_url = aTag.getAttribute("href");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (event.target.nodeName === "IMG") {
|
if (event.target.nodeName === "IMG") {
|
||||||
let aTag = event.target.parentNode.parentNode;
|
let aTag = event.target.parentNode.parentNode;
|
||||||
audio_url = aTag.getAttribute("href");
|
audio_url = aTag.getAttribute("href");
|
||||||
}
|
}
|
||||||
if (audio_url) {
|
if (audio_url) {
|
||||||
let desURL = new URL(audio_url);
|
let desURL = new URL(audio_url);
|
||||||
//console.log(desURL.protocol);
|
//console.log(desURL.protocol);
|
||||||
if (desURL.protocol === "http:") {
|
if (desURL.protocol === "http:") {
|
||||||
//skip http
|
//skip http
|
||||||
location.href = audio_url;
|
location.href = audio_url;
|
||||||
} else {
|
} else {
|
||||||
// console.log("audio_url:", audio_url);
|
// console.log("audio_url:", audio_url);
|
||||||
audio_player.setAttribute("src", audio_url);
|
audio_player.setAttribute("src", audio_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
document
|
document
|
||||||
.querySelector("#readme table tbody")
|
.querySelector("#readme table tbody")
|
||||||
.addEventListener("mouseover", (event) => {
|
.addEventListener("mouseover", (event) => {
|
||||||
let parentElement = event.target.parentElement;
|
let parentElement = event.target.parentElement;
|
||||||
if (parentElement && parentElement.nodeName === "TR") {
|
if (parentElement && parentElement.nodeName === "TR") {
|
||||||
if (parentElement.firstElementChild === event.target) {
|
if (parentElement.firstElementChild === event.target) {
|
||||||
event.target.setAttribute("title", "点击我打开搜索引擎检索");
|
event.target.setAttribute("title", "点击我打开搜索引擎检索");
|
||||||
event.target.style.cursor = "pointer";
|
event.target.style.cursor = "pointer";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
let table = document.querySelector("#readme table");
|
||||||
console.log("no found README.md table");
|
let parent = table.parentNode;
|
||||||
}
|
let note = document.createElement("span");
|
||||||
|
note.innerText = `⚪重置扩展提供的搜索结果打开方式⚪`;
|
||||||
|
note.setAttribute(
|
||||||
|
"class",
|
||||||
|
"chinese-programmer-wrong-pronunciation-custom-note-reset"
|
||||||
|
);
|
||||||
|
|
||||||
|
note.addEventListener("click", (event) => {
|
||||||
|
//重置配置
|
||||||
|
event.preventDefault();
|
||||||
|
event.stopPropagation();
|
||||||
|
box.cleanOpener();
|
||||||
|
});
|
||||||
|
parent.insertBefore(note, table);
|
||||||
|
} else {
|
||||||
|
console.log("no found README.md table");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export { init };
|
export { init };
|
||||||
|
Loading…
Reference in new issue