少数派作者激励器

看什么看,还不快去写稿!

当前为 2021-07-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         少数派作者激励器
// @namespace    https://github.com/kokdemo
// @version      0.1
// @description  看什么看,还不快去写稿!
// @author       kok
// @match        https://sspai.com/u/*/posts
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        unsafeWindow
// ==/UserScript==

(function() {
    'use strict';
    window.setTimeout(function(){
        var dateText = document.getElementsByClassName("time")[0].textContent
    var year,month,day,formatDate,lastUpdateDays
    var nowDate = new Date()
    if(dateText.indexOf("小时前")>-1){
        // 24 小时内的文章
        lastUpdateDays = 0
        formatDate = nowDate
    }else{
        if(dateText.length > 6){
        // 去年的文章
            year = dateText.split("年")[0]
            month = dateText.split("年")[1].split("月")[0]
            day = dateText.split("年")[1].split("月")[1].split("日")[0]
        }else{
        // 今年的文章
            year = nowDate.getFullYear()
            month = dateText.split("月")[0]
            day = dateText.split("月")[1].split("日")[0]
        }
        formatDate = new Date(year + "-" + month + "-" + day)
        lastUpdateDays = Math.floor((nowDate - formatDate)/(1000 * 60 * 60 * 24))
    }
    // 设置要过期的时间(4 个月后的 1 号)
    var outDate = new Date()
    outDate.setMonth(formatDate.getMonth() + 4)
    outDate.setDate(1)
    // 计算当前日期和要过期的日期差值
    var difOutDate = Math.floor((outDate - nowDate)/(1000 * 60 * 60 * 24))
    var htmlDom = document.createElement("div")
    htmlDom.className = "con_li mLeft"
    if(difOutDate>30){
        htmlDom.setAttribute('style', 'margin: 14px 0 0 28px!important;color:#8e8787;font-size:12px');
    }else if(difOutDate>0){
        htmlDom.setAttribute('style', 'margin: 14px 0 0 28px!important;color:red;font-size:12px');
    }else{
        htmlDom.setAttribute('style', 'margin: 14px 0 0 28px!important;color:#8e8787;font-size:12px');
    }
    var htmlText = "<span class='right pc_show'>距离上次更新 "+lastUpdateDays+" 天</span>"
    htmlDom.innerHTML = htmlText
        document.getElementsByClassName("side_content")[1].append(htmlDom)
    },1000)
})();