more documentation

This commit is contained in:
vel 2022-01-30 20:18:41 -08:00
parent 4e6d5f4c6b
commit c66f2440aa
Signed by: velvox
GPG Key ID: 1C8200C1D689CEF5
4 changed files with 353 additions and 300 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"discord.removeRemoteRepository": true
}

View File

@ -1,20 +1,11 @@
import {
d as dt
} from './parse_token.util-ed270559.js';
import {
n
} from './router.interface-6cdbc015.js';
import {
e
} from './fetch_youtube-cfbafc47.js';
import {
s as s$1,
m
} from './storage-a8ac7bd3.js';
import { d as dt } from "./parse_token.util-ed270559.js";
import { n } from "./router.interface-6cdbc015.js";
import { e } from "./fetch_youtube-cfbafc47.js";
import { s as s$1, m } from "./storage-a8ac7bd3.js";
class s extends Error {
constructor(t, e) {
super(e), this.code = t, this.message = e;
super(e), (this.code = t), (this.message = e);
}
}
const r = (t, e = {}, n) => ({
@ -22,17 +13,23 @@ const r = (t, e = {}, n) => ({
meta: {
isSuccess: !1,
code: t,
nonce: n
}
nonce: n,
},
});
let i;
const c = t => s$1.cookies.getAll({
url: t
}).then((t => t.filter((t => !t.name.startsWith("ST-"))).map((t => [t.name, t.value])))).then(Object.fromEntries),
const c = (t) =>
s$1.cookies
.getAll({
url: t,
})
.then((t) =>
t.filter((t) => !t.name.startsWith("ST-")).map((t) => [t.name, t.value])
)
.then(Object.fromEntries),
u = {
"@me": async () => {
const t = await m.auth.get("token");
return dt(t)
return dt(t);
},
token: async () => await m.auth.get("token"),
logout: async () => {
@ -40,31 +37,32 @@ const c = t => s$1.cookies.getAll({
await fetch("https://v2.mogultv.org/auth/youtube", {
method: "DELETE",
headers: {
Authorization: `Bearer ${t}`
}
}), await m.auth.remove("token");
Authorization: `Bearer ${t}`,
},
login: async t => {
}),
await m.auth.remove("token");
},
login: async (t) => {
const n = await c(t.href),
a = await fetch("https://v2.mogultv.org/auth/youtube", {
method: "POST",
body: JSON.stringify(Object.assign(Object.assign({}, t), {
cookies: n
}))
body: JSON.stringify(
Object.assign(Object.assign({}, t), {
cookies: n,
})
),
});
if (200 !== a.status) return null;
const {
jwt: o
} = await a.json();
return await m.auth.set("token", o), o
const { jwt: o } = await a.json();
return await m.auth.set("token", o), o;
},
link: async t => {
link: async (t) => {
const n = await m.auth.get("token"),
o = await fetch(`https://v2.mogultv.org/link/${t}`, {
method: "GET",
headers: {
Authorization: `Bearer ${n}`
}
Authorization: `Bearer ${n}`,
},
});
if (200 !== o.status) return;
const s = await o.text();
@ -74,39 +72,42 @@ const c = t => s$1.cookies.getAll({
value: n,
httpOnly: !0,
path: `/link/${t}/callback`,
expirationDate: Math.floor(Date.now() / 1e3) + 3600
}), await chrome.windows.create({
expirationDate: Math.floor(Date.now() / 1e3) + 3600,
}),
await chrome.windows.create({
url: s,
focused: !0,
type: "popup",
width: 850,
height: 800
height: 800,
});
const r = await new Promise((t => {
const r = await new Promise((t) => {
i = t;
}));
return m.auth.set("token", r), dt(r)
});
return m.auth.set("token", r), dt(r);
},
"finish-link": async (t, e) => {
var a, o;
(null === (a = e.sender.tab) || void 0 === a ? void 0 : a.id) && s$1.tabs.remove(null === (o = e.sender.tab) || void 0 === o ? void 0 : o.id), null == i || i(t);
(null === (a = e.sender.tab) || void 0 === a ? void 0 : a.id) &&
s$1.tabs.remove(
null === (o = e.sender.tab) || void 0 === o ? void 0 : o.id
),
null == i || i(t);
},
"disconnect-link": async t => {
"disconnect-link": async (t) => {
const n = await m.auth.get("token"),
o = await fetch(`https://v2.mogultv.org/link/${t}`, {
method: "DELETE",
headers: {
Authorization: `Bearer ${n}`
}
Authorization: `Bearer ${n}`,
},
});
if (200 !== o.status) return;
const {
jwt: s
} = await o.json();
return await m.auth.set("token", s), dt(s)
}
const { jwt: s } = await o.json();
return await m.auth.set("token", s), dt(s);
},
};
const l = t => async () => {
const l = (t) => async () => {
var n, a;
const o = await m.cache.get(t);
let s;
@ -114,40 +115,53 @@ const l = t => async () => {
else {
const o = await fetch("https://v2.mogultv.org" + t),
r = Number(o.headers.get("age")),
i = Number((null === (a = null === (n = o.headers.get("cache-control")) || void 0 === n ? void 0 : n.match(/max-age=(\d+)/)) || void 0 === a ? void 0 : a[1]) || 300) - r,
i =
Number(
(null ===
(a =
null === (n = o.headers.get("cache-control")) || void 0 === n
? void 0
: n.match(/max-age=(\d+)/)) || void 0 === a
? void 0
: a[1]) || 300
) - r,
c = Date.now() + 1e3 * i;
s = await o.json(), await m.cache.set(t, {
(s = await o.json()),
await m.cache.set(t, {
expiresAt: c,
value: s
value: s,
});
}
return s
return s;
};
async function d(t, e) {
const n = {
sourceType: t,
sourceId: e
sourceId: e,
};
try {
const t = await async function(t, e, n, {
throwIfErrors: a
} = {}) {
const t = await (async function (t, e, n, { throwIfErrors: a } = {}) {
var o;
const s = await fetch(t, {
method: "POST",
headers: {
"Content-Type": "application/json"
"Content-Type": "application/json",
},
body: JSON.stringify({
query: e,
variables: n
})
variables: n,
}),
}),
r = await s.json();
if (a && (null === (o = r.data) || void 0 === o ? void 0 : o.errors)) throw new Error(`spore graphql error ${r.data.errors}`);
return r.data
}("https://zygote.spore.build/graphql", "query GetExtensionMappingConnection($sourceType: String, $sourceId: String) {\n\textensionMappingConnection(sourceType: $sourceType, sourceId: $sourceId) {\n\t\tnodes {\n\t\t\tid\n\t\t\tslug\n\t\t\tiframeUrl\n\t\t\tdomAction\n\t\t\tquerySelector\n\t\t\tiframeQuerySelector\n\t\t}\n\t}\n}", n);
return t.extensionMappingConnection.nodes
if (a && (null === (o = r.data) || void 0 === o ? void 0 : o.errors))
throw new Error(`spore graphql error ${r.data.errors}`);
return r.data;
})(
"https://zygote.spore.build/graphql",
"query GetExtensionMappingConnection($sourceType: String, $sourceId: String) {\n\textensionMappingConnection(sourceType: $sourceType, sourceId: $sourceId) {\n\t\tnodes {\n\t\t\tid\n\t\t\tslug\n\t\t\tiframeUrl\n\t\t\tdomAction\n\t\t\tquerySelector\n\t\t\tiframeQuerySelector\n\t\t}\n\t}\n}",
n
);
return t.extensionMappingConnection.nodes;
} catch (t) {
console.error(t);
}
@ -160,97 +174,110 @@ const h = {
if (t && t.expiresAt > Date.now()) n = t.value;
else {
const t = Date.now() + 6e4;
n = await async function() {
(n = await (async function () {
try {
const t = await fetch("https://youtube.com/channel/UCrPseYLGpNygVi34QpGNqpA/live");
const t = await fetch(
"https://youtube.com/channel/UCrPseYLGpNygVi34QpGNqpA/live"
);
if (200 !== t.status) return null;
const e = await t.text(),
n = /(?:window\s*\[\s*["']ytInitialData["']\s*\]|ytInitialData)\s*=\s*({.+?})\s*;/.exec(e);
n =
/(?:window\s*\[\s*["']ytInitialData["']\s*\]|ytInitialData)\s*=\s*({.+?})\s*;/.exec(
e
);
if (n) {
const t = JSON.parse(n[1]),
e = t.currentVideoEndpoint.watchEndpoint.videoId,
a = t.contents.twoColumnWatchNextResults.results.results.contents[0].videoPrimaryInfoRenderer,
o = t.contents.twoColumnWatchNextResults.results.results.contents[1].videoSecondaryInfoRenderer.owner.videoOwnerRenderer.thumbnail.thumbnails[0].url,
s = a.viewCount.videoViewCountRenderer.viewCount.runs.find((t => /^[0-9,]+$/.test(t.text))).text;
a =
t.contents.twoColumnWatchNextResults.results.results
.contents[0].videoPrimaryInfoRenderer,
o =
t.contents.twoColumnWatchNextResults.results.results
.contents[1].videoSecondaryInfoRenderer.owner
.videoOwnerRenderer.thumbnail.thumbnails[0].url,
s = a.viewCount.videoViewCountRenderer.viewCount.runs.find(
(t) => /^[0-9,]+$/.test(t.text)
).text;
return {
title: a.title.runs[0].text,
viewersCount: parseInt(s.replace(/,/g, "")),
previewImageURL: `https://i.ytimg.com/vi/${e}/mqdefault.jpg`,
profileImageURL: o
}
profileImageURL: o,
};
}
} catch (t) {
console.warn(t);
}
return null
}(), await m.cache.set("get-stream", {
return null;
})()),
await m.cache.set("get-stream", {
expiresAt: t,
value: n
value: n,
});
}
return n
return n;
},
"get-user": async t => {
"get-user": async (t) => {
const e$1 = await c(t.href),
n = await e(Object.assign(Object.assign({}, t), {
cookies: e$1
}));
n = await e(
Object.assign(Object.assign({}, t), {
cookies: e$1,
})
);
if (!n.success) throw new s(n.code, n.message);
return n.data
}
return n.data;
},
},
gateway: {
users: l("/gateway/users"),
emotes: l("/gateway/emotes"),
badges: l("/gateway/badges"),
"set-settings": async t => {
"set-settings": async (t) => {
const n = await m.auth.get("token"),
o = await fetch("https://v2.mogultv.org/gateway/settings", {
method: "PUT",
headers: {
Authorization: `Bearer ${n}`
Authorization: `Bearer ${n}`,
},
body: JSON.stringify(t)
body: JSON.stringify(t),
}),
{
jwt: s
} = await o.json();
return m.auth.set("token", s), dt(s)
}
{ jwt: s } = await o.json();
return m.auth.set("token", s), dt(s);
},
},
auth: u,
extension: {
popup: () => s$1.action.openPopup(),
"open-tab": async t => {
"open-tab": async (t) => {
await s$1.tabs.create({
url: t
url: t,
});
}
},
},
spore: {
"fetch-extension-mappings": async t => await d("youtube", t)
}
"fetch-extension-mappings": async (t) => await d("youtube", t),
},
w = async (e, n$1) => {
};
const w = async (e, n$1) => {
var a;
const {
path: o,
body: s
} = e;
const { path: o, body: s } = e;
if (!o) return;
e.meta ? e.meta.sender = n$1 : e.meta = {
e.meta
? (e.meta.sender = n$1)
: (e.meta = {
sender: n$1,
isPort: !1
}, e.meta.isPort || (e.meta.isPort = !1);
const i = t => {},
isPort: !1,
}),
e.meta.isPort || (e.meta.isPort = !1);
const i = (t) => {},
c = o.split("/").filter(Boolean),
u = c[0];
if (!(u in h)) {
return r(n.NotFound, void 0, e.nonce)
return r(n.NotFound, void 0, e.nonce);
}
const l = h[u][c.slice(1).join("/")];
if (!l) {
return r(n.NotFound, void 0, e.nonce)
return r(n.NotFound, void 0, e.nonce);
}
try {
const n$1 = ((e, n$1) => ({
@ -258,24 +285,30 @@ const h = {
meta: {
isSuccess: !0,
code: n.Success,
nonce: n$1
}
nonce: n$1,
},
}))(await l(s, e.meta), e.nonce);
return i(n$1), n$1
return i(n$1), n$1;
} catch (n$1) {
const o = n$1;
return r(null !== (a = o.code) && void 0 !== a ? a : n.Unknown, {
message: o.message
}, e.nonce)
return r(
null !== (a = o.code) && void 0 !== a ? a : n.Unknown,
{
message: o.message,
},
e.nonce
);
}
};
s$1.runtime.onConnect.addListener((t => {
s$1.runtime.onConnect.addListener((t) => {
const e = t.sender;
e && t.onMessage.addListener((async n => {
e &&
t.onMessage.addListener(async (n) => {
n.meta = {
isPort: !0
isPort: !0,
};
const a = await w(n, e);
t.postMessage(a);
}));
})), s$1.runtime.onMessage.addListener(w);
});
}),
s$1.runtime.onMessage.addListener(w);

View File

@ -904,40 +904,48 @@ function ne(e, t) {
return e;
}
}
//spore
async function se(e, t, n) {
//spore fetch data
async function fetchSporeData(e, t, n) {
// if no youtube config, just return
if (!window.ytcfg) return;
const s$1 = await e.fetch("/auth/token");
if (!s(s$1) || !s$1.body) return;
// fetch our auth token
const mogulAuth = await e.fetch("/auth/token");
// todo find s
if (!s(mogulAuth) || !mogulAuth.body) return;
const r = {
sourceType: "google",
token: s$1.body,
token: mogulAuth.body,
};
t.setCredentials(r);
const o = await e.fetch("/spore/fetch-extension-mappings", n);
if (s(o)) {
const e = o.body;
e &&
(null == e ? void 0 : e.length) > 0 &&
e.forEach((e) => {
re(e, {
const sporeData = await e.fetch("/spore/fetch-extension-mappings", n);
if (s(sporeData)) {
const body = sporeData.body;
if (body && body.length > 0) {
body.forEach((e) => {
sporeInject(e, {
sourceType: "youtube",
});
});
}
nks;
}
// spore
function re(e, { sourceType: t, retries: n = 15 }) {
}
// spore injection
function sporeInject(e, { sourceType: t, retries: n = 15 }) {
if (!e) return;
if (n < 0) return;
const s = (function (e) {
const injectionSelector = (function (e) {
var t, n;
// if the iframe exists already, lets select that instead
if (e.iframeQuerySelector) {
const s = document.querySelector(e.querySelector),
r =
null !== (t = null == s ? void 0 : s.contentDocument) && void 0 !== t
// void 0 = undefined
const query = document.querySelector(e.querySelector);
const r =
null !== (t = null == query ? void 0 : query.contentDocument) &&
void 0 !== t
? t
: null === (n = null == s ? void 0 : s.contentWindow) ||
: null === (n = null == query ? void 0 : query.contentWindow) ||
void 0 === n
? void 0
: n.document;
@ -946,22 +954,24 @@ function re(e, { sourceType: t, retries: n = 15 }) {
}
return document.querySelector(e.querySelector);
})(e);
if (s) {
if (injectionSelector) {
const t = document.createElement("iframe");
(t.src = e.iframeUrl),
t.setAttribute("key", e.slug),
(t.id = e.slug),
t.src = e.iframeUrl;
t.setAttribute("key", e.slug);
t.id = e.slug;
"append" === e.domAction
? s.appendChild(t)
: "replace" === e.domAction && s.replaceWith(t);
} else
? injectionSelector.appendChild(t)
: "replace" === e.domAction && injectionSelector.replaceWith(t);
} else {
setTimeout(() => {
re(e, {
sporeInject(e, {
sourceType: t,
retries: n - 1,
});
}, 250);
}
}
// ottos code?
var ie;
async function oe(e, n) {
await customElements.whenDefined(e);
@ -1259,7 +1269,7 @@ if (he) {
const s = setInterval(() => {
const t = n();
(null == t ? void 0 : t.channelId) &&
(clearInterval(s), se(fe, e, t.channelId));
(clearInterval(s), fetchSporeData(fe, e, t.channelId));
}, 1e3);
setInterval(() => {
const e = document.querySelector("ytd-live-chat-frame iframe");

7
sporeinjection.json Normal file
View File

@ -0,0 +1,7 @@
{
"iframeQuerySelector": "",
"querySelector": "",
"slug": "ludwig",
"domAction": "append",
"iframeUrl": "https://ludwig.social/component-instance/4e8899d0-6d27-11ec-88da-c92b950649ef"
}