-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathresultado.html
More file actions
145 lines (119 loc) · 4.87 KB
/
resultado.html
File metadata and controls
145 lines (119 loc) · 4.87 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://asagod.github.io/dndsheet/styles/app.css">
<link rel="stylesheet" href="https://bootswatch.com/5/darkly/bootstrap.css">
<title>Valores Salvos</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
#entry-list {
margin-top: 20px;
list-style-type: none;
padding: 0;
}
#entry-list li {
margin: 5px 0;
}
.autowidth-custom {
overflow: auto;
}
</style>
</head>
<body>
<div class="container">
<div class="card shadow-lg">
<div class="card-header text-center">
<h3 class="card-title">Sorteio</h3>
</div>
<div class="card-body">
<ul id="entry-list">
<!-- Entries will be displayed here -->
</ul>
</div>
</div>
</div>
<script>
// Retrieve the entries from localStorage
const pessoas = JSON.parse(localStorage.getItem('entries'));
const todas_pessoas = [];
let amigos = []
const resultados = [];
randomize = function (pessoa) {
var index = pessoas.indexOf(pessoa);
if (index !== -1) {
pessoas.splice(index, 1);
}
const random = Math.floor(Math.random() * pessoas.length);
let spliced = pessoas.splice(random, 1);
let randomized = spliced[0]
if (!amigos.includes(pessoa)) {
pessoas.push(pessoa)
}
if (pessoa != randomized) {
let linkAmigo = "https://asagod.github.io/dndsheet/amigo.html?data=" + btoa(randomized)
amigos.push(randomized)
resultados.push({ pessoa, linkAmigo })
}
}
for (let i = 0; i < pessoas.length; i++) {
todas_pessoas.push(pessoas[i])
}
for (let j = 0; j < todas_pessoas.length; j++) {
randomize(todas_pessoas[j])
}
// If there are entries, display them
if (resultados && resultados.length > 0) {
const entryList = document.getElementById('entry-list');
resultados.forEach(entry => {
const listItem = document.createElement('li');
// Create a span for 'pessoa' to prepend to the list item
const nameSpan = document.createElement('span');
nameSpan.classList.add('input-group-prepend');
nameSpan.textContent = entry.pessoa;
// Create a span for the 'linkAmigo' to append after the name
const linkSpan = document.createElement('span');
linkSpan.classList.add('input-group-text');
linkSpan.classList.add('autowidth-custom');
linkSpan.textContent = entry.linkAmigo;
//const copyLink = document.createElement('button');
//copyLink.classList.add("copy-btn");
//copyLink.classList.add("btn");
//copyLink.classList.add("btn-secondary");
//copyLink.textContent = "Copiar";
// Append name and link to the list item
listItem.appendChild(nameSpan);
listItem.appendChild(linkSpan);
//listItem.appendChild(copyLink);
// Append the list item to the entry list
entryList.appendChild(listItem);
});
} else {
// If no entries, display a message
document.getElementById('entry-list').innerHTML = '<li> Nenhum amigo encontrado. :( </li>';
}
const copyButtons = document.querySelectorAll("copy-btn");
// Attach event listeners to each copy button
//copyButtons.forEach(button => {
//button.addEventListener('click', function() {
// Get the text content of the parent <li> (the line you want to copy)
//const lineText = button.parentElement.firstChild.textContent.trim();
// Use the Clipboard API to copy the text to the clipboard
//navigator.clipboard.writeText(lineText).then(() => {
// Optional: Notify the user that the text has been copied
//alert(`Copiado: "${lineText}"`);
//}).catch(err => {
// Handle any errors that occur during the copy process
//console.error('Não foi possível copiar: ', err);
//});
//});
//});
// Optionally, clear the entries from localStorage after displaying
//localStorage.removeItem('entries');
</script>
</body>
</html>