HTML/CSS/JS Obfuscation Script
This repository contains a simple Bash script to obfuscate and minify a single HTML file that contains embedded CSS and JavaScript. The script takes an index-master.html file as input and produces an index.html file as output.
Prerequisites
- Debian/Ubuntu: This script is designed to work on Debian-based systems.
- Node.js: Terser and html-minifier-terser require Node.js to be installed.
Install Node.js and npm on Debian
-
Update your package list:
sudo apt update -
Install Node.js and npm:
sudo apt install nodejs npm -y -
Verify the installation:
node -v npm -v
Install Required Tools
-
Install Terser:
npm install -g terser -
Install html-minifier-terser:
npm install -g html-minifier-terser
Script Usage
Running the Script
- Save the script as
obfuscate.sh. - Make the script executable:
chmod +x obfuscate.sh - Run the script:
./obfuscate.sh
Script Details
- Input File: The script takes
index-master.htmlas the input file. - Output File: The script outputs the obfuscated and minified version as
index.html. - Error Handling: The script checks if
index-master.htmlexists before proceeding. If the file does not exist, it will exit with an error message. - Terser and HTML-Minifier-Terser: The script first uses Terser to obfuscate any embedded JavaScript, then minifies the entire HTML file, including embedded CSS and JavaScript.
Script Example
#!/bin/bash
# Input and output file names
input_file="index-master.html"
output_file="index.html"
# Check if the input file exists
if [ ! -f "$input_file" ]; then
echo "Input file $input_file does not exist."
exit 1
fi
# Obfuscate embedded JavaScript using terser
terser_output=$(mktemp)
terser --compress --mangle -- "$input_file" > "$terser_output"
# Minify HTML, including the embedded CSS and the obfuscated JavaScript
html-minifier-terser \
--collapse-whitespace \
--minify-css true \
--minify-js true \
--remove-comments \
--remove-empty-attributes \
--output "$output_file" \
"$terser_output"
# Clean up temporary file
rm "$terser_output"
echo "Obfuscation and minification complete. Output saved as $output_file."
Editing the Script in Visual Studio Code (VSCode)
If you prefer to use Visual Studio Code to edit and run this script:
-
Install VSCode:
- Follow the official Visual Studio Code installation guide for Debian-based systems.
-
Open your project in VSCode:
code /path/to/your/project -
Edit the script by clicking on the
obfuscate.shfile in the file explorer. -
Run the script within the VSCode terminal:
- Open the terminal in VSCode:
View > Terminal. - Run the script:
./obfuscate.sh
- Open the terminal in VSCode:
Creating and Hosting a Flyer
The create_flyer.sh script automates filling config.json, building the HTML files, and copying everything into a new directory under host/.
Usage
# interactive mode
./create_flyer.sh
# use an existing filled PDF form
./create_flyer.sh --from-pdf path/to/form.pdf
By default the script updates src/config.json. After answering the prompts (or extracting from the PDF), index.html and nostr.html are generated and copied along with the QR code images and PDFs. The files end up in host/<subdomain> which can be served statically.