aboutsummaryrefslogtreecommitdiff
path: root/public/javascripts/getUsers.js
diff options
context:
space:
mode:
authorNoah Loomans <noahloomans@gmail.com>2016-09-05 11:02:24 +0200
committerNoah Loomans <noahloomans@gmail.com>2016-09-05 11:02:24 +0200
commit4a4c164e497e58197bc09af85a16abbfaa0725ae (patch)
tree3ec193ac083e8f263a5a8af30eaf5604dc64cf74 /public/javascripts/getUsers.js
parente7e9fbd1c7baa3d5a71e8359495791865b755e4b (diff)
fixed safari bug
Diffstat (limited to 'public/javascripts/getUsers.js')
-rw-r--r--public/javascripts/getUsers.js65
1 files changed, 35 insertions, 30 deletions
diff --git a/public/javascripts/getUsers.js b/public/javascripts/getUsers.js
index d179bee..fb54659 100644
--- a/public/javascripts/getUsers.js
+++ b/public/javascripts/getUsers.js
@@ -1,36 +1,41 @@
const Promise = require('bluebird')
const cheerio = require('cheerio')
const request = Promise.promisify(require('request'))
-const ty = require('then-yield').using(Promise.cast)
-module.exports = ty.async(function * () {
- const page = (yield request(`http://${window.location.host}/meetingpointProxy/Roosters-AL%2Fdoc%2Fdagroosters%2Fframes%2Fnavbar.htm`)).body
- const $ = cheerio.load(page)
- const $script = $('script').eq(1)
- const scriptText = $script.text()
+module.exports = function () {
+ return new Promise((resolve, reject) => {
+ request(`http://${window.location.host}/meetingpointProxy/Roosters-AL%2Fdoc%2Fdagroosters%2Fframes%2Fnavbar.htm`)
+ .then(function (page) {
+ page = page.body
- const regexs = [/var classes = \[(.+)\];/, /var teachers = \[(.+)\];/, /var rooms = \[(.+)\];/, /var students = \[(.+)\];/]
- const items = regexs.map(regex => scriptText.match(regex)[1].split(',').map(item => item.replace(/"/g, '')))
+ const $ = cheerio.load(page)
+ const $script = $('script').eq(1)
+ const scriptText = $script.text()
- return []
- .concat(items[0].map((item, index) => ({
- type: 'c',
- value: item,
- index: index
- })))
- .concat(items[1].map((item, index) => ({
- type: 't',
- value: item,
- index: index
- })))
- .concat(items[2].map((item, index) => ({
- type: 'r',
- value: item,
- index: index
- })))
- .concat(items[3].map((item, index) => ({
- type: 's',
- value: item,
- index: index
- })))
-})
+ const regexs = [/var classes = \[(.+)\];/, /var teachers = \[(.+)\];/, /var rooms = \[(.+)\];/, /var students = \[(.+)\];/]
+ const items = regexs.map(regex => scriptText.match(regex)[1].split(',').map(item => item.replace(/"/g, '')))
+
+ resolve([]
+ .concat(items[0].map((item, index) => ({
+ type: 'c',
+ value: item,
+ index: index
+ })))
+ .concat(items[1].map((item, index) => ({
+ type: 't',
+ value: item,
+ index: index
+ })))
+ .concat(items[2].map((item, index) => ({
+ type: 'r',
+ value: item,
+ index: index
+ })))
+ .concat(items[3].map((item, index) => ({
+ type: 's',
+ value: item,
+ index: index
+ }))))
+ })
+ })
+}