-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
136 lines (106 loc) · 4.66 KB
/
script.js
File metadata and controls
136 lines (106 loc) · 4.66 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
// Function to add video to DOM
function addVideoToDOM(videoData) {
const videoContainer = document.getElementById('video-container');
const product = document.createElement('div');
product.className = 'product';
const videoElement = document.createElement('video');
videoElement.src = videoData.url;
videoElement.controls = true;
videoElement.width = 320;
videoElement.height = 180;
const description = document.createElement('div');
description.className = 'description';
const creator = document.createElement('span');
creator.textContent = `Creator: ${videoData.creator}`;
const title = document.createElement('h5');
title.textContent = videoData.title;
const starDiv = document.createElement('div');
starDiv.className = 'star';
for (let i = 0; i < 5; i++) {
const star = document.createElement('i');
star.className = 'fas fa-star';
starDiv.appendChild(star);
}
const views = document.createElement('h4');
views.textContent = 'Views: 0';
description.appendChild(creator);
description.appendChild(title);
description.appendChild(starDiv);
description.appendChild(views);
product.appendChild(videoElement);
product.appendChild(description);
videoContainer.appendChild(product);
}
// Function to save video data to localStorage
function saveVideoData(videoData) {
let videos = JSON.parse(localStorage.getItem('videos')) || [];
videos.push(videoData);
localStorage.setItem('videos', JSON.stringify(videos));
}
// Function to load videos from localStorage
function loadVideosFromLocalStorage() {
const videos = JSON.parse(localStorage.getItem('videos')) || [];
videos.forEach(videoData => addVideoToDOM(videoData));
}
// Event listener for uploading a video
document.getElementById('uploadButton')?.addEventListener('click', function () {
const videoInput = document.getElementById('videoUpload');
const creatorInput = document.getElementById('creatorName');
const titleInput = document.getElementById('videoTitle');
if (videoInput.files && videoInput.files[0] && creatorInput.value && titleInput.value) {
const videoFile = videoInput.files[0];
const videoURL = URL.createObjectURL(videoFile);
const creatorName = creatorInput.value;
const videoTitle = titleInput.value;
const videoData = {
url: videoURL,
creator: creatorName,
title: videoTitle
};
// Save to localStorage
saveVideoData(videoData);
// Add video to the DOM immediately
addVideoToDOM(videoData);
// Reset inputs
videoInput.value = '';
creatorInput.value = '';
titleInput.value = '';
alert('Video uploaded successfully!');
} else {
alert("Please complete all fields and select a video file to upload.");
}
});
// Only load videos if we are on video.html
if (window.location.pathname.endsWith("video.html")) {
document.addEventListener('DOMContentLoaded', loadVideosFromLocalStorage);
}
// document.querySelector('.wallet').addEventListener('click', async () => {
// if (typeof window.ethereum !== 'undefined') {
// try {
// // Request connection to MetaMask
// const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
// const provider = new ethers.providers.Web3Provider(window.ethereum);
// const signer = provider.getSigner();
// // Get wallet details
// const walletAddress = accounts[0];
// const balance = await provider.getBalance(walletAddress);
// const balanceInEther = ethers.utils.formatEther(balance);
// // Display wallet details in the console (or on the page if needed)
// console.log("Wallet Address:", walletAddress);
// console.log("Wallet Balance:", balanceInEther);
// alert("Wallet connected successfully!\nAddress: " + walletAddress + "\nBalance: " + balanceInEther + " ETH");
// } catch (error) {
// console.error("Error connecting wallet:", error);
// // Handle specific MetaMask errors
// if (error.code === 4001) {
// alert("Connection request denied. Please authorize the connection in MetaMask.");
// } else {
// alert("Failed to connect wallet. Please try again or check the console for more details.");
// }
// }
// } else {
// alert("MetaMask is not installed. Please install MetaMask to connect your wallet.");
// }
// });
localStorage.removeItem('videos');
localStorage.clear();