-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Вклад в PoliObfusKlot | ||
|
||
Спасибо за интерес к проекту PoliObfusKlot! Мы рады любому вкладу от сообщества. Это руководство поможет вам разобраться, как правильно сделать это. | ||
|
||
## Процесс внесения изменений: | ||
|
||
1. **Создайте форк проекта.** | ||
|
||
- Нажмите кнопку "Fork" в верхнем правом углу репозитория на GitHub. | ||
|
||
2. **Клонируйте репозиторий на свою машину.** | ||
|
||
```bash | ||
git clone https://github.com/[Ваш_пользователь]/PoliObfusKlot.git | ||
``` | ||
|
||
3. **Создайте новую ветку.** | ||
|
||
Переходите в каталог вашего репозитория и выполните: | ||
|
||
```bash | ||
git checkout -b имя-новой-ветки | ||
``` | ||
|
||
4. **Внесите свои изменения.** | ||
|
||
Внесите необходимые изменения в код и убедитесь, что они работают. | ||
|
||
5. **Commit и push ваши изменения.** | ||
```bash | ||
git commit -am "Описание внесенных изменений" | ||
git push origin имя-новой-ветки | ||
``` | ||
|
||
6. **Создайте pull request.** | ||
|
||
Перейдите в ваш форк на GitHub и нажмите кнопку "New Pull Request". | ||
|
||
|
||
## Рекомендации по стилю кода: | ||
|
||
- Следуйте общепринятым стандартам стиля кода для языка, который вы используете. | ||
- Оставляйте комментарии, где это необходимо. | ||
- Пишите чистый и понятный код. | ||
|
||
## Сообщения о багах: | ||
|
||
Если вы нашли ошибку, прежде чем создать issue, пожалуйста: | ||
- Проверьте актуальный список issues, чтобы убедиться, что проблема не была уже отмечена. | ||
- Укажите версию вашего ПО и шаги для воспроизведения проблемы. | ||
|
||
## Идеи и предложения: | ||
|
||
Мы всегда рады новым идеям. Если у вас есть предложения по улучшению, создайте issue с меткой "enhancement" или "feature request". | ||
|
||
## Благодарим за ваш вклад! |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# PoliObfusKlot | ||
|
||
[![version](https://img.shields.io/badge/version-0.0.1-brightgreen)](https://github.com/Poliklot/PoliObfusKlot/releases/tag/v0.0.1) | ||
[![license](https://img.shields.io/badge/license-MIT-blue)](https://github.com/Poliklot/PoliObfusKlot/blob/main/LICENSE) | ||
|
||
**PoliObfusKlot** — это инструмент для обфускации CSS-классов, предоставляющий простой и эффективный способ скрыть исходные имена классов в вашем проекте. | ||
|
||
## Особенности | ||
|
||
- 🚀 Быстрая обфускация CSS-классов. | ||
- 📜 Создание карты соответствия между оригинальными и обфусцированными классами. | ||
- 🔄 Автоматическое обновление HTML и JS файлов с новыми именами классов. | ||
|
||
## Установка | ||
|
||
```bash | ||
npm install PoliObfusKlot | ||
``` | ||
|
||
## Использование | ||
|
||
Для запуска процесса обфускации выполните команду: | ||
|
||
```bash | ||
npm run obfuscate | ||
``` | ||
|
||
## Вклад | ||
|
||
Если вы хотите внести свой вклад в проект, ознакомьтесь с [руководством по участию](https://github.com/Poliklot/PoliObfusKlot/blob/main/CONTRIBUTING.md). | ||
|
||
## Лицензия | ||
|
||
PoliObfusKlot распространяется под лицензией MIT. Детали можно прочитать в файле [LICENSE](https://github.com/Poliklot/PoliObfusKlot/blob/main/LICENSE). | ||
|
||
Разработано с ❤️ by [Poliklot](https://github.com/Poliklot). |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const postcss = require('postcss'); | ||
const crypto = require('crypto'); | ||
|
||
const cssFilePath = path.resolve(__dirname, 'dist/assets/css/style.f17018e9.css'); | ||
const css = fs.readFileSync(cssFilePath, 'utf-8'); | ||
|
||
const obfuscatedClassNames = {}; | ||
|
||
const generateObfuscatedName = (originalName) => { | ||
const hash = crypto.createHash('md5').update(originalName).digest('hex').substring(0, 4); | ||
return `o_${hash}`; | ||
} | ||
|
||
const root = postcss.parse(css); | ||
|
||
root.walkRules(rule => { | ||
rule.selectors = rule.selectors.map(selector => { | ||
// Мы используем регулярное выражение для поиска всех классов в селекторе | ||
return selector.replace(/\.([a-zA-Z0-9-_]+)/g, (match, className) => { | ||
if (!obfuscatedClassNames[className]) { | ||
obfuscatedClassNames[className] = generateObfuscatedName(className); | ||
} | ||
return '.' + obfuscatedClassNames[className]; | ||
}); | ||
}); | ||
}); | ||
|
||
fs.writeFileSync(cssFilePath, root.toString()); | ||
fs.writeFileSync('./classMappings.json', JSON.stringify(obfuscatedClassNames, null, 2)); | ||
|
||
console.log('Обфускация завершена!'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "poliobfusklot", | ||
"version": "0.0.1", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Poliklot/PoliObfusKlot.git" | ||
}, | ||
"author": "Poliklot", | ||
"license": "MIT", | ||
"scripts": { | ||
"obfuscate": "node obfuscateCSS.js && node updateHTML.js && node updateJS.js" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// updateHTML.js | ||
const path = require('path'); | ||
const fs = require('fs'); | ||
const cheerio = require('cheerio'); | ||
|
||
const mappings = require('./classMappings.json'); | ||
const htmlFilePath = path.resolve(__dirname, 'dist/index.html'); | ||
const html = fs.readFileSync(htmlFilePath, 'utf-8'); | ||
const $ = cheerio.load(html); | ||
|
||
Object.keys(mappings).forEach((originalClassName) => { | ||
$(`.${originalClassName}`).removeClass(originalClassName).addClass(mappings[originalClassName]); | ||
}); | ||
|
||
fs.writeFileSync(htmlFilePath, $.html()); // перезаписываем исходный HTML файл |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// updateJS.js | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const mappings = require('./classMappings.json'); | ||
|
||
const scriptsFolderPath = path.resolve(__dirname, 'dist/assets/scripts'); | ||
const filesToExclude = ["example1.js", "example2.js"]; // список файлов для исключения | ||
|
||
// Получаем список всех файлов в папке | ||
const files = fs.readdirSync(scriptsFolderPath); | ||
|
||
// Фильтруем список файлов, исключая нежелательные | ||
const filesToProcess = files.filter(file => !filesToExclude.includes(file)); | ||
|
||
filesToProcess.forEach(file => { | ||
const jsFilePath = path.join(scriptsFolderPath, file); | ||
const jsContent = fs.readFileSync(jsFilePath, 'utf-8'); | ||
|
||
let updatedContent = jsContent; | ||
Object.keys(mappings).forEach((originalClassName) => { | ||
const singleQuoteRegex = new RegExp(`'${originalClassName}'`, 'g'); | ||
const doubleQuoteRegex = new RegExp(`"${originalClassName}"`, 'g'); | ||
const noQuotesRegex = new RegExp(`\\.${originalClassName}\\b`, 'g'); | ||
|
||
updatedContent = updatedContent.replace(singleQuoteRegex, `'${mappings[originalClassName]}'`); | ||
updatedContent = updatedContent.replace(doubleQuoteRegex, `"${mappings[originalClassName]}"`); | ||
updatedContent = updatedContent.replace(noQuotesRegex, `.${mappings[originalClassName]}`); | ||
}); | ||
|
||
fs.writeFileSync(jsFilePath, updatedContent); | ||
}); |