// ==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 // @downloadURL none // ==/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 = "距离上次更新 "+lastUpdateDays+" 天" htmlDom.innerHTML = htmlText document.getElementsByClassName("side_content")[1].append(htmlDom) },1000) })();