AO3: Incomplete. Continue?

Checks how long ago incomplete works were last updated and displays a warning if longer than user set time period.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        AO3: Incomplete. Continue?
// @version     1.0
// @description Checks how long ago incomplete works were last updated and displays a warning if longer than user set time period.
// @author      sharkcat
// @namespace   https://github.com/sharkcatshark/UserScripts
// @match       https://archiveofourown.org/works/*
// @icon        https://www.google.com/s2/favicons?sz=64&domain=archiveofourown.org
// @license     GNU GPLv3
// ==/UserScript==

// note: months are presumed at 30 days so worst case, warnings are gonna be off by a couple days here and there

// == START Settings ==

const maxTimeAllowed = 6; // months

// == END Settings ==

const chapters = document.querySelector("dd.chapters").innerText;

// if not matching chapter count
if (chapters.match(/\S+(?=\/)/g)[0] != chapters.match(/(?<=\/)\S+/g)[0]) {
    // get dates
    const currentDate = new Date();
    const lastUpdated = new Date(document.querySelector("dd.status").innerText);

    // do maths
    const diffTime = currentDate - lastUpdated;
    const timeSinceUpdateDays = diffTime / (1000 * 60 * 60 * 24);
    const timeSinceUpdateYears = timeSinceUpdateDays / (30 * 12);
    const roundedDays = Math.round(timeSinceUpdateDays);
    const roundedYears = timeSinceUpdateYears.toFixed(2);

    // find date of okay update time
    const updateLimit = currentDate.setDate(currentDate.getDate() - (maxTimeAllowed * 30));

    // see if warning needed
    if (updateLimit > lastUpdated) {
        const message = "This work is currently marked incomplete and was last updated " + roundedDays + " days or " + roundedYears + " years ago. Are you sure you wish to continue?";

        const subject = document.querySelector("#inner");
        subject.insertAdjacentHTML( 'afterbegin', '<div style="border: 2px solid red; background: #ffb5b5; color: black; padding: 10px 30px; max-width: max-content; margin: 0 auto;">'+ message + '</div>' );
    }
}