Normalize line endings to LF

main
Amēlija I 2024-12-17 22:30:58 +02:00
commit 8d878a1592
7 changed files with 9663 additions and 0 deletions

7
.gitattributes vendored 100644
View File

@ -0,0 +1,7 @@
* text=auto eol=lf
*.bat text eol=crlf
*.sh text eol=lf
*.json text eol=lf
*.yaml text eol=lf
*.md text eol=lf

30
.gitignore vendored 100644
View File

@ -0,0 +1,30 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
node_modules
# testing
coverage
# production
dist
# misc
.DS_Store
# config
config.json
# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local
# debug files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# extension.js
extension-env.d.ts

35
README.md 100644
View File

@ -0,0 +1,35 @@
# my-extension
> A minimum extension template. This template includes a manifest file.
## Available Scripts
In the project directory, you can run the following scripts:
### npm dev
**Development Mode**: This command runs your extension in development mode. It will launch a new browser instance with your extension loaded. The page will automatically reload whenever you make changes to your code, allowing for a smooth development experience.
```bash
npm dev
```
### npm start
**Production Preview**: This command runs your extension in production mode. It will launch a new browser instance with your extension loaded, simulating the environment and behavior of your extension as it will appear once published.
```bash
npm start
```
### npm build
**Build for Production**: This command builds your extension for production. It optimizes and bundles your extension, preparing it for deployment to the target browser's store.
```bash
npm build
```
## Learn More
To learn more about creating cross-browser extensions with Extension.js, visit the [official documentation](https://extension.js.org).

26
manifest.json 100644
View File

@ -0,0 +1,26 @@
{
"manifest_version": 3,
"version": "1.0",
"name": "my-extension",
"description": "A minimum extension template. This template includes a manifest file.",
"author": "Your Name",
"permissions": [
"storage"
],
"host_permissions": [
"http://localhost:5000/*"
],
"content_security_policy": {
"extension_pages": "script-src 'self'; object-src 'self'; connect-src 'self' http://localhost:5000"
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["src/borderify.js"]
}
]
}

9403
package-lock.json generated 100644

File diff suppressed because it is too large Load Diff

35
package.json 100644
View File

@ -0,0 +1,35 @@
{
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/extension-js/extension.git",
"directory": "examples/init"
},
"name": "my-extension",
"description": "An Extension.js example.",
"version": "0.0.1",
"keywords": [
"extension",
"browser-extension",
"web-extension",
"template"
],
"scripts": {
"dev": "extension dev",
"start": "extension start",
"build": "extension build"
},
"dependencies": {
"dotenv": "^16.4.5",
"mongodb": "^6.9.0"
},
"devDependencies": {
"extension": "latest"
},
"private": true,
"author": {
"name": "Your Name",
"email": "your@email.com",
"url": "https://yourwebsite.com"
}
}

127
src/borderify.js 100644
View File

@ -0,0 +1,127 @@
let serverUrl = "http://localhost:5000/submit";
fetch(browser.runtime.getURL("config.json"))
.then(response => {
if (!response.ok) {
throw new Error(`Ошибка загрузки config.json: ${response.statusText}`);
}
return response.json();
})
.then(config => {
serverUrl = config.FLASK_SERVER_URL;
console.log("URL сервера успешно загружен:", serverUrl);
})
.catch(error => console.error("Ошибка загрузки конфигурации:", error));
function createEventJSON(eventType, data) {
const timeStamp = new Date().toISOString();
return {
"@version": 1,
"type": `browserext.${eventType}`,
"TimeStamp": timeStamp,
"data": data,
"@timestamp": timeStamp
};
}
async function sendDataToServer(eventData) {
try {
const response = await fetch(serverUrl, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(eventData),
});
const responseData = await response.json();
if (response.ok) {
console.log("Данные успешно отправлены на сервер:", responseData);
} else {
console.error("Ошибка при отправке данных на сервер:", response.status, responseData);
}
} catch (error) {
console.error("Ошибка подключения к серверу:", error);
}
}
document.addEventListener("keydown", (event) => {
const key = event.key;
const code = event.code;
let description;
if (key.match(/^\p{Number}$/u)) {
description = "number";
} else if (key.match(/^\p{Letter}$/u)) {
description = "letter";
} else if (key.match(/^\p{Punctuation}$|^\p{Symbol}$/u)) {
description = "symbol";
} else {
description = `Клавиша: ${key} Код: ${code}`;
}
const eventData = createEventJSON('keydown', { description });
console.log("Событие keydown:", JSON.stringify(eventData));
sendDataToServer(eventData);
});
document.addEventListener("mousedown", (event) => {
const eventData = createEventJSON('mousedown', { button: event.button, description: `Клик мышью: ${event.button}` });
console.log("Событие mousedown:", JSON.stringify(eventData));
sendDataToServer(eventData);
});
document.addEventListener("click", (event) => {
const eventType = 'click';
const clickedElement = event.target;
const tag = clickedElement.tagName;
const id = clickedElement.id || "отсутствует";
const className = clickedElement.className || "отсутствует";
let description = "Клик по элементу";
let data = { tag, id, className };
if (tag === 'A') {
const href = clickedElement.href;
data.href = href;
description = "Клик по ссылке";
localStorage.setItem('clickedElementInfo', JSON.stringify(data));
navigateWithPromise(href);
} else if (tag === 'INPUT') {
const placeholder = clickedElement.placeholder || "отсутствует";
data.placeholder = placeholder;
description = "Клик по полю ввода";
}
data.description = description;
const eventData = createEventJSON(eventType, data);
console.log("Событие click:", JSON.stringify(eventData));
sendDataToServer(eventData);
});
function navigateWithPromise(href) {
return new Promise((resolve) => {
window.location.href = href;
window.addEventListener('load', resolve);
});
}
document.addEventListener("copy", (event) => {
const selectedText = window.getSelection().toString();
const pageUrl = window.location.href;
let outputText = selectedText.length > 50 ? selectedText.substring(0, 49) + '…' : selectedText;
if (selectedText.length > 0) {
const eventData = createEventJSON('copy', { selectedText: outputText, pageUrl, description: "Скопирован текст" });
console.log("Событие copy:", JSON.stringify(eventData));
sendDataToServer(eventData);
}
});