获取本周周报时间

try to take over the world!

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         获取本周周报时间
// @namespace    http://tampermonkey.net/
// @version      0.1.3
// @description  try to take over the world!
// @author       You
// @match        *://i.zuoyebang.cc/
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // Your code here...
    function week(callback) {
        // 按周日为一周的最后一天计算
        var date = new Date();
        // 今天是这周的第几天
        var today = date.getDay();
        //上周日距离今天的天数(负数表示)
        var stepSunDay = -today + 1;
        // 如果今天是周日
        if (today == 0) {
            stepSunDay = -7;
        };
        // 周一距离今天的天数(负数表示)
        var stepMonday = 7 - today;
        var time = date.getTime();
        var monday = new Date(time + stepSunDay * 24 * 3600 * 1000);
        var sunday = new Date(time + stepMonday * 24 * 3600 * 1000);
        // 本周一的日期 (起始日期)
        var startDate = transferDate(monday); // 日期变换 2018-11-10
        // 本周日的日期 (结束日期)
        var endDate = transferDate(sunday); // 日期变换  2018-11-10
        return callback(startDate, endDate) && callback;
    };

    function transferDate(date) {
        // 年
        var year = date.getFullYear();
        // 月
        var month = date.getMonth() + 1;
        // 日
        var day = date.getDate();

        if (month >= 1 && month <= 9) {

            month = "0" + month;
        }
        if (day >= 0 && day <= 9) {

            day = "0" + day;
        }

        var dateString = year + '.' + month + '.' + day;

        return dateString;
    };

    week((s, e) => {
        let val = s + "-" + e + " 周报"
        let inputEle = document.createElement('input')
        document.body.appendChild(inputEle)
        inputEle.setAttribute('value', val)
        inputEle.setAttribute('readonly', 'readonly')
        inputEle.select()
        console.log(document.execCommand('copy'))
        document.body.removeChild(inputEle);
        if (window.location.href.indexOf('weeklynew/create') != -1) {
            alert(val)
        }
    });

})();