Greasy Fork

Greasy Fork is available in English.

你看的时间太长了

You see it too long time.

当前为 2019-09-06 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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 *://*/*
// ==/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)
}