Skip to content

Instantly share code, notes, and snippets.

@D-Brox
Last active February 13, 2024 17:18
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save D-Brox/8cfc8a8a11bd8f9034f6892274afb1c7 to your computer and use it in GitHub Desktop.
Save D-Brox/8cfc8a8a11bd8f9034f6892274afb1c7 to your computer and use it in GitHub Desktop.
Replace classes for all .scss or .css themes
import os
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
default_path = True
if default_path:
powercord_path = os.path.join(os.path.expanduser('~'),"powercord")
else:
powercord_path = "" # replace with custom powercord folder location
themes_path = os.path.join(powercord_path,"src","Powercord","themes") # you can change this if you want to run in other places
path_list = glob.glob(f"{themes_path}/**/*.*css",recursive=True)
with urlopen("https://gist.githubusercontent.com/D-Brox/5ea0d9cec29c4921a9e397163f447646/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
if "@import url" in css:
remote_imports.append(file_path)
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"{powercord_path}/src/Powercord/plugins/pc-moduleManager/quickcss.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(themes_path+"/","")) for i in remote_imports]
@D-Brox
Copy link
Author

D-Brox commented Jan 9, 2022

If a theme doesn't work after patching, check if it uses a remote file, something like this:

@import url("https://github.com/user/repo/raw/master/filename.scss");

If it does, download the file, change the extentions to scss, and change the export to something like:

@import "./filename.scss"

@PhoenixAceVFX
Copy link

you absolute MADLAD!
Oh also you should of noted that the script need to do pip install tqdm if it errors about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment