forked from ListGaul/ListGaul
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
160 lines (137 loc) · 5.35 KB
/
Copy pathscript.js
File metadata and controls
160 lines (137 loc) · 5.35 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-app.js";
import { getDatabase, ref, increment, set, get, onValue } from "https://www.gstatic.com/firebasejs/10.12.2/firebase-database.js";
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyAmPhSw1n-Drv99MVOjYMmEGxoQHU0-omo",
authDomain: "listgaul-d8918.firebaseapp.com",
databaseURL: "https://listgaul-d8918-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "listgaul-d8918",
storageBucket: "listgaul-d8918.appspot.com",
messagingSenderId: "540182819112",
appId: "1:540182819112:web:6b6802f31a512dad84201d",
measurementId: "G-MPCK8Z1KPD"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
const viewCountRef = ref(database, 'viewCount');
// Increment view count
get(viewCountRef).then((snapshot) => {
if (snapshot.exists()) {
incrementViewCount();
} else {
set(viewCountRef, 1);
}
}).catch((error) => {
console.error(error);
});
function incrementViewCount() {
set(viewCountRef, increment(1));
}
// Update view count on the page
onValue(viewCountRef, (snapshot) => {
const viewCount = snapshot.val();
document.getElementById('viewCount').textContent = `Jumlah view: ${viewCount}`;
});
const badgesData = [
{ text: 'Gw > Aku' },
{ text: 'Gue > Aku' },
{ text: 'Gak > Tidak' },
{ text: 'Ngabuburit > Mengisi waktu untuk menunggu' },
{ text: 'Apes > Malang' },
{ text: 'Gaul > Informal' },
{ text: 'Kepo > Ingin tahu' },
{ text: 'Jomblo > Tidak punya pacar' },
{ text: 'Alay > Berlebihan' },
{ text: 'Ngenes > Tertekan' }
];
const shortBadgeThreshold = 20;
function createBadgeElement(text) {
const badge = document.createElement('div');
badge.className = 'badge';
badge.textContent = text;
return badge;
}
function sortAndDisplayBadges(badges) {
const badgeContainer = document.getElementById('badgeContainer');
badgeContainer.innerHTML = '';
const shortBadges = badges.filter(badge => badge.text.length <= shortBadgeThreshold);
const longBadges = badges.filter(badge => badge.text.length > shortBadgeThreshold);
const sortedBadges = [...shortBadges, ...longBadges];
sortedBadges.forEach(badge => {
const badgeElement = createBadgeElement(badge.text);
badgeContainer.appendChild(badgeElement);
});
}
function updateBadgeCount(count) {
document.getElementById('badgeCount').textContent = `Jumlah badge: ${count}`;
}
function performSearch() {
const searchInput = document.getElementById('searchInput').value.trim().toLowerCase();
const badgeContainer = document.getElementById('badgeContainer');
if (searchInput) {
const filteredBadges = badgesData.filter(badge =>
badge.text.toLowerCase().includes(searchInput)
);
if (filteredBadges.length > 0) {
sortAndDisplayBadges(filteredBadges);
updateBadgeCount(filteredBadges.length);
} else {
badgeContainer.innerHTML = '';
const errorMessage = document.createElement('div');
errorMessage.className = 'error-message';
errorMessage.textContent = `"${searchInput}" Lah bahasa gaul apaan lagi tuh?! 😩`;
badgeContainer.appendChild(errorMessage);
const kembaliContainer = document.createElement('div');
kembaliContainer.className = 'kembali-container';
const kembaliBadge = document.createElement('div');
kembaliBadge.className = 'kembali-badge';
kembaliBadge.textContent = 'Kembali';
kembaliContainer.appendChild(kembaliBadge);
badgeContainer.appendChild(kembaliContainer);
kembaliBadge.addEventListener('click', function () {
errorMessage.remove();
kembaliContainer.remove();
sortAndDisplayBadges(badgesData);
document.getElementById('searchInput').value = '';
updateBadgeCount(badgesData.length);
});
}
} else {
const errorMessage = document.querySelector('.error-message');
const kembaliContainer = document.querySelector('.kembali-container');
if (errorMessage) {
errorMessage.remove();
}
if (kembaliContainer) {
kembaliContainer.remove();
}
sortAndDisplayBadges(badgesData);
updateBadgeCount(badgesData.length);
}
}
document.getElementById('searchInput').addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
event.preventDefault();
performSearch();
}
});
document.getElementById('searchBadge').addEventListener('click', function () {
performSearch();
});
document.getElementById('mainTitle').addEventListener('click', function () {
const errorMessage = document.querySelector('.error-message');
const kembaliContainer = document.querySelector('.kembali-container');
if (errorMessage) {
errorMessage.remove();
}
if (kembaliContainer) {
kembaliContainer.remove();
}
sortAndDisplayBadges(badgesData);
document.getElementById('searchInput').value = '';
updateBadgeCount(badgesData.length);
});
sortAndDisplayBadges(badgesData);
updateBadgeCount(badgesData.length);