mirror of
https://github.com/vale981/tridactyl
synced 2025-03-05 09:31:41 -05:00
Initial attempt at userChrome editing
This commit is contained in:
parent
f640526585
commit
7b04fc455b
2 changed files with 73 additions and 0 deletions
63
native/cssfiddle.py
Executable file
63
native/cssfiddle.py
Executable file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# need to merge this into main native file
|
||||
import tinycss2
|
||||
# only want to import this if CSS fiddling is called
|
||||
|
||||
# need to figure out how to find this
|
||||
USER_PROFILE = ""
|
||||
# need to make chrome folder if it doesn't exist
|
||||
chromefile = USER_PROFILE + "/chrome/userChrome.css"
|
||||
# Should probably put in absolutely minimal css (so just namespace?) if it doesn't exist
|
||||
|
||||
cssString = ""
|
||||
with open(chromefile, "r") as file:
|
||||
cssString = file.read()
|
||||
|
||||
RULES = tinycss2.parse_stylesheet(cssString)
|
||||
|
||||
# Get the relevant rules
|
||||
def getrules(filt):
|
||||
return [(i,RULES[i]) for (i,r) in enumerate(RULES) if (
|
||||
isinstance(r,tinycss2.ast.QualifiedRule)
|
||||
and filt == tinycss2.serialize(r.prelude)
|
||||
# Consider swapping this for in? don't want to care about e.g. " or '
|
||||
)]
|
||||
|
||||
# Can we potentially store this in JS? Otherwise it will be very hard to document.
|
||||
# Also, what do we do about meta rules that include other rules, e.g gui=none?
|
||||
potentialRules = {
|
||||
"hoverlink": {
|
||||
"name": """statuspanel[type="overLink"]""",
|
||||
"options": {
|
||||
"none": """display: none !important;""",
|
||||
"right": """right: 0; display: inline;""",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def changerule(rulename,optionname):
|
||||
try:
|
||||
RULES[
|
||||
getrules(potential_rules[rulename]["name"])[1][0]
|
||||
].content = tinycss2.parse_component_value_list(
|
||||
potential_rules[rulename]["options"][optionname]
|
||||
)
|
||||
# If we can't find the rule we want, make a new one
|
||||
except IndexError:
|
||||
RULES.append(
|
||||
tinycss2.parse_one_rule(
|
||||
potential_rules[rulename]["name"] + "{" + potential_rules[rulename]["options"][optionname] + "}"
|
||||
)
|
||||
)
|
||||
|
||||
# Change the rules they asked for
|
||||
# changerule("hoverlink","right")
|
||||
|
||||
# Make a backup
|
||||
with open(chromefile + ".tri.bak", "w") as file:
|
||||
file.write(cssString)
|
||||
|
||||
# Write the CSS file
|
||||
with open(chromefile,"w") as file:
|
||||
file.write(tinycss2.serialize(RULES))
|
|
@ -38,3 +38,13 @@ native_file_escaped=$(sed 's/[&/\]/\\&/g' <<< "$native_file")
|
|||
|
||||
sed -i.bak "s/REPLACE_ME_WITH_SED/$native_file_escaped/" "$manifest_file"
|
||||
chmod +x $native_file
|
||||
|
||||
# Requirements for native messenger
|
||||
python_path=$(which python3)
|
||||
pip_path=$(which pip3)
|
||||
if [[ -x "$python_path" ]] && [[ -x "$pip_path" ]]; then
|
||||
pip3 install --user tinycss2
|
||||
else
|
||||
echo "Error: Python 3 and pip3 must exist in PATH."
|
||||
echo "Please install them and run this script again."
|
||||
fi
|
||||
|
|
Loading…
Add table
Reference in a new issue