Skip to content

Instantly share code, notes, and snippets.

@SmolAlli
Forked from D-Brox/canary-broke-themes-again.py
Last active January 11, 2022 05:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SmolAlli/14edd46fc691066db717ce1dba1dcbb3 to your computer and use it in GitHub Desktop.
Save SmolAlli/14edd46fc691066db717ce1dba1dcbb3 to your computer and use it in GitHub Desktop.
Replace classes for all .css themes **BetterDiscord version**
# Original by D-Brox for Powercord. Repurposed for use with BetterDiscord.
import glob
from tqdm import tqdm
from pathlib import Path
from urllib.request import urlopen
import shutil
keep_old = True
use_old = True
fix_quickcss = True
betterdiscord_path = f"" # betterdiscord folder location (ex: "/home/username/betterdiscord")
# PLEASE DO NOT USE \ IN YOUR FOLDER LOCATION PATHS, IT WILL NOT WORK.
path = f"{betterdiscord_path}/themes" # you can change it if you want to run in other places
path_list = glob.glob(f"{path}/*.*css",recursive=True)
with urlopen("https://gist.githubusercontent.com/Davr1/a768191cb50171bfd56cb7c65d0a2e68/raw/classes2.txt") as f:
raw_classes = f.read().decode("utf8").split("\n")
classes = [i.split(" = ") for i in raw_classes]
remote_imports = []
def replace_classes(file_path):
if use_old and Path(file_path+".old").is_file():
css_path = file_path+".old"
else:
css_path = file_path
if keep_old and not Path(file_path+".old").is_file():
shutil.copy(file_path, file_path+".old")
try:
with open(css_path,"r",encoding="utf8") as f:
css = f.read()
except:
print("Unable to read "+ file_path.split("/").split("\\")[-1]+" due to codec issues")
return
for class_pair in classes:
css = css.replace(class_pair[0],class_pair[1])
with open(file_path,"w",encoding="utf8") as f:
f.write(css)
for file_path in tqdm(path_list):
replace_classes(file_path)
quickcss_path = f"{betterdiscord_path}/data/stable/custom.css"
if fix_quickcss and Path(quickcss_path).is_file():
replace_classes(quickcss_path)
if remote_imports:
print("This is script is unable to fix css from remote imports")
print("The following files contain remote imports:")
[print(i.replace(path+"/","")) for i in remote_imports]
# BEFORE RUNNING, PLEASE MAKE SURE THAT YOU HAVE DONE pip install tqdm BEFORE RUNNING. YOU NEED IT INSTALLED TO HAVE THIS WORK.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment