// ==UserScript== // @name 打卡提醒 // @namespace http://tampermonkey.net/ // @version 0.2 // @description try to take over the world! // @author cA7dEm0n // @include * // @match * // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @require http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js // @downloadURL https://update.greasyfork.icu/scripts/401212/%E6%89%93%E5%8D%A1%E6%8F%90%E9%86%92.user.js // @updateURL https://update.greasyfork.icu/scripts/401212/%E6%89%93%E5%8D%A1%E6%8F%90%E9%86%92.meta.js // ==/UserScript== (function () { 'use strict'; const DEFAULT_WORK_START_TIME = "09:00"; const DEFAULT_WORK_END_TIME = "18:30"; const REFRESH_MS_TIME = 3000; const TIME_FORMAT = "H:m"; let today = moment().format('L'); const WORK_SIGN_KEY = `workSign_${today}`; const WORK_SIGN_TIME_KEY = `workSignTime_${today}`; const OFF_WORK_SIGN_KEY = `offWorkSign_${today}`; const OFF_WORK_SIGN_TIME_KEY = `offWorkSignTime_${today}`; const DEFAULT_WORK_TIME_MINUTE = Number(moment(DEFAULT_WORK_END_TIME, TIME_FORMAT).diff(moment(DEFAULT_WORK_START_TIME, TIME_FORMAT), 'minute')) if (stringInUrl("help!!!")) { console.log("setWorkTime 手动设置上班打卡时间,例: http://www.baidu.com/?setWorkTime=09:40") console.log("setWorkStatus 手动设置上班打卡状态,例: http://www.baidu.com/?setWorkStatus=true") console.log("setOffWorkTime 手动设置下班打卡时间,例: http://www.baidu.com/?setOffWorkTime=18:40") console.log("setOffWorkStatus 手动设置下班打卡状态,例: http://www.baidu.com/?setOffWorkStatus=true") alert("查看控制台") } if (getParameterByName("setWorkTime")) { let workSignTime = getParameterByName("setWorkTime") GM_setValue(WORK_SIGN_TIME_KEY, workSignTime) let endTime = moment(workSignTime, TIME_FORMAT).add(DEFAULT_WORK_TIME_MINUTE, 'm').format(TIME_FORMAT) GM_setValue(OFF_WORK_SIGN_TIME_KEY, endTime) alert(`上班打卡提示时间修改为: ${workSignTime}\n下班打卡提示时间修改为: ${endTime}`) } if (getParameterByName("setOffWorkTime")) { let offWorkSignTime = getParameterByName("setOffWorkTime") GM_setValue(OFF_WORK_SIGN_TIME_KEY, offWorkSignTime) alert(`下班打卡时间改为\n${offWorkSignTime}`) }; if (getParameterByName("setOffWorkStatus")) { let offWorkSignStatus = getParameterByName("setOffWorkStatus") let status = offWorkSignStatus == "true" ? true : false GM_setValue(OFF_WORK_SIGN_KEY, status) alert(`修改下班打卡状态为[${status}]`) } if (getParameterByName("setWorkStatus")) { let workSignStatus = getParameterByName("setWorkStatus") let status = workSignStatus == "true" ? true : false GM_setValue(WORK_SIGN_KEY, status) alert(`修改上班打卡状态为[${status}]`) } function stringInUrl(name, url) { if (!url) url = window.location.href; return url.indexOf(name) > 0 }; function getParameterByName(name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, '\\$&'); var regex = new RegExp('[?&]' + name + '(=([^]*)|&|#|$)'), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, ' ')); } if (GM_getValue(OFF_WORK_SIGN_KEY, false)) { throw new Error("下班已经打卡,进程结束."); } let workSignTime = GM_getValue(WORK_SIGN_TIME_KEY, DEFAULT_WORK_START_TIME); $("body").append(`