// ==UserScript== // @name 你看的时间太长了 // @namespace You see it too long time. // @version 0.0.2 // @author 稻米鼠 // @description You see it too long time. // @run-at document-idle // @homepage https://meta.appinn.net/t/11501 // @supportURL https://meta.appinn.com/t/11501 // @match *://*/* // @downloadURL none // ==/UserScript== const oldLoadFun = window.onload window.onload=function(){ oldLoadFun && oldLoadFun() // 获取当前所需时间对象 const getNow = ()=>{ const now = Number( new Date() ) const day = now - now%864e5 return { now, day } } // 初始化 const start = getNow() let historyLong = 0 const maxLong = 36e5 // 储存当前数据 const storeData = (long)=>{ const todayYouSeeItHowLong = { day: start.day, long: long } localStorage.setItem('todayYouSeeItHowLong', JSON.stringify(todayYouSeeItHowLong)) } // 如果存在数据 if(localStorage.getItem('todayYouSeeItHowLong')){ try { const temp = JSON.parse(localStorage.getItem('todayYouSeeItHowLong')) // 如果有合理的数据,并且是当天数据 if(temp.day && temp.day === start.day && temp.long){ historyLong = temp.long }else{ storeData(0) } } catch (error) { storeData(0) } } else { storeData(0) } window.setInterval(()=>{ const n = getNow() if(n.day === start.day){ historyLong += n.now - (start.lastTime ? start.lastTime : start.now) start.lastTime = n.now }else{ start.day = n.day historyLong = n.now%864e5 start.lastTime = n.now } storeData(historyLong) if(historyLong >= maxLong){ const alpha = 1 - 4*(historyLong-maxLong)/maxLong document.querySelector('body').style.opacity = ( alpha>1 ? 1 : ( alpha<0 ? 0 : alpha ) ).toFixed(2) if(alpha<0){ document.querySelector('html').style.backgroundImage = 'url("https://i.v2ex.co/WJ15n12m.png")' document.querySelector('html').style.backgroundPosition = 'center top' document.querySelector('html').style.backgroundRepeat = 'no-repeat' } } }, 1e3) }