Декъашхо:Sasan700/savetimer.js

ХӀара агӀо Википеди чуьра йу — маьрша энциклопеди

Билгалдаккхар: Ӏалашйинчул тӀаьхьа хийцамаш га браузеран кэш цӀанйан йезаш хила мега.

  • Firefox / Safari: Shift тӀетаӀийна йитина, гӀирсийн панелан тӀера тӀетаӀайе Карлайаккха йа Ctrl+F5 йа Ctrl+R (⌘+R Mac тӀехь)
  • Google Chrome: тӀетаӀайе Ctrl+Shift+R (⌘+Shift+R Mac тӀехь)
  • Internet Explorer / Edge: тӀетаӀийна йитина Ctrl, тӀетаӀайе Карлайаккха йа тӀетаӀайе Ctrl+F5
  • Opera: тӀетаӀайе Ctrl+F5.
//Сахьатца хан хотта йо, тlетаlайе нуьйда lалашйа оцу хоттийначу хенахь/Sets a timer to press Save button at specific time

//Optional parameter: saveTimerInterval in milliseconds - how often to check the time(default: 1000)

var saveTimer = new function(){

var wpSave, wpTimer, destDate, timerId = null
if (!window.saveTimerInterval) saveTimerInterval = 1000 //every second
 
this.onLoad = function(){
 wpSave = document.getElementById('wpSave')
 if (!wpSave) return
 wpTimer = document.createElement('a')
 wpTimer.id = 'wptimer'
 wpTimer.title = 'Click Save button as specific time'
 wpTimer.href = 'javascript:saveTimer.click()'
 stopTimer()
 wpSave.parentNode.insertBefore(wpTimer, wpSave)
} 

this.click = function (e){
 stopTimer()
 destDate = new Date()
 var tt, when = prompt('Now:\n' 
  + destDate.getHours() + ':' + dd(destDate.getMinutes()) + ':' + dd(destDate.getSeconds())
  +'\n\Click Save button at:')
 if (!when || !when.match(/^[\d:]+$/)) return
 when = when.split(':')
 if (tt = when.pop()) destDate.setSeconds(tt)  
 if (tt = when.pop()) destDate.setMinutes(tt)  
 if (tt = when.pop()) destDate.setHours(tt)  
 tt = destDate - new Date()
 if (tt < 1000) return alert('Please enter future time\n as\n mm:ss\n or\n hh:mm:ss') 
 //if (confirm ('Will press Save in about ' + showTime(tt) + '\n at ' + destDate))
   timerId = setInterval('saveTimer.timer()', saveTimerInterval)
}

this.timer = function(){
 if (!timerId) return
 var diff = destDate - new Date()
 if (diff <= 999) {
   stopTimer()
   wpSave.click()
 }else{
   wpTimer.innerHTML = showTime(diff)   
 }
}

function stopTimer(){
 wpTimer.innerHTML = '#'   
 if (timerId) {
   clearInterval (timerId)
   timerId = null
 }
}

function showTime(ms){ //milliseconds -> mm:ss or hh:mm:ss
 var hh = '', mm, ss = Math.floor(ms/1000)
 mm = Math.floor(ss/60)
 if (mm > 60) {
  hh = Math.floor(mm/60) + ':'
  mm = dd(mm % 60)
 }
 return  hh + mm + ':' + dd(ss % 60)
}

function dd(d){
 if (d <= 9) return '0'+d
 else return d
}

}
if (wgAction == 'edit' || wgAction == 'submit')
$(saveTimer.onLoad)