mogultv/content/twitch/inject.js

200 lines
9.0 KiB
JavaScript

import '../../index-6137f488.js';
import {
e
} from '../../background.injected-af36b849.js';
import {
s
} from '../../router.interface-6cdbc015.js';
!async function(e) {
async function a(e) {
if (Array.isArray(e))
for (const t of e) await n(t);
return e
}
async function n(a) {
var n, i, r;
try {
switch (a.extensions.operationName) {
case "FollowingLive_CurrentUser": {
const n = a.data,
i = await e.fetch("/youtube/get-stream");
s(i) && i.body && (n.currentUser.followedLiveUsers.edges.push(function({
title: e,
viewersCount: t,
profileImageURL: a,
previewImageURL: n
}) {
return {
__typename: "FollowedLiveUserEdge",
cursor: "LTE=",
node: {
__typename: "User",
id: "40934651",
displayName: "ludwig",
login: "ludwig",
profileImageURL: a,
stream: {
broadcaster: {
id: "40934651",
primaryColorHex: "00FFE2",
__typename: "User",
channel: {
id: "40934651",
self: {
isAuthorized: !0,
__typename: "ChannelSelfEdge"
},
__typename: "Channel"
}
},
id: "-1",
previewImageURL: n,
game: {
id: "-1",
name: "YouTube",
displayName: "YouTube",
boxArtURL: "https://i.postimg.cc/NjQvCPh2/image.png",
__typename: "Game"
},
restriction: null,
tags: [],
title: e,
type: "live",
viewersCount: t,
__typename: "Stream"
}
}
}
}(i.body)), n.currentUser.followedLiveUsers.edges.sort(((e, t) => t.node.stream.viewersCount - e.node.stream.viewersCount)));
break
}
case "PersonalSections": {
const n = a.data.personalSections.find((e => "FOLLOWED_SECTION" === e.type));
if (n) {
const a = await e.fetch("/youtube/get-stream");
s(a) && a.body && (n.items.push(function({
title: e,
viewersCount: t,
profileImageURL: a,
previewImageURL: n
}) {
return {
trackingID: "1bb8ab4b-aed2-4f25-a750-c295d57e6a95",
promotionsCampaignID: "",
user: {
id: "40934651",
login: "ludwig",
displayName: "ludwig",
profileImageURL: a,
primaryColorHex: "00FFE2",
broadcastSettings: {
id: "40934651",
title: e,
__typename: "BroadcastSettings"
},
channel: {
id: "40934651",
creatorAnniversaries: {
id: "40934651",
isAnniversary: !1,
__typename: "CreatorAnniversaries"
},
__typename: "Channel"
},
__typename: "User"
},
label: "NONE",
content: {
id: "-1",
previewImageURL: n,
broadcaster: {
id: "40934651",
broadcastSettings: {
id: "40934651",
title: e,
__typename: "BroadcastSettings"
},
__typename: "User"
},
viewersCount: t,
self: {
canWatch: !0,
isRestricted: !1,
restrictionType: null,
__typename: "StreamSelfConnection"
},
game: {
id: "-1",
displayName: "YouTube",
name: "YouTube",
__typename: "Game"
},
type: "live",
__typename: "Stream"
},
__typename: "PersonalSectionChannel"
}
}(a.body)), n.items.sort(((e, t) => (t.content.viewersCount || 0) - (e.content.viewersCount || 0))));
}
break
}
case "StreamMetadata": {
const n = a.data;
if ("40934651" === n.user.id) {
const a = await e.fetch("/youtube/get-stream");
s(a) && a.body && (n.user.lastBroadcast.id = "-1", n.user.lastBroadcast.title = a.body.title, n.user.stream = {
id: "-1",
type: "live",
createdAt: (new Date).toJSON(),
viewersCount: a.body.viewersCount,
game: {
id: "-1",
name: "YouTube",
__typename: "Game"
},
__typename: "Stream"
});
}
break
}
default: {
const o = a.data;
if ("40934651" === (null === (n = o.user) || void 0 === n ? void 0 : n.id) && (null === (r = null === (i = o.user) || void 0 === i ? void 0 : i.lastBroadcast) || void 0 === r ? void 0 : r.title)) {
const a = await e.fetch("/youtube/get-stream");
s(a) && a.body && (o.user.lastBroadcast.title = a.body.title);
}
}
}
} catch (e) {}
}
const i = window.fetch.bind(window);
window.fetch = async function(e, t) {
const n = await i(e, t);
try {
let t;
if (t = "string" == typeof e ? e : e.url, !t.includes("gql.twitch.tv/gql")) return n;
const i = n.text.bind(n),
r = n.json.bind(n);
n.text = async function() {
const e = await i();
try {
const t = JSON.parse(e);
return await a(t), JSON.stringify(t)
} catch (t) {
return e
}
}, n.json = async function() {
const e = await r();
try {
return await a(e), e
} catch (t) {
return e
}
};
} catch (e) {
return n
}
return n
};
}(new e);