-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage-nav-foot.js
More file actions
46 lines (43 loc) · 1.72 KB
/
page-nav-foot.js
File metadata and controls
46 lines (43 loc) · 1.72 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
async function fetchAndLogPage() {
const url = "https://sheets.googleapis.com/v4/spreadsheets/1RamZbmilTQZePFSq3OruCsjW2sf3KilOg05JdWZjfm0/values/Sheet1?alt=json&key=AIzaSyD02By87q_dkNk6VPNSOPBpDhPQJJOqSmk";
let page; // Declare 'page' in the outer scope
async function fetchData() {
try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}
const json = await response.json();
page = json.values[0][0]; // Assign value to 'page'
console.log(json)
return page;
} catch (error) {
console.error('Error with fetch operation:', error.message);
}
}
return await fetchData();
}
document.querySelectorAll('.sidebar-link').forEach(link => {
elClone = link.cloneNode(true);
link.parentNode.replaceChild(elClone, link);
})
document.querySelectorAll('.sidebar-link').forEach(link => {
link.addEventListener('click', async function(event) {
//event.preventDefault();
const page1 = await fetchAndLogPage(); // Await the result of fetchAndLogPage
const href = link.getAttribute('href');
const sixthCharFromBack = parseInt(href[href.length - 6]);
const page = parseInt(page1)
console.log(typeof page, page);
console.log(typeof sixthCharFromBack, sixthCharFromBack );
console.log(sixthCharFromBack > page)
if (sixthCharFromBack > page) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
console.log(page);
console.log(`Link to ${href} is disabled because page (${page}) is less than ${sixthCharFromBack}`);
return false;
}
});
});