Skip to content

Commit 354b593

Browse files
authored
Create script.js
1 parent 6756bc4 commit 354b593

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

Wiki/script.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// DO NOT DELETE OR EDIT
2+
// Firebase configuration
3+
const firebaseConfig = {
4+
apiKey: "AIzaSyC_fh1xWlHdVJVjhHr-ZUy2sKWy9jilUHM",
5+
authDomain: "wiki-storage-51c29.firebaseapp.com",
6+
projectId: "wiki-storage-51c29",
7+
storageBucket: "wiki-storage-51c29.firebasestorage.app",
8+
messagingSenderId: "607647989206",
9+
appId: "1:607647989206:web:e838a6fe33fe5fc47b3877",
10+
measurementId: "G-MS4Y95QN1M"
11+
};
12+
13+
// Initialize Firebase
14+
firebase.initializeApp(firebaseConfig);
15+
const db = firebase.firestore();
16+
17+
// Fetch and display all wikis
18+
async function fetchWikis() {
19+
const wikiList = document.getElementById('wiki-list');
20+
wikiList.innerHTML = '';
21+
22+
const snapshot = await db.collection('wikis').get();
23+
snapshot.forEach(doc => {
24+
const wiki = doc.data();
25+
const li = document.createElement('li');
26+
li.innerHTML = `
27+
<strong>${wiki.title}</strong>
28+
<button onclick="viewWiki('${doc.id}')">📝 View</button>
29+
<button onclick="editWiki('${doc.id}', '${wiki.title}')">
30+
<img src="images.png" width="20" alt="Edit">
31+
</button>
32+
<button onclick="deleteWiki('${doc.id}')">
33+
<img src="delete-page.png" width="20" alt="Delete">
34+
</button>
35+
`;
36+
wikiList.appendChild(li);
37+
});
38+
}
39+
40+
// Create a new wiki
41+
async function createWiki() {
42+
const title = prompt('Enter wiki title:');
43+
const content = prompt('Enter HTML/CSS/JS content for this wiki:');
44+
45+
if (title && content) {
46+
await db.collection('wikis').add({ title, content });
47+
fetchWikis();
48+
}
49+
}
50+
51+
// Edit an existing wiki
52+
async function editWiki(id, title) {
53+
const content = prompt('Edit HTML/CSS/JS content:', '');
54+
55+
if (content) {
56+
await db.collection('wikis').doc(id).update({ title, content });
57+
fetchWikis();
58+
}
59+
}
60+
61+
// Delete a wiki
62+
async function deleteWiki(id) {
63+
if (confirm('Are you sure you want to delete this wiki?')) {
64+
await db.collection('wikis').doc(id).delete();
65+
fetchWikis();
66+
}
67+
}
68+
69+
// View a wiki’s content
70+
async function viewWiki(id) {
71+
const doc = await db.collection('wikis').doc(id).get();
72+
const wiki = doc.data();
73+
74+
const viewer = document.getElementById('wiki-viewer');
75+
viewer.innerHTML = `
76+
<h2>${wiki.title}</h2>
77+
<div>${wiki.content}</div>
78+
`;
79+
80+
// Execute any inline scripts in the content
81+
const scriptTags = viewer.querySelectorAll('script');
82+
scriptTags.forEach(script => {
83+
const newScript = document.createElement('script');
84+
newScript.textContent = script.textContent;
85+
document.body.appendChild(newScript);
86+
script.remove();
87+
});
88+
}
89+
90+
// Initial fetch
91+
fetchWikis();

0 commit comments

Comments
 (0)