Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
133 lines (108 loc) · 4.28 KB
/
Copy pathscript.js
File metadata and controls
133 lines (108 loc) · 4.28 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
// Функция для регистрации
function register() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
if (!username || !password) {
alert('Брателло, заполни все поля, не будь котом!');
return;
}
// Сохраняем пользователя в localStorage
localStorage.setItem('user', JSON.stringify({ username, password }));
localStorage.setItem('links', JSON.stringify([]));
alert('Аккаунт создан, добро пожаловать в банду!');
showProfile();
}
// Функция для входа
function login() {
const username = document.getElementById('username').value;
const password = document.getElementById('password').value;
if (!username || !password) {
alert('Брателло, заполни все поля!');
return;
}
const user = JSON.parse(localStorage.getItem('user'));
if (user && user.username === username && user.password === password) {
alert('Приветствую, братишка!');
showProfile();
} else {
alert('Неверный логин или пароль, брателло!');
}
}
// Показать профиль
function showProfile() {
document.getElementById('auth').style.display = 'none';
document.getElementById('profile').style.display = 'block';
// Загружаем ссылки
loadLinks();
}
// Добавление ссылки
function addLink() {
const linkInput = document.getElementById('linkInput');
const url = linkInput.value.trim();
if (!url) {
alert('Брателло, ты забыл вставить ссылку!');
return;
}
// Проверяем URL
try {
new URL(url);
} catch (e) {
alert('Это не похоже на ссылку, братишка!');
return;
}
// Получаем текущие ссылки
const links = JSON.parse(localStorage.getItem('links') || '[]');
links.push(url);
// Сохраняем обновленный список
localStorage.setItem('links', JSON.stringify(links));
// Очищаем поле ввода
linkInput.value = '';
// Обновляем список
loadLinks();
}
// Загрузка ссылок
function loadLinks() {
const linksList = document.getElementById('linksList');
const links = JSON.parse(localStorage.getItem('links') || '[]');
linksList.innerHTML = '';
links.forEach((link, index) => {
const li = document.createElement('li');
li.className = 'link-item';
// Определяем иконку в зависимости от домена
let iconClass = 'default';
let iconCode = '<i class="fas fa-link"></i>';
if (link.includes('youtube.com') || link.includes('youtu.be')) {
iconClass = 'youtube';
iconCode = '<i class="fab fa-youtube"></i>';
} else if (link.includes('vk.com')) {
iconClass = 'vk';
iconCode = '<i class="fab fa-vk"></i>';
} else if (link.includes('spotify.com')) {
iconClass = 'spotify';
iconCode = '<i class="fab fa-spotify"></i>';
} else if (link.includes('music.yandex')) {
iconClass = 'yandex';
iconCode = '<i class="fab fa-yandex"></i>';
}
li.innerHTML = `
<div class="link-icon ${iconClass}">${iconCode}</div>
<a href="${link}" target="_blank" class="link-url">${link}</a>
<button class="delete-btn" onclick="deleteLink(${index})"><i class="fas fa-trash"></i></button>
`;
linksList.appendChild(li);
});
}
// Удаление ссылки
function deleteLink(index) {
const links = JSON.parse(localStorage.getItem('links') || '[]');
links.splice(index, 1);
localStorage.setItem('links', JSON.stringify(links));
loadLinks();
}
// Проверяем, авторизован ли пользователь при загрузке
window.onload = function() {
const user = localStorage.getItem('user');
if (user) {
showProfile();
}
};