Add: VK bot support (#19)
Co-authored-by: Maksim <maksim@MBP-Maksim.lan>
This commit is contained in:
1 parent
84da73c324
commit
2ce446f74c
8 files changed
+501
-8
No files matched your search
@@ -0,0 +1,122 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
class BotManager {
|
||||
constructor(settings, onCreateTab) {
|
||||
this.settings = settings;
|
||||
this.onCreateTab = onCreateTab;
|
||||
this.baseUrl = 'https://api.vk.com/method';
|
||||
this.ts = null;
|
||||
this.key = null;
|
||||
this.server = null;
|
||||
this.running = false;
|
||||
}
|
||||
async api(method, params = {}) {
|
||||
params.v = '5.131';
|
||||
params.access_token = this.settings.token;
|
||||
const url = new URL(`${this.baseUrl}/${method}`);
|
||||
Object.keys(params).forEach(k => url.searchParams.set(k, params[k]));
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.error) {
|
||||
throw new Error(data.error.error_msg || 'VK API error');
|
||||
}
|
||||
return data.response;
|
||||
}
|
||||
|
||||
async getLongPollServer() {
|
||||
const data = await this.api('groups.getLongPollServer', { group_id: parseInt(this.settings.groupId) });
|
||||
this.server = data.server;
|
||||
this.key = data.key;
|
||||
this.ts = data.ts;
|
||||
return data;
|
||||
}
|
||||
|
||||
async start() {
|
||||
this.running = true;
|
||||
console.log('[BOT] Starting with settings:', this.settings);
|
||||
|
||||
try {
|
||||
await this.getLongPollServer();
|
||||
console.log('[BOT] LongPoll server:', this.server);
|
||||
this.pollLoop();
|
||||
} catch (err) {
|
||||
console.error('[BOT] Failed to start:', err.message);
|
||||
}
|
||||
}
|
||||
|
||||
stop() {
|
||||
this.running = false;
|
||||
console.log('[BOT] Stopped');
|
||||
}
|
||||
|
||||
async pollLoop() {
|
||||
while (this.running) {
|
||||
try {
|
||||
const url = `${this.server}?act=a_check&key=${this.key}&ts=${this.ts}&wait=25`;
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
|
||||
if (data.failed) {
|
||||
console.log('[BOT] LongPoll failed, reconnecting...');
|
||||
await this.getLongPollServer();
|
||||
continue;
|
||||
}
|
||||
this.ts = data.ts;
|
||||
for (const update of data.updates) {
|
||||
await this.handleUpdate(update);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('[BOT] Poll error:', err.message);
|
||||
await new Promise(r => setTimeout(r, 1000));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async handleUpdate(update) {
|
||||
if (update.type === 'message_new') {
|
||||
const message = update.object.message;
|
||||
const text = message.text || '';
|
||||
const fromId = message.from_id;
|
||||
const peerId = message.peer_id;
|
||||
|
||||
if (this.settings.userId && fromId.toString() !== this.settings.userId.toString()) {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[BOT] Message from', fromId, ':', text);
|
||||
|
||||
if (text.startsWith('/vk')) {
|
||||
const mode = text.includes('video') ? 'pion-video' : 'dc';
|
||||
console.log('[BOT] Creating VK tab with mode:', mode);
|
||||
|
||||
this.onCreateTab({ mode: mode, peerId: peerId, platform: 'vk' });
|
||||
await this.sendMessage(peerId, 'Creating VK call (' + (mode === 'dc' ? 'DC' : 'Video') + ')...');
|
||||
}
|
||||
|
||||
if (text.startsWith('/tm')) {
|
||||
const mode = text.includes('video') ? 'pion-video' : 'dc';
|
||||
console.log('[BOT] Creating Telemost tab with mode:', mode);
|
||||
|
||||
this.onCreateTab({ mode: mode, peerId: peerId, platform: 'telemost' });
|
||||
|
||||
await this.sendMessage(peerId, 'Creating Telemost call (' + (mode === 'dc' ? 'DC' : 'Video') + ')...');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async sendMessage(peerId, text) {
|
||||
try {
|
||||
await this.api('messages.send', {
|
||||
peer_id: peerId,
|
||||
message: text,
|
||||
random_id: Math.floor(Math.random() * 1e9)
|
||||
});
|
||||
console.log('[BOT] Sent message to', peerId);
|
||||
} catch (err) {
|
||||
console.error('[BOT] Send message error:', err.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = BotManager;
|
||||
+123
-3
@@ -4,13 +4,20 @@
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { font-family: -apple-system, sans-serif; background: #1a1a1a; color: #e0e0e0; height: 100vh; display: flex; flex-direction: column; }
|
||||
.tab-bar { display: flex; align-items: center; background: #222; border-bottom: 1px solid #333; height: 36px; flex-shrink: 0; overflow-x: auto; }
|
||||
.tab-bar { display: flex; align-items: center; background: #222; border-bottom: 1px solid #333; height: 36px; flex-shrink: 0; }
|
||||
.tab-bar-tabs { display: flex; align-items: center; height: 100%; flex: 1; overflow-x: auto; }
|
||||
.tab-bar-actions { display: flex; align-items: center; height: 100%; border-left: 1px solid #333; }
|
||||
.tab { display: flex; align-items: center; gap: 6px; padding: 0 12px; height: 100%; font-size: 12px; cursor: pointer; border-right: 1px solid #333; white-space: nowrap; color: #888; }
|
||||
.tab.active { background: #1a1a1a; color: #e0e0e0; }
|
||||
.tab .close { font-size: 14px; opacity: 0.5; cursor: pointer; margin-left: 4px; }
|
||||
.tab .close:hover { opacity: 1; }
|
||||
.tab-add { padding: 0 12px; height: 100%; display: flex; align-items: center; font-size: 16px; cursor: pointer; color: #888; }
|
||||
.tab-add:hover { color: #e0e0e0; }
|
||||
.tab-settings { padding: 0 12px; height: 100%; display: flex; align-items: center; font-size: 14px; cursor: pointer; color: #888; }
|
||||
.tab-settings:hover { color: #e0e0e0; }
|
||||
.tab-bot { padding: 0 12px; height: 100%; display: flex; align-items: center; font-size: 12px; cursor: pointer; color: #888; font-weight: 500; }
|
||||
.tab-bot:hover { color: #e0e0e0; }
|
||||
.tab-bot.running { color: #dc3545; }
|
||||
.toolbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: #252525; border-bottom: 1px solid #333; height: 36px; flex-shrink: 0; }
|
||||
.toolbar button { padding: 3px 12px; border: none; border-radius: 6px; font-size: 12px; cursor: pointer; font-weight: 500; }
|
||||
.btn-vk { background: #0077ff; color: white; }
|
||||
@@ -28,11 +35,32 @@ body { font-family: -apple-system, sans-serif; background: #1a1a1a; color: #e0e0
|
||||
.log-content { flex: 1; overflow-y: auto; padding: 3px 8px; font-family: monospace; font-size: 10px; background: #111; white-space: pre-wrap; word-break: break-all; }
|
||||
.log-content.relay { color: #4fc3f7; }
|
||||
.log-content.hook { color: #66bb6a; }
|
||||
|
||||
/* Settings Popup */
|
||||
.popup-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); z-index: 1000; display: none; align-items: center; justify-content: center; }
|
||||
.popup-overlay.visible { display: flex; }
|
||||
.popup { background: #2a2a2a; border-radius: 12px; padding: 24px; width: 400px; box-shadow: 0 8px 32px rgba(0,0,0,0.4); }
|
||||
.popup h2 { margin: 0 0 20px; font-size: 18px; font-weight: 600; color: #e0e0e0; }
|
||||
.popup label { display: block; margin-bottom: 6px; font-size: 12px; color: #888; font-weight: 500; }
|
||||
.popup input { width: 100%; padding: 10px 12px; border: 1px solid #444; border-radius: 8px; font-size: 14px; background: #1a1a1a; color: #e0e0e0; outline: none; margin-bottom: 16px; box-sizing: border-box; }
|
||||
.popup input:focus { border-color: #0077ff; }
|
||||
.popup-buttons { display: flex; gap: 8px; justify-content: flex-end; }
|
||||
.popup button { padding: 8px 16px; border: none; border-radius: 8px; font-size: 13px; cursor: pointer; font-weight: 500; }
|
||||
.btn-save { background: #0077ff; color: white; }
|
||||
.btn-cancel { background: #444; color: #e0e0e0; }
|
||||
.btn-bot { background: #6f42c1; color: white; }
|
||||
.btn-bot.running { background: #dc3545; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="tab-bar" id="tabBar">
|
||||
<div class="tab-add" onclick="addTab()" title="New tab">+</div>
|
||||
<div class="tab-bar">
|
||||
<div class="tab-bar-tabs" id="tabBar">
|
||||
<div class="tab-add" onclick="addTab()" title="New tab">+</div>
|
||||
</div>
|
||||
<div class="tab-bar-actions">
|
||||
<div class="tab-settings" onclick="openSettings()" title="Settings">Settings</div>
|
||||
<div class="tab-bot" id="tabBot" onclick="toggleBot()">Bot: Off</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="toolbar" id="toolbar" style="display:none">
|
||||
<button class="btn-vk" onclick="loadURL('https://vk.com/im')">VK</button>
|
||||
@@ -60,10 +88,69 @@ body { font-family: -apple-system, sans-serif; background: #1a1a1a; color: #e0e0
|
||||
<div class="log-content hook" id="hookLog"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Settings Popup -->
|
||||
<div class="popup-overlay" id="settingsPopup">
|
||||
<div class="popup">
|
||||
<h2>VK bot settings</h2>
|
||||
<label for="vkToken">Token</label>
|
||||
<input type="text" id="vkToken" placeholder="vk1.a.xxx...">
|
||||
<label for="vkGroupId">Group ID</label>
|
||||
<input type="number" id="vkGroupId" placeholder="123456789">
|
||||
<label for="vkUserId">User ID</label>
|
||||
<input type="number" id="vkUserId" placeholder="123456789">
|
||||
<div class="popup-buttons">
|
||||
<button class="btn-cancel" onclick="closeSettings()">Cancel</button>
|
||||
<button class="btn-save" onclick="saveSettings()">Save</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
var tabsState = {}; // tabId -> { wv, mode, relayLogs, hookLogs }
|
||||
var activeTabId = null;
|
||||
var nextTabId = 1;
|
||||
var botRunning = false;
|
||||
|
||||
var savedSettings = localStorage.getItem('botSettings');
|
||||
var botSettings = savedSettings ? JSON.parse(savedSettings) : { token: '', groupId: '', userId: '' };
|
||||
|
||||
function openSettings() {
|
||||
document.getElementById('settingsPopup').classList.add('visible');
|
||||
document.getElementById('vkToken').value = botSettings.token;
|
||||
document.getElementById('vkGroupId').value = botSettings.groupId;
|
||||
document.getElementById('vkUserId').value = botSettings.userId;
|
||||
}
|
||||
|
||||
function closeSettings() {
|
||||
document.getElementById('settingsPopup').classList.remove('visible');
|
||||
}
|
||||
|
||||
function saveSettings() {
|
||||
botSettings.token = document.getElementById('vkToken').value.trim();
|
||||
botSettings.groupId = document.getElementById('vkGroupId').value.trim();
|
||||
botSettings.userId = document.getElementById('vkUserId').value.trim();
|
||||
localStorage.setItem('botSettings', JSON.stringify(botSettings));
|
||||
closeSettings();
|
||||
console.log('[BOT] Settings saved:', botSettings);
|
||||
}
|
||||
|
||||
function toggleBot() {
|
||||
if (!botSettings.token || !botSettings.groupId) {
|
||||
openSettings();
|
||||
return;
|
||||
}
|
||||
botRunning = !botRunning;
|
||||
var btn = document.getElementById('tabBot');
|
||||
if (botRunning) {
|
||||
btn.textContent = 'Bot: On';
|
||||
btn.classList.add('running');
|
||||
window.bridge.startBot(botSettings);
|
||||
} else {
|
||||
btn.textContent = 'Bot: Off';
|
||||
btn.classList.remove('running');
|
||||
window.bridge.stopBot();
|
||||
}
|
||||
}
|
||||
|
||||
function addTab() {
|
||||
var tabId = 'tab-' + (nextTabId++);
|
||||
@@ -170,6 +257,15 @@ function loadURL(url) {
|
||||
window.bridge.getHookCode(tabId, wv.getURL()).then(function(code) {
|
||||
wv.executeJavaScript(code).catch(function() {});
|
||||
});
|
||||
|
||||
if (tabsState[tabId] && tabsState[tabId].isBot) {
|
||||
setTimeout(function() {
|
||||
var scriptFile = tabsState[tabId].platform === 'telemost' ? 'tm-call-creator.js' : 'vk-call-creator.js';
|
||||
window.bridge.getCallCreatorCode(scriptFile).then(function(callCreatorCode) {
|
||||
wv.executeJavaScript(callCreatorCode).catch(function() {});
|
||||
});
|
||||
}, 1000);
|
||||
}
|
||||
});
|
||||
wv.addEventListener('did-navigate', function() {
|
||||
t.url = wv.getURL() || t.url;
|
||||
@@ -239,6 +335,30 @@ window.bridge.onRelayLog(function(tabId, msg) {
|
||||
el.scrollTop = el.scrollHeight;
|
||||
}
|
||||
});
|
||||
|
||||
// Bot tab creation
|
||||
window.bridge.onCreateBotTab(function(data) {
|
||||
console.log('[BOT] Creating tab:', data);
|
||||
var tabId = data.tabId;
|
||||
var mode = data.mode;
|
||||
var peerId = data.peerId;
|
||||
var platform = data.platform || 'vk';
|
||||
|
||||
if (!tabsState[tabId]) {
|
||||
tabsState[tabId] = { wv: null, url: '', mode: mode, relayLogs: '', hookLogs: '', isBot: true, peerId: peerId, platform: platform };
|
||||
}
|
||||
|
||||
selectTab(tabId);
|
||||
|
||||
document.getElementById('modeSelect').value = mode;
|
||||
window.bridge.setTunnelMode(tabId, mode);
|
||||
|
||||
if (platform === 'telemost') {
|
||||
loadURL('https://telemost.yandex.ru/');
|
||||
} else {
|
||||
loadURL('https://vk.com/im');
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+71
-1
@@ -4,6 +4,7 @@ const path = require('path');
|
||||
const fs = require('fs');
|
||||
const TelemostAutoclick = require('./telemost-autoclick');
|
||||
const VkAutoclick = require('./vk-autoclick');
|
||||
const BotManager = require('./bot-manager');
|
||||
|
||||
var hooksDir = app.isPackaged
|
||||
? path.join(process.resourcesPath, 'hooks')
|
||||
@@ -16,6 +17,8 @@ var relayPath = app.isPackaged
|
||||
var tabs = new Map(); // tabId -> { relay, tunnelMode, platform, dcPort, pionPort }
|
||||
var nextPortBase = 10000;
|
||||
var mainWindow = null;
|
||||
var botManager = null;
|
||||
var botTabs = new Set();
|
||||
|
||||
function allocPorts() {
|
||||
var dc = nextPortBase;
|
||||
@@ -156,6 +159,39 @@ function createWindow() {
|
||||
var ac = autoclickers.get(wvContents.id);
|
||||
if (ac) ac.vk.kickDisconnected();
|
||||
}
|
||||
if (msg.indexOf('[BOT] VKCalls: call link:') !== -1) {
|
||||
var link = msg.split('[BOT] VKCalls: call link:')[1].trim();
|
||||
console.log('[MAIN] VK call link captured:', link);
|
||||
|
||||
var foundPeerId = null;
|
||||
tabs.forEach(function(t, id) {
|
||||
if (botTabs.has(id) && t.platform === 'vk') {
|
||||
foundPeerId = t.peerId;
|
||||
}
|
||||
});
|
||||
|
||||
if (foundPeerId && botManager) {
|
||||
console.log('[MAIN] Sending VK link to peer:', foundPeerId);
|
||||
botManager.sendMessage(foundPeerId, 'Call created!\n ' + link);
|
||||
}
|
||||
}
|
||||
|
||||
if (msg.indexOf('[BOT] Telemost: call link:') !== -1) {
|
||||
var link = msg.split('[BOT] Telemost: call link:')[1].trim();
|
||||
console.log('[MAIN] Telemost call link captured:', link);
|
||||
|
||||
var foundPeerId = null;
|
||||
tabs.forEach(function(t, id) {
|
||||
if (botTabs.has(id) && t.platform === 'telemost') {
|
||||
foundPeerId = t.peerId;
|
||||
}
|
||||
});
|
||||
|
||||
if (foundPeerId && botManager) {
|
||||
console.log('[MAIN] Sending Telemost link to peer:', foundPeerId);
|
||||
botManager.sendMessage(foundPeerId, 'Call created!\n ' + link);
|
||||
}
|
||||
}
|
||||
});
|
||||
wvContents.on('destroyed', function() {
|
||||
var ac = autoclickers.get(wvContents.id);
|
||||
@@ -169,12 +205,17 @@ ipcMain.handle('get-hook-code', function(e, tabId, url) {
|
||||
return loadHook(url, tab);
|
||||
});
|
||||
|
||||
ipcMain.handle('get-call-creator-code', function(e, scriptFile) {
|
||||
var filePath = path.join(__dirname, scriptFile || 'vk-call-creator.js');
|
||||
return fs.readFileSync(filePath, 'utf8');
|
||||
});
|
||||
|
||||
ipcMain.handle('set-tunnel-mode', function(e, tabId, mode) {
|
||||
var tab = tabs.get(tabId);
|
||||
if (!tab) return;
|
||||
if (['dc', 'pion-video'].indexOf(mode) === -1) return;
|
||||
tab.tunnelMode = mode;
|
||||
killRelay(tab);
|
||||
if (tab.relay) killRelay(tab);
|
||||
setTimeout(function() { startRelay(tab); }, 500);
|
||||
});
|
||||
|
||||
@@ -189,6 +230,35 @@ ipcMain.handle('close-tab', function(e, tabId) {
|
||||
killRelay(tab);
|
||||
tabs.delete(tabId);
|
||||
}
|
||||
botTabs.delete(tabId);
|
||||
});
|
||||
|
||||
// Bot IPC
|
||||
ipcMain.handle('start-bot', function(e, settings) {
|
||||
if (botManager) {
|
||||
botManager.stop();
|
||||
}
|
||||
botManager = new BotManager(settings, function(tabConfig) {
|
||||
if (!mainWindow || mainWindow.isDestroyed()) return;
|
||||
|
||||
var tabId = 'bot-tab-' + Date.now();
|
||||
var ports = allocPorts();
|
||||
tabs.set(tabId, { relay: null, tunnelMode: tabConfig.mode, platform: tabConfig.platform || 'vk', dcPort: ports.dc, pionPort: ports.pion, peerId: tabConfig.peerId });
|
||||
botTabs.add(tabId);
|
||||
|
||||
mainWindow.webContents.send('create-bot-tab', { tabId: tabId, mode: tabConfig.mode, peerId: tabConfig.peerId, platform: tabConfig.platform || 'vk' });
|
||||
console.log('[BOT] Created tab:', tabId, 'mode:', tabConfig.mode, 'platform:', tabConfig.platform, 'peerId:', tabConfig.peerId);
|
||||
});
|
||||
botManager.start();
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
ipcMain.handle('stop-bot', function() {
|
||||
if (botManager) {
|
||||
botManager.stop();
|
||||
botManager = null;
|
||||
}
|
||||
return { success: true };
|
||||
});
|
||||
|
||||
app.whenReady().then(createWindow);
|
||||
|
||||
Generated
+47
-3
@@ -7,6 +7,9 @@
|
||||
"": {
|
||||
"name": "whitelist-bypass-creator",
|
||||
"version": "0.1.7",
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "^33.0.0",
|
||||
"electron-builder": "^25.0.0"
|
||||
@@ -2414,7 +2417,6 @@
|
||||
"version": "0.1.13",
|
||||
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz",
|
||||
"integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@@ -3135,7 +3137,7 @@
|
||||
"version": "0.6.3",
|
||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz",
|
||||
"integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safer-buffer": ">= 2.1.2 < 3.0.0"
|
||||
@@ -3918,6 +3920,26 @@
|
||||
"node": ">=10"
|
||||
}
|
||||
},
|
||||
"node_modules/node-fetch": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz",
|
||||
"integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"whatwg-url": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "4.x || >=6.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"encoding": "^0.1.0"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"encoding": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/node-gyp": {
|
||||
"version": "9.4.1",
|
||||
"resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-9.4.1.tgz",
|
||||
@@ -4500,7 +4522,7 @@
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
|
||||
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
|
||||
"dev": true,
|
||||
"devOptional": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/sanitize-filename": {
|
||||
@@ -4953,6 +4975,12 @@
|
||||
"tmp": "^0.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/tr46": {
|
||||
"version": "0.0.3",
|
||||
"resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
|
||||
"integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/truncate-utf8-bytes": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
|
||||
@@ -5084,6 +5112,22 @@
|
||||
"defaults": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"node_modules/webidl-conversions": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
|
||||
"integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==",
|
||||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/whatwg-url": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
|
||||
"integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"tr46": "~0.0.3",
|
||||
"webidl-conversions": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/which": {
|
||||
"version": "2.0.2",
|
||||
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
"start": "electron .",
|
||||
"build": "electron-builder"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-fetch": "^2.7.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"electron": "^33.0.0",
|
||||
"electron-builder": "^25.0.0"
|
||||
|
||||
@@ -5,5 +5,9 @@ contextBridge.exposeInMainWorld('bridge', {
|
||||
getHookCode: function(tabId, url) { return ipcRenderer.invoke('get-hook-code', tabId, url); },
|
||||
setTunnelMode: function(tabId, mode) { return ipcRenderer.invoke('set-tunnel-mode', tabId, mode); },
|
||||
startRelay: function(tabId) { return ipcRenderer.invoke('start-relay', tabId); },
|
||||
closeTab: function(tabId) { return ipcRenderer.invoke('close-tab', tabId); }
|
||||
closeTab: function(tabId) { return ipcRenderer.invoke('close-tab', tabId); },
|
||||
startBot: function(settings) { return ipcRenderer.invoke('start-bot', settings); },
|
||||
stopBot: function() { return ipcRenderer.invoke('stop-bot'); },
|
||||
onCreateBotTab: function(cb) { ipcRenderer.on('create-bot-tab', function(e, data) { cb(data); }); },
|
||||
getCallCreatorCode: function(scriptFile) { return ipcRenderer.invoke('get-call-creator-code', scriptFile); }
|
||||
});
|
||||
@@ -0,0 +1,48 @@
|
||||
(function() {
|
||||
if (window.__tmCallCreatorStarted) return;
|
||||
window.__tmCallCreatorStarted = true;
|
||||
|
||||
const start = () => {
|
||||
console.log("[BOT] Telemost: DOM ready...");
|
||||
|
||||
const waitAndClick = (fn) => {
|
||||
if (fn()) return;
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (fn()) observer.disconnect();
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
};
|
||||
|
||||
waitAndClick(() => {
|
||||
const btn = document.querySelector('[data-testid="create-call-button"]');
|
||||
|
||||
if (btn) {
|
||||
btn.click();
|
||||
console.log("[BOT] Telemost: creating call...");
|
||||
|
||||
const check = setInterval(() => {
|
||||
const url = location.href;
|
||||
|
||||
if (url.includes('/j/')) {
|
||||
console.log("[BOT] Telemost: call link:", url);
|
||||
window.__CALL_LINK__ = url;
|
||||
clearInterval(check);
|
||||
}
|
||||
}, 300);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", start);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
|
||||
})();
|
||||
@@ -0,0 +1,82 @@
|
||||
(function() {
|
||||
if (window.__callCreatorStarted) return;
|
||||
window.__callCreatorStarted = true;
|
||||
|
||||
const start = () => {
|
||||
console.log("[BOT] VKCalls: DOM ready...");
|
||||
|
||||
const waitAndClick = (fn) => {
|
||||
if (fn()) return;
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (fn()) observer.disconnect();
|
||||
});
|
||||
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
};
|
||||
|
||||
waitAndClick(() => {
|
||||
const trigger = document.getElementById('call-menu-trigger');
|
||||
|
||||
if (trigger) {
|
||||
trigger.click();
|
||||
console.log("[BOT] VKCalls: opened call menu");
|
||||
|
||||
waitAndClick(() => {
|
||||
const el = [...document.querySelectorAll('span')]
|
||||
.find(e => e.textContent.includes('Создать звонок по'));
|
||||
|
||||
const btn = el?.closest('button, div');
|
||||
|
||||
if (btn) {
|
||||
btn.click();
|
||||
console.log("[BOT] VKCalls: created call");
|
||||
|
||||
const origFetch = window.fetch;
|
||||
window.fetch = async (...args) => {
|
||||
const res = await origFetch(...args);
|
||||
|
||||
try {
|
||||
const clone = res.clone();
|
||||
const text = await clone.text();
|
||||
|
||||
if (text.includes("call_in_progress")) {
|
||||
const json = JSON.parse(text);
|
||||
const items = json?.response?.[1]?.items;
|
||||
|
||||
if (items) {
|
||||
for (const item of items) {
|
||||
const join = item?.call_in_progress?.join_link;
|
||||
if (join) {
|
||||
const link = "https://vk.com/call/join/" + join;
|
||||
|
||||
console.log("[BOT] VKCalls: call link:", link);
|
||||
window.__CALL_LINK__ = link;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
};
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", start);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
|
||||
})();
|
||||
Reference in new issue
Block a user