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 { import { d as dt } from "./parse_token.util-ed270559.js";
d as dt import { n } from "./router.interface-6cdbc015.js";
} from './parse_token.util-ed270559.js'; import { e } from "./fetch_youtube-cfbafc47.js";
import { import { s as s$1, m } from "./storage-a8ac7bd3.js";
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 { class s extends Error {
constructor(t, e) { constructor(t, e) {
super(e), this.code = t, this.message = e; super(e), (this.code = t), (this.message = e);
} }
} }
const r = (t, e = {}, n) => ({ const r = (t, e = {}, n) => ({
@ -22,17 +13,23 @@ const r = (t, e = {}, n) => ({
meta: { meta: {
isSuccess: !1, isSuccess: !1,
code: t, code: t,
nonce: n nonce: n,
} },
}); });
let i; let i;
const c = t => s$1.cookies.getAll({ const c = (t) =>
url: t s$1.cookies
}).then((t => t.filter((t => !t.name.startsWith("ST-"))).map((t => [t.name, t.value])))).then(Object.fromEntries), .getAll({
url: t,
})
.then((t) =>
t.filter((t) => !t.name.startsWith("ST-")).map((t) => [t.name, t.value])
)
.then(Object.fromEntries),
u = { u = {
"@me": async () => { "@me": async () => {
const t = await m.auth.get("token"); const t = await m.auth.get("token");
return dt(t) return dt(t);
}, },
token: async () => await m.auth.get("token"), token: async () => await m.auth.get("token"),
logout: async () => { logout: async () => {
@ -40,31 +37,32 @@ const c = t => s$1.cookies.getAll({
await fetch("https://v2.mogultv.org/auth/youtube", { await fetch("https://v2.mogultv.org/auth/youtube", {
method: "DELETE", method: "DELETE",
headers: { headers: {
Authorization: `Bearer ${t}` Authorization: `Bearer ${t}`,
}
}), await m.auth.remove("token");
}, },
login: async t => { }),
await m.auth.remove("token");
},
login: async (t) => {
const n = await c(t.href), const n = await c(t.href),
a = await fetch("https://v2.mogultv.org/auth/youtube", { a = await fetch("https://v2.mogultv.org/auth/youtube", {
method: "POST", method: "POST",
body: JSON.stringify(Object.assign(Object.assign({}, t), { body: JSON.stringify(
cookies: n Object.assign(Object.assign({}, t), {
})) cookies: n,
})
),
}); });
if (200 !== a.status) return null; if (200 !== a.status) return null;
const { const { jwt: o } = await a.json();
jwt: o return await m.auth.set("token", o), 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"), const n = await m.auth.get("token"),
o = await fetch(`https://v2.mogultv.org/link/${t}`, { o = await fetch(`https://v2.mogultv.org/link/${t}`, {
method: "GET", method: "GET",
headers: { headers: {
Authorization: `Bearer ${n}` Authorization: `Bearer ${n}`,
} },
}); });
if (200 !== o.status) return; if (200 !== o.status) return;
const s = await o.text(); const s = await o.text();
@ -74,39 +72,42 @@ const c = t => s$1.cookies.getAll({
value: n, value: n,
httpOnly: !0, httpOnly: !0,
path: `/link/${t}/callback`, path: `/link/${t}/callback`,
expirationDate: Math.floor(Date.now() / 1e3) + 3600 expirationDate: Math.floor(Date.now() / 1e3) + 3600,
}), await chrome.windows.create({ }),
await chrome.windows.create({
url: s, url: s,
focused: !0, focused: !0,
type: "popup", type: "popup",
width: 850, width: 850,
height: 800 height: 800,
}); });
const r = await new Promise((t => { const r = await new Promise((t) => {
i = t; i = t;
})); });
return m.auth.set("token", r), dt(r) return m.auth.set("token", r), dt(r);
}, },
"finish-link": async (t, e) => { "finish-link": async (t, e) => {
var a, o; 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"), const n = await m.auth.get("token"),
o = await fetch(`https://v2.mogultv.org/link/${t}`, { o = await fetch(`https://v2.mogultv.org/link/${t}`, {
method: "DELETE", method: "DELETE",
headers: { headers: {
Authorization: `Bearer ${n}` Authorization: `Bearer ${n}`,
} },
}); });
if (200 !== o.status) return; if (200 !== o.status) return;
const { const { jwt: s } = await o.json();
jwt: s return await m.auth.set("token", s), dt(s);
} = await o.json(); },
return await m.auth.set("token", s), dt(s)
}
}; };
const l = t => async () => { const l = (t) => async () => {
var n, a; var n, a;
const o = await m.cache.get(t); const o = await m.cache.get(t);
let s; let s;
@ -114,40 +115,53 @@ const l = t => async () => {
else { else {
const o = await fetch("https://v2.mogultv.org" + t), const o = await fetch("https://v2.mogultv.org" + t),
r = Number(o.headers.get("age")), 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; 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, expiresAt: c,
value: s value: s,
}); });
} }
return s return s;
}; };
async function d(t, e) { async function d(t, e) {
const n = { const n = {
sourceType: t, sourceType: t,
sourceId: e sourceId: e,
}; };
try { try {
const t = await async function(t, e, n, { const t = await (async function (t, e, n, { throwIfErrors: a } = {}) {
throwIfErrors: a
} = {}) {
var o; var o;
const s = await fetch(t, { const s = await fetch(t, {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json",
}, },
body: JSON.stringify({ body: JSON.stringify({
query: e, query: e,
variables: n variables: n,
}) }),
}), }),
r = await s.json(); 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}`); if (a && (null === (o = r.data) || void 0 === o ? void 0 : o.errors))
return r.data throw new Error(`spore graphql error ${r.data.errors}`);
}("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 r.data;
return t.extensionMappingConnection.nodes })(
"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) { } catch (t) {
console.error(t); console.error(t);
} }
@ -160,97 +174,110 @@ const h = {
if (t && t.expiresAt > Date.now()) n = t.value; if (t && t.expiresAt > Date.now()) n = t.value;
else { else {
const t = Date.now() + 6e4; const t = Date.now() + 6e4;
n = await async function() { (n = await (async function () {
try { 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; if (200 !== t.status) return null;
const e = await t.text(), 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) { if (n) {
const t = JSON.parse(n[1]), const t = JSON.parse(n[1]),
e = t.currentVideoEndpoint.watchEndpoint.videoId, e = t.currentVideoEndpoint.watchEndpoint.videoId,
a = t.contents.twoColumnWatchNextResults.results.results.contents[0].videoPrimaryInfoRenderer, a =
o = t.contents.twoColumnWatchNextResults.results.results.contents[1].videoSecondaryInfoRenderer.owner.videoOwnerRenderer.thumbnail.thumbnails[0].url, t.contents.twoColumnWatchNextResults.results.results
s = a.viewCount.videoViewCountRenderer.viewCount.runs.find((t => /^[0-9,]+$/.test(t.text))).text; .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 { return {
title: a.title.runs[0].text, title: a.title.runs[0].text,
viewersCount: parseInt(s.replace(/,/g, "")), viewersCount: parseInt(s.replace(/,/g, "")),
previewImageURL: `https://i.ytimg.com/vi/${e}/mqdefault.jpg`, previewImageURL: `https://i.ytimg.com/vi/${e}/mqdefault.jpg`,
profileImageURL: o profileImageURL: o,
} };
} }
} catch (t) { } catch (t) {
console.warn(t); console.warn(t);
} }
return null return null;
}(), await m.cache.set("get-stream", { })()),
await m.cache.set("get-stream", {
expiresAt: t, 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), const e$1 = await c(t.href),
n = await e(Object.assign(Object.assign({}, t), { n = await e(
cookies: e$1 Object.assign(Object.assign({}, t), {
})); cookies: e$1,
})
);
if (!n.success) throw new s(n.code, n.message); if (!n.success) throw new s(n.code, n.message);
return n.data return n.data;
} },
}, },
gateway: { gateway: {
users: l("/gateway/users"), users: l("/gateway/users"),
emotes: l("/gateway/emotes"), emotes: l("/gateway/emotes"),
badges: l("/gateway/badges"), badges: l("/gateway/badges"),
"set-settings": async t => { "set-settings": async (t) => {
const n = await m.auth.get("token"), const n = await m.auth.get("token"),
o = await fetch("https://v2.mogultv.org/gateway/settings", { o = await fetch("https://v2.mogultv.org/gateway/settings", {
method: "PUT", method: "PUT",
headers: { headers: {
Authorization: `Bearer ${n}` Authorization: `Bearer ${n}`,
}, },
body: JSON.stringify(t) body: JSON.stringify(t),
}), }),
{ { jwt: s } = await o.json();
jwt: s return m.auth.set("token", s), dt(s);
} = await o.json(); },
return m.auth.set("token", s), dt(s)
}
}, },
auth: u, auth: u,
extension: { extension: {
popup: () => s$1.action.openPopup(), popup: () => s$1.action.openPopup(),
"open-tab": async t => { "open-tab": async (t) => {
await s$1.tabs.create({ await s$1.tabs.create({
url: t url: t,
}); });
} },
}, },
spore: { 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; var a;
const { const { path: o, body: s } = e;
path: o,
body: s
} = e;
if (!o) return; if (!o) return;
e.meta ? e.meta.sender = n$1 : e.meta = { e.meta
? (e.meta.sender = n$1)
: (e.meta = {
sender: n$1, sender: n$1,
isPort: !1 isPort: !1,
}, e.meta.isPort || (e.meta.isPort = !1); }),
const i = t => {}, e.meta.isPort || (e.meta.isPort = !1);
const i = (t) => {},
c = o.split("/").filter(Boolean), c = o.split("/").filter(Boolean),
u = c[0]; u = c[0];
if (!(u in h)) { 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("/")]; const l = h[u][c.slice(1).join("/")];
if (!l) { if (!l) {
return r(n.NotFound, void 0, e.nonce) return r(n.NotFound, void 0, e.nonce);
} }
try { try {
const n$1 = ((e, n$1) => ({ const n$1 = ((e, n$1) => ({
@ -258,24 +285,30 @@ const h = {
meta: { meta: {
isSuccess: !0, isSuccess: !0,
code: n.Success, code: n.Success,
nonce: n$1 nonce: n$1,
} },
}))(await l(s, e.meta), e.nonce); }))(await l(s, e.meta), e.nonce);
return i(n$1), n$1 return i(n$1), n$1;
} catch (n$1) { } catch (n$1) {
const o = n$1; const o = n$1;
return r(null !== (a = o.code) && void 0 !== a ? a : n.Unknown, { return r(
message: o.message null !== (a = o.code) && void 0 !== a ? a : n.Unknown,
}, e.nonce) {
message: o.message,
},
e.nonce
);
} }
}; };
s$1.runtime.onConnect.addListener((t => { s$1.runtime.onConnect.addListener((t) => {
const e = t.sender; const e = t.sender;
e && t.onMessage.addListener((async n => { e &&
t.onMessage.addListener(async (n) => {
n.meta = { n.meta = {
isPort: !0 isPort: !0,
}; };
const a = await w(n, e); const a = await w(n, e);
t.postMessage(a); 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; return e;
} }
} }
//spore //spore fetch data
async function se(e, t, n) { async function fetchSporeData(e, t, n) {
// if no youtube config, just return
if (!window.ytcfg) return; if (!window.ytcfg) return;
const s$1 = await e.fetch("/auth/token"); // fetch our auth token
if (!s(s$1) || !s$1.body) return; const mogulAuth = await e.fetch("/auth/token");
// todo find s
if (!s(mogulAuth) || !mogulAuth.body) return;
const r = { const r = {
sourceType: "google", sourceType: "google",
token: s$1.body, token: mogulAuth.body,
}; };
t.setCredentials(r); t.setCredentials(r);
const o = await e.fetch("/spore/fetch-extension-mappings", n); const sporeData = await e.fetch("/spore/fetch-extension-mappings", n);
if (s(o)) { if (s(sporeData)) {
const e = o.body; const body = sporeData.body;
e && if (body && body.length > 0) {
(null == e ? void 0 : e.length) > 0 && body.forEach((e) => {
e.forEach((e) => { sporeInject(e, {
re(e, {
sourceType: "youtube", sourceType: "youtube",
}); });
}); });
} }
nks;
}
} }
// spore // spore injection
function re(e, { sourceType: t, retries: n = 15 }) { function sporeInject(e, { sourceType: t, retries: n = 15 }) {
if (!e) return; if (!e) return;
if (n < 0) return; if (n < 0) return;
const s = (function (e) { const injectionSelector = (function (e) {
var t, n; var t, n;
// if the iframe exists already, lets select that instead
if (e.iframeQuerySelector) { if (e.iframeQuerySelector) {
const s = document.querySelector(e.querySelector), // void 0 = undefined
r = const query = document.querySelector(e.querySelector);
null !== (t = null == s ? void 0 : s.contentDocument) && void 0 !== t
const r =
null !== (t = null == query ? void 0 : query.contentDocument) &&
void 0 !== t
? t ? t
: null === (n = null == s ? void 0 : s.contentWindow) || : null === (n = null == query ? void 0 : query.contentWindow) ||
void 0 === n void 0 === n
? void 0 ? void 0
: n.document; : n.document;
@ -946,22 +954,24 @@ function re(e, { sourceType: t, retries: n = 15 }) {
} }
return document.querySelector(e.querySelector); return document.querySelector(e.querySelector);
})(e); })(e);
if (s) { if (injectionSelector) {
const t = document.createElement("iframe"); const t = document.createElement("iframe");
(t.src = e.iframeUrl), t.src = e.iframeUrl;
t.setAttribute("key", e.slug), t.setAttribute("key", e.slug);
(t.id = e.slug), t.id = e.slug;
"append" === e.domAction "append" === e.domAction
? s.appendChild(t) ? injectionSelector.appendChild(t)
: "replace" === e.domAction && s.replaceWith(t); : "replace" === e.domAction && injectionSelector.replaceWith(t);
} else } else {
setTimeout(() => { setTimeout(() => {
re(e, { sporeInject(e, {
sourceType: t, sourceType: t,
retries: n - 1, retries: n - 1,
}); });
}, 250); }, 250);
}
} }
// ottos code?
var ie; var ie;
async function oe(e, n) { async function oe(e, n) {
await customElements.whenDefined(e); await customElements.whenDefined(e);
@ -1259,7 +1269,7 @@ if (he) {
const s = setInterval(() => { const s = setInterval(() => {
const t = n(); const t = n();
(null == t ? void 0 : t.channelId) && (null == t ? void 0 : t.channelId) &&
(clearInterval(s), se(fe, e, t.channelId)); (clearInterval(s), fetchSporeData(fe, e, t.channelId));
}, 1e3); }, 1e3);
setInterval(() => { setInterval(() => {
const e = document.querySelector("ytd-live-chat-frame iframe"); 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"
}