Top.Mail.Ru
popup.js function injectTheScript() { chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { // query the active tab, which will be only one tab //and inject the script in it chrome.tabs.executeScript(tabs[0].id, {file: \"content_script.js\"}); }); } document.getElementById('clickactivity').addEventListener('click', injectTheScript); \nНо при двойном клике ничего не происходит","author":{"@type":"Person","name":"sivvol","url":"https://otvet.mail.ru/profile/sivvol"},"dateCreated":"2024-01-21T11:42:32+03:00","datePublished":"2024-01-21T11:42:32+03:00","answerCount":1,"upvoteCount":0,"acceptedAnswer":{"@type":"Answer","text":"Кто съел код то","dateCreated":"2024-01-21T11:42:54+03:00","datePublished":"2024-01-21T11:42:54+03:00","upvoteCount":0,"author":{"@type":"Person","name":"zasckeep","url":"https://otvet.mail.ru/profile/zasckeep"},"url":""},"suggestedAnswer":[]}},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@type":"WebPage","@id":"https://otvet.mail.ru/space/programming/","name":"Программирование"}},{"@type":"ListItem","position":2,"item":{"@type":"WebPage","name":"Не работает двойной клик в плагине Google Chrome"}}]}]}
Ответы
Аватар пользователя
Изменено
Аватар пользователя
Аватар пользователя
Аватар пользователя
Программирование
+3

Не работает двойной клик в плагине Google Chrome

Добрый день. Я пытаюсь сделать разрешение (плагин) для Google Chrome, которое дважды бы кликало по заданой ячейке таблицы, после чего должна открываться новая вкладка. Вот мой код:

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
 content_script.js 
 
function searchAndClickCategory(category) 
{ 
var tdTags = document.querySelectorAll("td"); 
var searchText = category; 
var found; 
 
for (var i = 0; i < tdTags.length; i++) { 
  if (tdTags[i].textContent == searchText) { 
   found = tdTags[i]; 
    break; 
  } 
} 
 
var clickEvent  = document.createEvent ('MouseEvents'); 
clickEvent.initEvent ('dblclick', true, true); 
found.dispatchEvent (clickEvent); 
 
} 
 
searchAndClickCategory("Text in cell table"); 
manifest.json 
 
{   
    "manifest_version": 2,   
 
    "name": "Such Activity",   
    "description": "Wow",   
    "version": "1.0",     
    "permissions": ["tabs", "<all_urls>"],   
 
    "browser_action": {   
        "default_icon": "icon.png",   
        "default_popup": "popup.html"   
    } 
} 
popup.html 
 
<!doctype html>   
<html>   
    <head><title>activity</title></head>   
<body>   
    <button id="clickactivity">click</button>   
    <script src="popup.js"></script>  
</body> 
 
</html>  
popup.js 
 
function injectTheScript() { 
    chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { 
        // query the active tab, which will be only one tab 
        //and inject the script in it 
        chrome.tabs.executeScript(tabs[0].id, {file: "content_script.js"}); 
    }); 
} 
 
document.getElementById('clickactivity').addEventListener('click', injectTheScript); 
 



Но при двойном клике ничего не происходит

По дате
По рейтингу
Аватар пользователя
Ученик

Кто съел код то