ResetEra: Display Posts Per Day

Shows Post Per Day on ResetEra

目前為 2018-08-01 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name     ResetEra: Display Posts Per Day
// @version  1
// @grant    none
// @match    *://*.resetera.com/members/*
// @match    *://*.neogaf.com/members/*
// @namespace https://greasyfork.org/users/734
// @description Shows Post Per Day on ResetEra
// ==/UserScript==

(() => {
    'use strict'

    class Posts {

        constructor() {
            let { joined, messages } = this.rawData
            console.log('Found date/messages:', joined, messages)
            this.messages = Posts.toInt(messages)

            joined = joined.split(' ')
            const month = Posts.MONTHS[joined[0]]
            const day = Posts.toInt(joined[1])
            const year = Posts.toInt(joined[2])

            this.joined = new Date(`${month} ${day} ${year}`)
            console.log('Detected date:', this.joined.toString())
        }

        diff(initial, latest) {
            return Math.floor((latest - initial) / Posts.MILLS_PER_DAY)
        }

        template(title, body) {
            return `<dl><dt>${title}:</dt><dd>${body}</dd></dl>`
        }

        get parent() {
            return document.querySelector('.secondaryContent.pairsJustified')
        }

        get rawData() {
            return Array.from(this.parent.querySelectorAll('dl'))
                .reduce((o, d) => {
                    const txt = d.textContent.split(':')
                    o[txt[0].trim().toLowerCase().replace(':', '')] = txt[1].trim()
                    return o
                }, {})
        }

        get average() {
            const days = this.diff(this.joined, new Date())
            return this.messages / days
        }

        static toInt(str) {
            return +(str.replace(/\D/g, ''))
        }

        static main() {
            const p = new Posts();
            const temp = p.template('Posts Per Day', p.average.toFixed(2))
            p.parent.insertAdjacentHTML('beforeend', temp)
        }

    }

    Posts.MILLS_PER_DAY = 24 * 60 * 60 * 1000

    Posts.MONTHS = {
        Jan: 1,
        Feb: 2,
        Mar: 3,
        Apr: 4,
        May: 5,
        Jun: 6,
        Jul: 7,
        Aug: 8,
        Sep: 9,
        Sept: 9,
        Oct: 10,
        Nov: 11,
        Dec: 12
    }

    Posts.main()

})()