Skip to content

Commit

Permalink
fix more things
Browse files Browse the repository at this point in the history
  • Loading branch information
RoootTheFox committed May 24, 2022
1 parent 3022b88 commit 3f58a51
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
2 changes: 1 addition & 1 deletion discord-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os

def response(flow: http.HTTPFlow):
flow.response.headers["content-security-policy"] = "default-src * 'unsafe-inline' 'unsafe-eval'; img-src * blob: data:; media-src * blob: data:"
flow.response.headers["content-security-policy"] = "default-src * 'unsafe-inline' 'unsafe-eval' data:; img-src * blob: data:; media-src * blob: data:"
flow.response.headers["access-control-allow-origin"] = "*"
if "content-type" in flow.response.headers:
if flow.response.headers["content-type"] == "text/html" and (flow.request.pretty_url.startswith("https://discord.com/app") or flow.request.pretty_url.startswith("https://discord.com/channels")):
Expand Down
41 changes: 9 additions & 32 deletions loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function loadTheme(url) {

themeName = _escapeID(themeName);

// TODO: check what betterdiscord specific things exist
addTheme(themeName, data_string, url);
});
}
Expand All @@ -80,43 +79,18 @@ async function getEnabledThemes() {

async function addTheme(name, css, url) {
var theme = css;
if ( /*data.toString().contains("bd-")*/ true) {
if (data.toString().contains("bd-")) {
console.log("* Patching theme");

// todo - add theme patching code here (if needed)

console.log("* Injecting theme");

_injectTheme(name, theme);
} else {
console.log("* Injecting theme");
let theme = document.createElement("link");
theme.rel = "stylesheet";
theme.href = url;
document.head.append(theme);
// TODO: check what betterdiscord specific things exist
// and add theme patching code here (if needed)
}

console.log("adding to cookie");
var themes = await getThemes();
var found = false;
for (var i = 0; i < themes.length; i++) {
if (themes[i].name == name) {
console.log("found")
found = true;
themes[i].enabled = true;
themes[i].url = url;
}
}
console.log("* Injecting theme");

if (!found) {
console.log("not found, adding to themes array");
themes.push({
name: name,
enabled: true,
url: url
});
}
_injectTheme(name, theme);

console.log("adding to storage");
fetch('https://discord.com/themeldr/modifytheme', {
method: 'POST',
headers: {
Expand All @@ -136,7 +110,9 @@ async function addTheme(name, css, url) {
async function disableTheme(name) {
var themes = await getThemes();
for (var i = 0; i < themes.length; i++) {
var found = false;
if (themes[i].name == name) {
found = true;
themes[i].enabled = false;
var response = await fetch('https://discord.com/themeldr/modifytheme', {
method: 'POST',
Expand All @@ -158,6 +134,7 @@ async function disableTheme(name) {
}
}
}
if(!found) console.log("There is no theme named '" + name + "'.");
}

console.log("Functions loaded. Use loadTheme(\"url\") to load a theme and clearTheme() or CTRL-R to unload.");
Expand Down

0 comments on commit 3f58a51

Please sign in to comment.