Skip to content

Commit

Permalink
fix peek無し対応
Browse files Browse the repository at this point in the history
  • Loading branch information
fa0311 committed Jul 16, 2022
1 parent fcefa49 commit 3edf61c
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions js/TwitterSpacesWiretapExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ new MutationObserver(async () => {
if (href == location.href) return;
href = location.href;
if (href.match(new RegExp("https://twitter.com/i/spaces/")) == null) return;
let id = href.split("?")[0].split("/").slice(-1)[0];
if (id == "peek") id = href.split("?")[0].split("/").slice(-2)[0];
if (document.getElementById("twitter-spaces-wiretap-audio") != null) return;
let hrefList = href.split("?")[0].split("/");
let id = hrefList.slice(-1)[0];
if (id == "peek") id = hrefList.slice(-2)[0];
console.log(id);

let space = new TwitterSpacesWiretap();
Expand All @@ -93,12 +95,34 @@ new MutationObserver(async () => {

const audio = document.createElement("audio");
audio.setAttribute("controls", "");
document
.querySelectorAll('div[role="menu"] div[aria-haspopup="menu"]')[0]
.parentNode.parentNode.prepend(audio);
audio.id = "twitter-spaces-wiretap-audio";

if (hrefList.slice(-1)[0] == "peek") {
let element;
for (let i = 0; i < 10; i++) {
element = document.querySelector(
'div[role="menu"] div[aria-haspopup="menu"]'
);
if (element != null) break;
await new Promise((resolve) => setTimeout(resolve, 500));
}
if (element == null) return;
element.parentNode.parentNode.prepend(audio);
} else {
let element;
for (let i = 0; i < 10; i++) {
element = document.querySelector(
'div[data-testid="placementTracking"] div[role="button"] > div > div'
);
if (element != null) break;
await new Promise((resolve) => setTimeout(resolve, 500));
}
if (element == null) return;
element.append(audio);
}

if (Hls.isSupported()) {
var hls = new Hls();
let hls = new Hls();
hls.loadSource(url);
hls.attachMedia(audio);
audio.play();
Expand Down

0 comments on commit 3edf61c

Please sign in to comment.