forked from GusBusDraws/smallweb-subway.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzines.js
171 lines (163 loc) · 4.61 KB
/
zines.js
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
161
162
163
164
165
166
167
168
169
170
171
let thisURL_zines;
let thisSite_zines;
let matchedSiteIndex_zines;
let matchedSite_zines;
let prevSiteIndex_zines;
let nextSiteIndex_zines;
const WEBRING_DATA_URL_zines = `https://gusbus.space/smallweb-subway.js/zines.json`;
let DATA_zines;
loadWebringJSON_zines(WEBRING_DATA_URL_zines);
function loadWebringJSON_zines(url) {
fetch(url)
.then(response => response.json())
.then((json) => {webringDataReady_zines(json)});
}
function webringDataReady_zines(json) {
DATA_zines = json;
customElements.get('smallweb-subway-zines') || (
customElements.define('smallweb-subway-zines', Webring_zines));
}
function getHostName_zines(url) {
// this is a bit of a cheat that leverages the URL type to get the hostname automagically
return new URL(url).hostname;
}
function goToPrev_zines() {
// Adding '//' treats the link as an external site, even without "https:"
location.href = '//' + DATA_zines[prevSiteIndex_zines].url
}
function goToNext_zines() {
// Adding '//' treats the link as an external site, even without "https:"
location.href = '//' + DATA_zines[nextSiteIndex_zines].url
}
let template_zines = document.createElement("template");
template_zines.innerHTML = `
<div class="webring_zines">
<h3>The Smallweb Subway</h3>
<div>
<button id="tri-left_zines" onclick="goToPrev_zines()"></button>
<div id="line">
<div id="outer-circle">
<div id="inner-circle"></div>
</div>
</div>
<button id="tri-right_zines" onclick="goToNext_zines()"></button>
</div>
<p>
Zines Line: Sites with original zines and zine resources.
</p>
</div>
<style>
.webring_zines {
width: 100%;
height: auto;
}
.webring_zines > div {
display: flex;
gap: 20px;
align-items: center;
justify-content: center;
}
h3 {
text-align: center;
margin-bottom: 10px;
padding-top: 10px;
}
p {
text-align: center;
margin-top: 10px;
margin-bottom: 10px;
padding-bottom: 10px;
}
#tri-left_zines {
width: 0;
height: 0;
background: none;
border-top: 20px solid transparent;
border-left: none;
border-right: 40px solid #0077c0;
border-bottom: 20px solid transparent;
outline: none;
cursor: pointer;
}
#tri-left_zines:hover {
border-top: 20px solid transparent;
border-left: none;
border-right: 40px solid black;
border-bottom: 20px solid transparent;
}
#tri-right_zines {
width: 0;
height: 0;
background: none;
border-top: 20px solid transparent;
border-left: 40px solid #0077c0;
border-right: none;
border-bottom: 20px solid transparent;
cursor: pointer;
}
#tri-right_zines:hover {
border-top: 20px solid transparent;
border-left: 40px solid black;
border-right: none;
border-bottom: 20px solid transparent;
}
#line {
width: 120px;
height: 20px;
background: #0077c0;
display: flex;
align-items: center;
justify-content: center;
}
#outer-circle {
width: 40px;
height: 40px;
background: black;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
}
#inner-circle {
width: 20px;
height: 20px;
background: white;
border-radius: 50%;
}
</style>
`;
class Webring_zines extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: "open" })
this.shadowRoot.appendChild(template_zines.content.cloneNode(true));
}
connectedCallback() {
console.log('----------')
console.log('zines line')
console.log('----------')
console.log('Webring JSON data:')
console.log(JSON.stringify(DATA_zines))
thisURL_zines = new URL(window.location.href);
thisSite_zines = (
thisURL_zines.hostname + thisURL_zines.pathname)
console.log("This site:")
console.log(thisSite_zines)
matchedSiteIndex_zines = (
DATA_zines.map(x => x.url).indexOf(thisSite_zines))
matchedSite_zines = (
DATA_zines[matchedSiteIndex_zines]);
console.log("Matched site:")
console.log(matchedSite_zines.url)
prevSiteIndex_zines = matchedSiteIndex_zines - 1;
if (prevSiteIndex_zines === -1) {
prevSiteIndex_zines = DATA_zines.length - 1};
console.log("Previous site:")
console.log(DATA_zines[prevSiteIndex_zines].url)
nextSiteIndex_zines = matchedSiteIndex_zines + 1;
if (nextSiteIndex_zines === DATA_zines.length) {
nextSiteIndex_zines = 0};
console.log("Next site:")
console.log(DATA_zines[nextSiteIndex_zines].url)
}
}