-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
160 lines (138 loc) · 6.1 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
document.addEventListener('DOMContentLoaded', () => {
const themeToggle = document.getElementById('theme-toggle');
const tagButtons = document.querySelectorAll('.tag-button');
const imageDisplaySection = document.getElementById('image-display');
const tagSelectionSection = document.getElementById('tag-selection');
const imageContainer = document.getElementById('image-container');
const imageElement = document.getElementById('image');
const ageVerification = document.getElementById('age-verification');
const ageYesButton = document.getElementById('age-yes');
const ageNoButton = document.getElementById('age-no');
const chooseAnotherTagButton = document.getElementById('choose-another-tag');
const getAnotherImageButton = document.getElementById('get-another-image');
let currentTag = null;
let isAgeVerified = false;
// Load and apply the saved theme
const savedTheme = localStorage.getItem('theme');
if (savedTheme) {
document.body.classList.add(savedTheme);
themeToggle.checked = savedTheme === 'dark-mode';
}
// Toggle theme
themeToggle.addEventListener('change', () => {
document.body.classList.toggle('dark-mode', themeToggle.checked);
document.body.classList.toggle('light-mode', !themeToggle.checked);
localStorage.setItem('theme', themeToggle.checked ? 'dark-mode' : 'light-mode');
});
// Tag button click event
tagButtons.forEach(button => {
button.addEventListener('click', () => {
currentTag = button.dataset.tag;
if (button.classList.contains('nsfw')) {
if (isAgeVerified) {
fetchImage(currentTag);
} else {
showAgeVerification();
}
} else {
fetchImage(currentTag);
}
});
});
// Age verification buttons
ageYesButton.addEventListener('click', () => {
isAgeVerified = true;
fetchImage(currentTag);
hideAgeVerification();
});
ageNoButton.addEventListener('click', () => {
window.location.href = 'https://google.com';
});
// Fetch image function
function fetchImage(tag) {
fetch(`https://api.waifu.im/search?included_tags=${tag}`)
.then(response => response.json())
.then(data => {
const imageUrl = data.images[0].url;
const dominantColor = data.images[0].dominant_color;
imageElement.src = imageUrl;
document.body.style.backgroundColor = dominantColor;
tagSelectionSection.classList.add('hidden');
imageDisplaySection.classList.remove('hidden');
if (!currentTag.includes('nsfw')) {
imageContainer.classList.remove('hidden');
imageElement.classList.remove('hidden');
}
// Update the artist name and source
const artistNameElement = document.getElementById('artist-name');
const sourceLinkElement = document.getElementById('source-link');
const artistInfo = data.images[0].artist;
let artistName = 'Unknown artist';
let artistLink = '';
if (artistInfo) {
if (artistInfo.deviant_art) {
artistLink = artistInfo.deviant_art;
} else if (artistInfo.twitter) {
artistLink = artistInfo.twitter;
} else if (artistInfo.pixiv) {
artistLink = artistInfo.pixiv;
} else if (artistInfo.patreon) {
artistLink = artistInfo.patreon;
}
artistName = artistInfo.name;
}
artistNameElement.textContent = artistName;
if (artistLink) {
artistNameElement.href = artistLink;
artistNameElement.target = '_blank';
} else {
artistNameElement.removeAttribute('href');
artistNameElement.removeAttribute('target');
}
const source = data.images[0].source || 'Unknown source';
sourceLinkElement.textContent = 'View Source';
sourceLinkElement.href = source;
sourceLinkElement.target = '_blank';
// Show image info box
const imageInfoBox = document.getElementById('image-info');
imageInfoBox.classList.remove('hidden');
});
}
// Show age verification
function showAgeVerification() {
ageVerification.classList.remove('hidden');
imageDisplaySection.classList.remove('hidden');
chooseAnotherTagButton.classList.add('hidden');
getAnotherImageButton.classList.add('hidden');
imageContainer.classList.add('hidden');
imageElement.classList.add('hidden');
// Create a new div element for the overlay
const overlay = document.createElement('div');
overlay.id = 'age-verification-overlay';
document.body.appendChild(overlay);
}
// Hide age verification
function hideAgeVerification() {
ageVerification.classList.add('hidden');
chooseAnotherTagButton.classList.remove('hidden');
getAnotherImageButton.classList.remove('hidden');
// Remove the overlay
const overlay = document.getElementById('age-verification-overlay');
if (overlay) {
overlay.remove();
}
}
// Choose another tag
chooseAnotherTagButton.addEventListener('click', () => {
tagSelectionSection.classList.remove('hidden');
imageDisplaySection.classList.add('hidden');
imageContainer.classList.add('hidden');
imageElement.classList.add('hidden');
document.getElementById('image-info').classList.add('hidden');
document.body.style.backgroundColor = '';
});
// Get another image
getAnotherImageButton.addEventListener('click', () => {
fetchImage(currentTag);
});
});