у меня есть расширение для google написанное на JS его код выглядит так manifest {…
- User
у меня есть расширение для google написанное на JS его код выглядит так
manifest { "manifest_version": 3, "name": "Info Extractor", "version": "1.0", "action": { "default_popup": "popup.html", "default_icon": "icons/icon128.png" }, "permissions": ["activeTab", "scripting"] }
popup.html
popup.js document.getElementById('fetchButton').addEventListener('click', () => { updateData(); });
document.getElementById('simulateButton').addEventListener('click', () => { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, func: () => { const button = document.querySelector('.by-button.by-builder-opr-btn.by-button--contained.by-button--xx-large.by-button--primary'); if (button) { button.click(); // Симулируем нажатие на кнопку } }, }); }); });
document.getElementById('updateValueButton').addEventListener('click', () => { const newValue = document.getElementById('newValue').value; chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, func: (value) => { const element = document.querySelector('.pb-position-editor.pb-position-editor-qty-containner'); if (element) { element.innerText = value; // Обновляем текст элемента } }, args: [newValue] // Передаем новое значение }); }); });
function updateData() { chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { chrome.scripting.executeScript({ target: { tabId: tabs[0].id }, func: () => { let data = []; document.querySelectorAll('.by-table-row').forEach((row) => { const cells = row.querySelectorAll('.by-table-cell'); let rowData = { modeledPositions: cells[0] ? cells[0].innerText : '--', leverage: cells[1] ? cells[1].innerText : '--', expiration: cells[2] ? cells[2].innerText : '--', strikePrice: cells[3] ? cells[3].innerText : '--', type: cells[4] ? cells[4].innerText : '--', direction: cells[5] ? cells[5].innerText : '--', bidSize: cells[6] ? cells[6].innerText : '--', bidPriceIV: cells[7] ? cells[7].innerText : '--', orderPriceIV: cells[8] ? cells[8].innerText : '--', quantity: cells[9] ? cells[9].innerText : '--', askSize: cells[10] ? cells[10].innerText : '--', askPriceIV: cells[11] ? cells[11].innerText : '--', pnl: cells[12] ? cells[12].innerText : '--', delta: cells[13] ? cells[13].innerText : '--', gamma: cells[14] ? cells[14].innerText : '--', vega: cells[15] ? cells[15].innerText : '--', theta: cells[16] ? cells[16].innerText : '--', action: cells[17] ? cells[17].innerText : '--' };
data.push(rowData); }); return data; }, }, (results) => { if (results && results[0]) { let data = results[0].result; let dataDiv = document.getElementById('data'); // Очистить предыдущие данные dataDiv.innerHTML = ''; // Создаем таблицу let table = document.createElement('table'); data.forEach(rowData => { let row = document.createElement('tr'); let columns = [ 'modeledPositions', 'leverage', 'expiration', 'strikePrice', 'type', 'direction', 'bidSize', 'bidPriceIV', 'orderPriceIV', 'quantity', 'askSize', 'askPriceIV', 'pnl', 'delta', 'gamma', 'vega', 'theta', 'action' ]; columns.forEach(key => { let cell = document.createElement('td'); cell.innerText = rowData[key]; row.appendChild(cell); }); table.appendChild(row); }); dataDiv.appendChild(table); } }); - Assistant
- User
этот вариант не изменят значение Цена ордера на странице
- Assistant
Если возникли трудности с динамическим изменением значения на странице, вероятно, проблема связана с тем, как выбираются или изменяются DOM-элементы. Давайте попробуем другой подход, который гарантирует, что изменения происходят на активной странице.
- User
- Assistant
- User
мне нужно что бы значения обновлялись постоянно
- Assistant
- Assistant
Если у вас остались вопросы или вам требуется дополнительная помощь по настройке и использованию расширения, пожалуйста, не стесняйтесь спросить. Я здесь, чтобы помочь!
- User
расширение не меняет значения когда окно popup скрыто
- Assistant