forked from PrototypeFunction/PlanMaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (34 loc) · 858 Bytes
/
app.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
App({
onLaunch: function (opts) {
if (opts.referrerInfo && opts.referrerInfo.extraData && opts.referrerInfo.extraData.from) {
wx.reportAnalytics('adclick', {
from: opts.referrerInfo.extraData.from,
})
}
wx.setStorage({
key: 'showTime',
data: null,
})
},
getAds: function (cb) {
wx.request({
url: 'https://planmaster.prototype.im/ads.json',
success: res => {
const { showAd, ads } = res.data
let showTime = Number(wx.getStorageSync('showTime')) || 0
if (showAd) {
wx.setStorage({
key: 'showTime',
data: showTime + 1
})
}
const adData = {
showAd: showAd,
ads: ads,
ad: ads[showTime % ads.length],
}
typeof cb === 'function' && cb(adData)
}
})
},
})