-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
72 lines (63 loc) · 2.69 KB
/
script.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
$(document).ready(function () {
$('#copyBtn').prop('disabled', true); // Initially disable the copy button
// SRC links
$('#extractSrcBtn').on('click', function () {
const htmlCode = $('#htmlCode').val();
const tempDiv = $('<div></div>').html(htmlCode);
const iframes = tempDiv.find('iframe');
const allLinks = $('#allLinks');
allLinks.empty(); // Clear previous links
if (iframes.length > 0) {
let count = 1;
iframes.each(function () {
const src = $(this).attr('src');
if (src) {
const linkContainer = $('<div></div>');
const numberElement = $('<span></span>').text(count + '. ');
linkContainer.append(numberElement);
const aElement = $('<a></a>').text(src).css({
'display': 'block',
'overflow': 'hidden',
'text-overflow': 'ellipsis',
'white-space': 'nowrap',
'width': '100%',
'max-width': '100%'
});
aElement.attr('href', src);
aElement.attr('target', '_blank');
linkContainer.append(aElement);
allLinks.append(linkContainer);
allLinks.append('<br>');
count++;
}
});
$('#copyBtn').prop('disabled', false); // Enable the copy button if valid content is present
} else {
allLinks.text('No iframe elements with src found.');
$('#copyBtn').prop('disabled', true); // Disable the copy button if no valid content
}
});
$('#copyBtn').on('click', function () {
const linkContainers = $('#allLinks').find('div');
let textToCopy = '';
linkContainers.each(function (index) {
const linkText = $(this).find('a').text();
textToCopy += (index + 1) + '. ' + linkText + '\n'; // Adding count before each link
});
if (textToCopy.trim() !== '') {
const textArea = $('<textarea></textarea>');
textArea.val(textToCopy.trim()); // Trim extra whitespace
$('body').append(textArea);
textArea.select();
document.execCommand('copy');
textArea.remove();
alert('Text copied to clipboard');
}
});
// Click event for the Clear Text button
$('#clearBtn').on('click', function () {
$('#allLinks').empty();
$('#htmlCode').val('');
$('#copyBtn').prop('disabled', true); // Disable the copy button on clear
});
});