function runNextTime(key, ms, func) {
let saveTime = Number(GM_getValue(key)) || 0
let nowTime = Date.now()
let dif = nowTime - saveTime
let res = ms - dif < 0
res && func(key)
return res
}
function GM_getValue(key) {
return JSON.parse(localStorage.getItem(key))
}
function GM_setValue(key, value) {
localStorage.setItem(key, JSON.stringify(value))
}
class LocalQueue {
constructor(key) {
this.key = key
this.queue = GM_getValue(key) || []
}
getQueue() {
return GM_getValue(this.key)
}
setQueue(array) {
this.queue = array
GM_setValue(this.key, array)
}
push(value) {
this.queue.push(value)
GM_setValue(this.key, this.queue)
}
pop(asyncCallback) {
let v = this.queue.pop()
GM_setValue(this.key, this.queue)
// let save = _ => GM_setValue(this.key, this.queue)
// asyncCallback(save)
return v
}
err(value) {
GM_setValue(this.key+'_err', value)
}
}
function sleep(ms) {
return new Promise((resolv, reject) => {
setTimeout(_ => {
resolv()
}, ms)
})
}
function localQueue(key) {
let q = GM_getValue(key) || []
}
// runNextTime('aaa', 5000, function(key) {
// localStorage.setItem(key, Date.now())
// })
console