一天天的太划了,活跃度那个条已经溢出去了
嗯...不知道有没有bug
visibleState为visible的页面,每3秒向localstorage插入一次truncate之后的时间,再根据标记个数记录页面活跃的时间。
显示到活跃度下边,与进度条颜色相同。
// ==UserScript==
// @name V2EX Timer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 该干活了亲
// @author Anonymous
// @match https://*.v2ex.com/*
// @grant none
// ==/UserScript==
const SET_CACHE_KEY = 'V2EX_WASTE_SET';
const DATE_CACHE_KEY = 'V2EX_WASTE_DATE';
function tick() {
if (document.visibilityState !== 'visible') {
//invisible
return
}
const now = new Date()
const cache_date = localStorage.getItem(DATE_CACHE_KEY)
if (cache_date != now.toLocaleDateString()) {
//today is a good day
localStorage.setItem(DATE_CACHE_KEY, now.toLocaleDateString())
localStorage.setItem(SET_CACHE_KEY, '[]')
}
const set = new Set(JSON.parse(localStorage.getItem(SET_CACHE_KEY)))
const flag = now.getTime() - now.getTime() % 6000 // record every 6 seconds
set.add(flag)
localStorage.setItem(SET_CACHE_KEY, JSON.stringify(Array.from(set)))
}
function render_node(minutes) {
const origin_bar = document.getElementById('member-activity')
const div = document.createElement('div')
const span = document.createElement('span')
span.innerHTML = `今日已在V2EX浪费${minutes}分钟`
span.style.color = window.getComputedStyle(origin_bar.firstElementChild.firstElementChild).backgroundColor
span.style.fontWeight = 700
div.append(span)
origin_bar.append(div)
}
(function () {
'use strict';
tick()
setInterval(tick, 3000)
const len = JSON.parse(localStorage.getItem(SET_CACHE_KEY)).length
render_node(len / 10)
})();
1
ipadpro4k 2020-07-03 13:07:24 +08:00 via iPhone
这和香烟包装上写个吸烟有害健康有啥区别
|
2
Procumbens 2020-07-03 13:11:20 +08:00 1
逛 V 站的时间 能叫浪费么🐶
|
3
d5 2020-07-03 13:13:24 +08:00
学习老哥们的生活、生产经验,以后少踩坑,不觉得是浪费时间,超值 哈哈哈
|