URL fix? #10
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .gituhb \ workflows \ obfuscate.yml | |
name: Obfuscate and Push to Main | |
on: | |
push: | |
branches: [dev] | |
paths: ['*.html', '*.js', '*.css'] | |
jobs: | |
obfuscate-to-main: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
token: ${{ secrets.PAT }} | |
ref: dev | |
fetch-depth: 0 | |
- uses: actions/setup-node@v3 | |
with: | |
node-version: '18' | |
- name: Install dependencies | |
run: npm install html-minifier-terser javascript-obfuscator --save-dev | |
- name: Process Files | |
run: | | |
node -e ' | |
const fs = require("fs"); | |
const minify = require("html-minifier-terser").minify; | |
const JavaScriptObfuscator = require("javascript-obfuscator"); | |
async function processHtml() { | |
if (!fs.existsSync("index.html")) { | |
console.log("index.html not found"); | |
return; | |
} | |
try { | |
let html = fs.readFileSync("index.html", "utf8"); | |
// Preserve SEO and Schema markup | |
const seoPattern = /(<script type="application\/ld\+json">[\s\S]*?<\/script>|<!--\s*SEO:[\s\S]*?-->)/gi; | |
const seoElements = []; | |
html = html.replace(seoPattern, (match) => { | |
seoElements.push(match); | |
return `###SEO${seoElements.length - 1}###`; | |
}); | |
// Obfuscate scripts | |
html = html.replace(/<script>([\s\S]*?)<\/script>/g, (match, script) => { | |
if (!script.trim()) return match; | |
const obfuscated = JavaScriptObfuscator.obfuscate(script, { | |
compact: true, | |
controlFlowFlattening: true, | |
controlFlowFlatteningThreshold: 0.75, | |
deadCodeInjection: true, | |
deadCodeInjectionThreshold: 0.4, | |
debugProtection: true, | |
debugProtectionInterval: 2000, | |
identifierNamesGenerator: "hexadecimal", | |
numbersToExpressions: true, | |
rotateStringArray: true, | |
selfDefending: true, | |
splitStrings: true, | |
stringArray: true, | |
stringArrayEncoding: ["base64"], | |
stringArrayThreshold: 0.75, | |
transformObjectKeys: true | |
}); | |
return `<script>${obfuscated.getObfuscatedCode()}</script>`; | |
}); | |
// Add security | |
const security = ` | |
<script> | |
(() => { | |
let d = false; | |
const check = () => { | |
const w = window.outerWidth - window.innerWidth > 160; | |
const h = window.outerHeight - window.innerHeight > 160; | |
if (w || h !== d) { | |
d = w || h; | |
if (d) document.body.innerHTML = ""; | |
} | |
}; | |
setInterval(check, 1000); | |
check(); | |
})(); | |
</script> | |
`; | |
// Minify | |
const minified = await minify(security + html, { | |
collapseWhitespace: true, | |
removeComments: false, | |
minifyJS: false, | |
minifyCSS: true, | |
minifyURLs: true, | |
removeAttributeQuotes: false, | |
removeEmptyAttributes: false, | |
removeRedundantAttributes: false, | |
removeScriptTypeAttributes: true, | |
removeStyleLinkTypeAttributes: true, | |
preserveLineBreaks: false | |
}); | |
// Restore SEO elements | |
const finalHtml = minified.replace(/###SEO(\d+)###/g, (_, index) => seoElements[index]); | |
fs.writeFileSync("index.html", finalHtml); | |
console.log("Processing complete"); | |
} catch (error) { | |
console.error("Error:", error); | |
process.exit(1); | |
} | |
} | |
processHtml(); | |
' | |
- name: Deploy to main | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add . | |
git commit -m "Deploy obfuscated version from dev" || echo "No changes to commit" | |
git push -f origin HEAD:main |