-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
165 lines (133 loc) · 4.23 KB
/
main.js
File metadata and controls
165 lines (133 loc) · 4.23 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import './style.css'
import { ProsePlay} from "proseplay"
import { gpt, queer } from './results.js'
//this is heavyhanded but it works
var docs
const app = document.getElementById("app")
const queryClass = app.classList[0]
console.log(app, queryClass)
// let docs = OpenWebTexts // OneTexts
if (queryClass == "queer"){
docs = queer
} else {
docs = gpt
}
function fetchIt(){
pass
}
Array.prototype.random = function (){
return this[Math.floor((Math.random()*this.length))]
}
function makePP(){
const el = document.createElement('div')
el.classList.add("databox")
document.body.appendChild(el)
const pp = new ProsePlay(el)
return pp
}
function swapAll(pp){
// slides every entry at once
pp.choices.forEach((list, choice)=>{
let len = list.length
let current = pp.currentIndexes[choice]
let next = current+1
// console.log(current)
if (current < len-1){
pp.slideWindow(choice,next)
} else {
// pp.currentIndexes[choice] = 0
next = 0
pp.slideWindow(choice,next)
}
})
}
// function swapR(pp){
// pp.random
// }
function swapRandom(pp){
// select random entry
let randomPP = pp.random()
// console.log(randomPP.el)
// let element = document.body.querySelectorAll(".proseplay-current")
let randomPick = randomPP.generate()
// randomPick.target.classList.add("proseplay-hover");
// randomPP.choices.forEach((list, choice)=>{
// let current = randomPP.currentIndexes[choice]
// let next = current+1
// let len = list.length
// // check if reached end of list
// if (next > len-1){
// console.log("end")
// next = 0
// }
// // NEXT IN LIST
// randomPP.slideWindow(choice,next)
// // RANDOM FROM WHOLE LIST
// // // // let randomWord = list.random()
// // let rWindex = Math.floor((Math.random()*list.length))
// // // hoverStyle()
// // randomPP.slideWindow(choice,rWindex)
// // randomPP.slideWindow(choice, randomPP.random)
// // unhoverStyle(randomPP.el.firstChild)
// })
}
function turnLight() {
document.body.classList.remove("dark");
document.body.classList.add("light");
}
function turnDark() {
document.body.classList.remove("light");
document.body.classList.add("dark");
}
function hoverStyle() {
let element = document.body.querySelectorAll(".proseplay-current")
// console.log(element)
// element.classList.add("proseplay-has-hover")
// document.body.classList.add("proseplay-hover")
}
function unhoverStyle(pp) {
pp.classList.remove("proseplay-has-hover")
// document.body.classList.remove("proseplay-hover")
}
function setParam(){
const urlPath = window.location.pathname
const urlSearch = window.location.search
console.log(urlPath, urlSearch)
var docs = urlSearch
return docs
}
function main(){
let ppList = []
// window.addEventListener('content-document-global-created', setParam)
// async window.addEventListener('DOMContentLoaded', setParam)
// document.addEventListener('loadstart', setParam)
// window.addEventListener('onloadstart', setParam)
// const urlPath = window.location.pathname
// const urlSearch = window.location.search
// console.log(urlPath, urlSearch)
// // var docs = urlPath
// setParam().then((docs)=>{
docs.forEach((count, i) => {
let pp = makePP()
pp.parse(docs[i])
// pp.parse(count)
pp.setFunction("turnLight", turnLight);
pp.setFunction("turnDark", turnDark);
// pp.setFunction("hover", hoverStyle)
// let timer = setInterval(function() {swapAll(pp)}, 5000)
ppList.push(pp)
// let timer = setInterval(pp.random, 2000)
return ppList
})
// console.log(ppList)
let timer = setInterval(function() {swapRandom(ppList)}, 2000)
// }).catch((err)=>(console.log(err)))
}
main()
// document.addEventListener('DOMContentLoaded', function(){
// const docs = window.location.pathname
// console.log(docs)
// return docs
// }).then((docs)=>{
// main()
// })