-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
54 lines (46 loc) · 1.72 KB
/
popup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
document.addEventListener('DOMContentLoaded', function() {
var checkLinksBtn = document.getElementById('checkLinksBtn');
checkLinksBtn.addEventListener('click', function() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var tabId = tabs[0].id;
chrome.scripting.executeScript({
target: {tabId: tabId},
files: ['content.js']
}, function() {
chrome.tabs.sendMessage(tabId, {action: 'checkLinks'}, function(response) {
if (response && response.links) {
generateTable(response.links);
}
});
});
});
});
var copyBtn = document.getElementById('copyBtn');
copyBtn.addEventListener('click', function() {
copyLinks();
});
});
function generateTable(links) {
var tbody = document.querySelector('#linkTable tbody');
tbody.innerHTML = '';
links.forEach(function(link) {
var row = document.createElement('tr');
var linkCell = document.createElement('td');
linkCell.textContent = link.url;
row.appendChild(linkCell);
tbody.appendChild(row);
});
}
function copyLinks() {
var linkElements = document.querySelectorAll('#linkTable tbody td:first-child');
var links = Array.from(linkElements).map(function(linkElement) {
return linkElement.textContent;
});
var textarea = document.createElement('textarea');
textarea.value = links.join('\n');
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
alert('Les liens ont été copiés dans le presse-papiers.');
}