-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
147 lines (113 loc) · 4.24 KB
/
Copy pathscript.js
File metadata and controls
147 lines (113 loc) · 4.24 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
window.startTime = (new Date).getTime();
window.onload = function () {
console.log((new Date).getTime() - window.startTime);
}
var PictureMap = new Map();
window.addEventListener('load',function () {
PictureList()
let img = document.getElementsByClassName("PictureForFree")
console.log(img[1])
console.log(img.length)
let SS = fetchHandler()
console.log(SS)
for (let i =0; i <img.length; i++)
{
SS.then(( uurrll)=>{
console.log(uurrll[i])
img[i].src = uurrll[i].download_url })
}
let time = ((new Date).getTime() - window.startTime)/1000
document.getElementById("foot").innerHTML= "Load time: "+time+"c";
document.getElementById("about-us").style.color="black"
if (document.location.href == 'http://localhost:63342/1_lab/WebLab1.html')
{
document.getElementById("about-us").style.textDecoration="none"
}
if (document.location.href == 'http://localhost:63342/1_lab/WebLab4.html')
{
document.getElementById("about-us").style.textDecoration="underline"
}
},false)
function showCart()
{
if (localStorage.getItem('BuyList') !== null)
{
BuyList = JSON.parse(localStorage.getItem('BuyList'))
let output = ""
let sum = 0
for (let i=0; i < BuyList.length; i++)
{
output += BuyList[i].name + " - " + BuyList[i].price + " rub" + "\n"
sum += BuyList[i].price
}
output += "Итого: " + sum + " rub"
alert(output)
}
else {
alert('Вы ничего не купили')
}
console.log(JSON.parse(localStorage.getItem('BuyList')))
}
function addToCart (PictureName) //На html страницу в вызове данной функции в onclick, передавай в неё названия своих картин
{
let BuyList
let pos = {
name: "",
price: 0
}
if (PictureMap.get(PictureName) !== null ) {
if (localStorage.getItem('BuyList') !== null) {
BuyList = JSON.parse(localStorage.getItem('BuyList'))
pos.name = PictureName
pos.price = PictureMap.get(PictureName)
BuyList.push(pos)
localStorage.setItem('BuyList', JSON.stringify(BuyList))
alert("Picture " + PictureName + " was added to the cart")
} else {
BuyList = []
pos.name = PictureName
pos.price = PictureMap.get(PictureName)
BuyList.push(pos)
localStorage.setItem('BuyList', JSON.stringify(BuyList))
}
}
else
alert("Не продам и не скажу почему")
console.log(JSON.parse(localStorage.getItem('BuyList')))
}
function PictureList()
{
let BuyList = []
localStorage.setItem('BuyList', JSON.stringify(BuyList))
PictureMap.set("Название картины", 1000000) // Картины хранятся в Map (массив в котором значение выдаётся по ключу)
// Название карины - ключ, Цена картины значение// Заполни этот массив своми значениями, чтобы поиск и покупка работали работал
PictureMap.set("Go Nowhere", 6800)
PictureMap.set("Down", 3690)
PictureMap.set("We have wings", 1)
}
function Add() {
let input = document.getElementById("form-input").value
}
function Checkis() {
alert("hello")
let input = document.getElementById("Check").value
if (PictureMap.get(input) !== null )
if (PictureMap.has(input))
alert("Такая Картина есть ! и она бесплатна")
else
alert("Такая Картина есть ! и она стоит:" + PictureMap.get(input))
else
alert("Крысы такого не рисуют")
return false
}
async function fetchHandler() {
const url = "https://picsum.photos/v2/list";
try {
const response = await fetch(url);
let data = await response.json()
console.log(data)
return data;
} catch (error) {
console.log(error);
}
}