You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chinese-programmer-wrong-pr.../tools/chromium_extension/js/content-script.js

46 lines
1.5 KiB

{
let URLObj = new URL(location.href);
console.log(URLObj);
if (document.querySelector("#readme table tbody")) {
console.log(chrome.runtime.getURL("css/app.css"));
let css = document.createElement("link");
css.setAttribute("rel", "stylesheet");
css.setAttribute("type", "text/css");
css.setAttribute("href", chrome.runtime.getURL("css/app.css"));
document.head.appendChild(css);
let audio_player = new Audio();
audio_player.setAttribute("autoplay", "true");
document
.querySelector("#readme table tbody")
.addEventListener("click", (event) => {
// console.log(event)
// console.log(event.target.nodeType)
// console.log(event.target.nodeName);
event.preventDefault();
event.stopPropagation();
let audio_url = null;
if (event.target.nodeName === "TD") {
let aTag = event.target.querySelector("a");
if (aTag) {
audio_url = aTag.getAttribute("href");
}
}
if (event.target.nodeName === "IMG") {
let aTag = event.target.parentNode.parentNode;
audio_url = aTag.getAttribute("href");
}
if (audio_url) {
let desURL = new URL(audio_url);
console.log(desURL.protocol);
if (desURL.protocol === "http:") {
//skip http
location.href = audio_url;
} else {
console.log("audio_url:", audio_url);
audio_player.setAttribute("src", audio_url);
}
}
});
}
}