window.localStorage.setItem('language.title', '钉钉')
window.localStorage.setItem('conf.fadeIn', 1000)
window.localStorage.setItem('conf.fadeOut', 1000)
window.localStorage.setItem('conf.lastHeartBeatMax', 3)
window.localStorage.setItem('conf.delayNotify', 60*5)
window.localStorage.setItem('conf.showMsgDelayDefault', 2500)
var boring = 0, currentTitle = window.localStorage.getItem('language.title'), countMsg = 0
var lastHeartBeat = []
var runContent = {
hasMessage: false,
countMsg: -1,
timestamp: [parseInt(+new Date()/1000), 0]
}
var notifyObj = {}
Object.defineProperty(runContent, 'countMsg', {
get: function() {
if(this.history && this.history.length){
if(1 === this.history.length){
return this.history[0]
}else{
return this.history[1]
}
}else{
this.history = []
return -1
}
},
set: function(v) {
if(!this.history){
this.history = []
}
this.history.push(v)
while(this.history.length && this.history.length > 2){
this.history.shift()
}
return this.history[1]
}
})
Object.defineProperty(runContent, 'firstCountMsg', {
get: function() {
if(this.history && 2 === this.history.length){
return this.history[0]
}else if(this.history && 1 === this.history.length){
return -1
}else{
this.history = []
return -1
}
}
})
Object.defineProperty(runContent, 'lastHeartBeat', {
get: function() {
if(this.heartBeat.length){
return this.heartBeat[this.heartBeat.length - 1]
}else{
return null
}
}
})
var getUnreadNum = function(){
var tmp = [], unread = $("em[class='ng-binding']")
for(var len = unread.length - 1; len>=0; len--){
tmp.unshift(+unread[len].innerText)
}
return tmp[0]
}
var notifyMsg = function(msg){
msgTitle = msg.title
if(msg.immediate){
msgTitle = '(' + msgTitle + ') 条未读'
}else{
runContent.timestamp[1] = parseInt(+new Date()/1000)
if(runContent.timestamp[1] < runContent.timestamp[0] + parseInt(window.localStorage.getItem('conf.delayNotify'))){
msgTitle = ''
}else{
msgTitle = '(' + msgTitle + ') 条未读'
runContent.timestamp[0] = runContent.timestamp[1]
}
}
if(msgTitle){
console.log(msgTitle)
extension = {
icon: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7O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yV6QNLOqNVd/DNLvu5f4dICUqGRUVN68fQfUn6TlJkuGASAQ/gmov9rNWBJvEwePI7T+AA14onaMQBMHJ5DRqxcVDWkVx9ZC4SDGgKbPjaJflFXEsTXzuIkxQP2H6E8bDUmsDU0uYoJAuUE0TEsRe1OXU5qwAda/v/1qlcXR2EZq7uMEth++f8UWAODmPlKHAyewqXn/URJXhwOpy4M7MatYSeLu8iA6XXgyFL5OF+XdPso7npR3fSnvfFPQ/QcA4b/UZg8P+5wAAAAASUVORK5CYII=',
body: ''
}
notifyObj = new Notification(msgTitle, extension)
var notifyShowEvent = function () {
setTimeout(this.close.bind(this), window.localStorage.getItem('conf.showMsgDelayDefault'))
}
notifyObj.addEventListener('show', notifyShowEvent, false)
}
}
var showNotification = function(){
var unread = getUnreadNum()
if(unread){
if(runContent.countMsg < 0){
runContent.countMsg = unread
}
if(runContent.firstCountMsg < 0){
runContent.countMsg = unread
}
runContent.countMsg = unread
if(runContent.countMsg > -1 && (runContent.countMsg != runContent.firstCountMsg)){
runContent.countMsg = unread
notifyMsg({title: runContent.countMsg, immediate: true})
console.log(runContent.countMsg)
}else{
notifyMsg({title: runContent.countMsg, immediate: false})
}
console.log('_')
return
}
console.log('.')
}
window.onblur = function() {
if(!boring){
boring = setInterval(showNotification, window.localStorage.getItem('conf.fadeIn'))
}
}
var stopListen = function(){
clearInterval(boring)
}