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,281 +1,314 @@
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) => ({
body: e, body: e,
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({
u = { url: t,
"@me": async () => { })
const t = await m.auth.get("token"); .then((t) =>
return dt(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);
},
token: async () => await m.auth.get("token"),
logout: async () => {
const t = await m.auth.get("token");
await fetch("https://v2.mogultv.org/auth/youtube", {
method: "DELETE",
headers: {
Authorization: `Bearer ${t}`,
}, },
token: async () => await m.auth.get("token"), }),
logout: async () => { await m.auth.remove("token");
const t = await m.auth.get("token"); },
await fetch("https://v2.mogultv.org/auth/youtube", { login: async (t) => {
method: "DELETE", const n = await c(t.href),
headers: { a = await fetch("https://v2.mogultv.org/auth/youtube", {
Authorization: `Bearer ${t}` method: "POST",
} body: JSON.stringify(
}), await m.auth.remove("token"); Object.assign(Object.assign({}, t), {
}, cookies: n,
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
}))
});
if (200 !== a.status) return null;
const {
jwt: o
} = await a.json();
return await m.auth.set("token", o), o
},
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}`
}
});
if (200 !== o.status) return;
const s = await o.text();
await chrome.cookies.set({
url: "https://v2.mogultv.org",
name: "Authorization",
value: n,
httpOnly: !0,
path: `/link/${t}/callback`,
expirationDate: Math.floor(Date.now() / 1e3) + 3600
}), await chrome.windows.create({
url: s,
focused: !0,
type: "popup",
width: 850,
height: 800
});
const r = await new Promise((t => {
i = t;
}));
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);
},
"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}`
}
});
if (200 !== o.status) return;
const {
jwt: s
} = await o.json();
return await m.auth.set("token", s), dt(s)
}
};
const l = t => async () => {
var n, a;
const o = await m.cache.get(t);
let s;
if (o && o.expiresAt > Date.now()) s = o.value;
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,
c = Date.now() + 1e3 * i;
s = await o.json(), await m.cache.set(t, {
expiresAt: c,
value: s
}); });
} if (200 !== a.status) return null;
return s const { jwt: o } = await a.json();
return await m.auth.set("token", o), o;
},
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}`,
},
});
if (200 !== o.status) return;
const s = await o.text();
await chrome.cookies.set({
url: "https://v2.mogultv.org",
name: "Authorization",
value: n,
httpOnly: !0,
path: `/link/${t}/callback`,
expirationDate: Math.floor(Date.now() / 1e3) + 3600,
}),
await chrome.windows.create({
url: s,
focused: !0,
type: "popup",
width: 850,
height: 800,
});
const r = await new Promise((t) => {
i = t;
});
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);
},
"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}`,
},
});
if (200 !== o.status) return;
const { jwt: s } = await o.json();
return await m.auth.set("token", s), dt(s);
},
};
const l = (t) => async () => {
var n, a;
const o = await m.cache.get(t);
let s;
if (o && o.expiresAt > Date.now()) s = o.value;
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,
c = Date.now() + 1e3 * i;
(s = await o.json()),
await m.cache.set(t, {
expiresAt: c,
value: 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;
} = {}) { const s = await fetch(t, {
var o; method: "POST",
const s = await fetch(t, { headers: {
method: "POST", "Content-Type": "application/json",
headers: { },
"Content-Type": "application/json" body: JSON.stringify({
}, query: e,
body: JSON.stringify({ variables: n,
query: e, }),
variables: n }),
}) r = await s.json();
}), if (a && (null === (o = r.data) || void 0 === o ? void 0 : o.errors))
r = await s.json(); throw new Error(`spore graphql error ${r.data.errors}`);
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;
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); "https://zygote.spore.build/graphql",
return t.extensionMappingConnection.nodes "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}",
} catch (t) { n
console.error(t); );
} return t.extensionMappingConnection.nodes;
} catch (t) {
console.error(t);
}
} }
const h = { const h = {
youtube: { youtube: {
"get-stream": async () => { "get-stream": async () => {
const t = await m.cache.get("get-stream"); const t = await m.cache.get("get-stream");
let n; let n;
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(
if (200 !== t.status) return null; "https://youtube.com/channel/UCrPseYLGpNygVi34QpGNqpA/live"
const e = await t.text(), );
n = /(?:window\s*\[\s*["']ytInitialData["']\s*\]|ytInitialData)\s*=\s*({.+?})\s*;/.exec(e); if (200 !== t.status) return null;
if (n) { const e = await t.text(),
const t = JSON.parse(n[1]), n =
e = t.currentVideoEndpoint.watchEndpoint.videoId, /(?:window\s*\[\s*["']ytInitialData["']\s*\]|ytInitialData)\s*=\s*({.+?})\s*;/.exec(
a = t.contents.twoColumnWatchNextResults.results.results.contents[0].videoPrimaryInfoRenderer, e
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; if (n) {
return { const t = JSON.parse(n[1]),
title: a.title.runs[0].text, e = t.currentVideoEndpoint.watchEndpoint.videoId,
viewersCount: parseInt(s.replace(/,/g, "")), a =
previewImageURL: `https://i.ytimg.com/vi/${e}/mqdefault.jpg`, t.contents.twoColumnWatchNextResults.results.results
profileImageURL: o .contents[0].videoPrimaryInfoRenderer,
} o =
} t.contents.twoColumnWatchNextResults.results.results
} catch (t) { .contents[1].videoSecondaryInfoRenderer.owner
console.warn(t); .videoOwnerRenderer.thumbnail.thumbnails[0].url,
} s = a.viewCount.videoViewCountRenderer.viewCount.runs.find(
return null (t) => /^[0-9,]+$/.test(t.text)
}(), await m.cache.set("get-stream", { ).text;
expiresAt: t, return {
value: n title: a.title.runs[0].text,
}); viewersCount: parseInt(s.replace(/,/g, "")),
} previewImageURL: `https://i.ytimg.com/vi/${e}/mqdefault.jpg`,
return n profileImageURL: o,
}, };
"get-user": async t => {
const e$1 = await c(t.href),
n = await e(Object.assign(Object.assign({}, t), {
cookies: e$1
}));
if (!n.success) throw new s(n.code, n.message);
return n.data
} }
}, } catch (t) {
gateway: { console.warn(t);
users: l("/gateway/users"), }
emotes: l("/gateway/emotes"), return null;
badges: l("/gateway/badges"), })()),
"set-settings": async t => { await m.cache.set("get-stream", {
const n = await m.auth.get("token"), expiresAt: t,
o = await fetch("https://v2.mogultv.org/gateway/settings", { value: n,
method: "PUT", });
headers: { }
Authorization: `Bearer ${n}` return n;
},
body: JSON.stringify(t)
}),
{
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 => {
await s$1.tabs.create({
url: t
});
}
},
spore: {
"fetch-extension-mappings": async t => await d("youtube", t)
}
}, },
w = async (e, n$1) => { "get-user": async (t) => {
var a; const e$1 = await c(t.href),
const { n = await e(
path: o, Object.assign(Object.assign({}, t), {
body: s cookies: e$1,
} = e; })
if (!o) return; );
e.meta ? e.meta.sender = n$1 : e.meta = { if (!n.success) throw new s(n.code, n.message);
sender: n$1, return n.data;
isPort: !1 },
}, e.meta.isPort || (e.meta.isPort = !1); },
const i = t => {}, gateway: {
c = o.split("/").filter(Boolean), users: l("/gateway/users"),
u = c[0]; emotes: l("/gateway/emotes"),
if (!(u in h)) { badges: l("/gateway/badges"),
return r(n.NotFound, void 0, e.nonce) "set-settings": async (t) => {
} const n = await m.auth.get("token"),
const l = h[u][c.slice(1).join("/")]; o = await fetch("https://v2.mogultv.org/gateway/settings", {
if (!l) { method: "PUT",
return r(n.NotFound, void 0, e.nonce) headers: {
} Authorization: `Bearer ${n}`,
try { },
const n$1 = ((e, n$1) => ({ body: JSON.stringify(t),
body: e, }),
meta: { { jwt: s } = await o.json();
isSuccess: !0, return m.auth.set("token", s), dt(s);
code: n.Success, },
nonce: n$1 },
} auth: u,
}))(await l(s, e.meta), e.nonce); extension: {
return i(n$1), n$1 popup: () => s$1.action.openPopup(),
} catch (n$1) { "open-tab": async (t) => {
const o = n$1; await s$1.tabs.create({
return r(null !== (a = o.code) && void 0 !== a ? a : n.Unknown, { url: t,
message: o.message });
}, e.nonce) },
} },
}; spore: {
s$1.runtime.onConnect.addListener((t => { "fetch-extension-mappings": async (t) => await d("youtube", t),
const e = t.sender; },
e && t.onMessage.addListener((async n => { };
n.meta = { const w = async (e, n$1) => {
isPort: !0 var a;
}; const { path: o, body: s } = e;
const a = await w(n, e); if (!o) return;
t.postMessage(a); e.meta
})); ? (e.meta.sender = n$1)
})), s$1.runtime.onMessage.addListener(w); : (e.meta = {
sender: n$1,
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);
}
const l = h[u][c.slice(1).join("/")];
if (!l) {
return r(n.NotFound, void 0, e.nonce);
}
try {
const n$1 = ((e, n$1) => ({
body: e,
meta: {
isSuccess: !0,
code: n.Success,
nonce: n$1,
},
}))(await l(s, e.meta), e.nonce);
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
);
}
};
s$1.runtime.onConnect.addListener((t) => {
const e = t.sender;
e &&
t.onMessage.addListener(async (n) => {
n.meta = {
isPort: !0,
};
const a = await w(n, e);
t.postMessage(a);
});
}),
s$1.runtime.onMessage.addListener(w);

View File

@ -904,64 +904,74 @@ 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
? t const r =
: null === (n = null == s ? void 0 : s.contentWindow) || null !== (t = null == query ? void 0 : query.contentDocument) &&
void 0 === n void 0 !== t
? void 0 ? t
: n.document; : null === (n = null == query ? void 0 : query.contentWindow) ||
void 0 === n
? void 0
: n.document;
if (!r) return; if (!r) return;
return r.querySelector(e.iframeQuerySelector); return r.querySelector(e.iframeQuerySelector);
} }
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"
}