Greasy Fork

Greasy Fork is available in English.

AO3 Publication date

Adds AO3 publication date i.e. date of publication of first chapter to AO3 search/sort page

当前为 2024-11-08 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AO3 Publication date
// @namespace    http://greasyfork.icu/en/scripts/455343/
// @version      2.1
// @description  Adds AO3 publication date i.e. date of publication of first chapter to AO3 search/sort page
// @author       MM
// @match        https://archiveofourown.org/tags/*
// @match        https://archiveofourown.org/works?commit=Sort+and+Filter*
// @match        https://archiveofourown.org/works?utf8=%E2%9C%93&commit=Sort+and+Filter*
// @grant        none
// @license      none
// ==/UserScript==




(function ao3firstpubdate() {
    'use strict';

    // Define the HTML template for the date display with a span for styling
    var html_date_heading = '&nbsp;&nbsp;&nbsp;<span class="date-published" style="font-size: 12px; color: #555; font-family: monospace;"> Date Published: <strong><span style="font-size: 14px; font-family: inherit;">';

    // Check for story headings in the index page
    if (jQuery('.header h4.heading').length) {
        jQuery('.header h4.heading').each(function() {
            var sStoryPath = jQuery(this).find('a').first().attr('href');
            var oHeader = this;

            // Check if link is for an individual work
            var aMatch = sStoryPath.match(/works\/(\d+)/);
            if (aMatch !== null) {
                var iStoryId = aMatch[1];

                // Fetch the work page
                jQuery.get('https://archiveofourown.org/works/' + iStoryId, function(oData) {
                    // Extract and reformat the publication date
                    var rawDate = jQuery(oData).find('dd.published').text().trim();
                    if (rawDate) {
                        // Reformat the date to '05 Oct 2020'
                        var formattedDate = new Intl.DateTimeFormat('en-GB', {
                            day: '2-digit',
                            month: 'short',
                            year: 'numeric'
                        }).format(new Date(rawDate));

                        // Append the formatted date to the story header
                        jQuery(oHeader).append(html_date_heading + '&nbsp;' +  formattedDate + '</span></strong></span>&nbsp;');
                    }
                }).fail(function() {
                    console.log('Failed to fetch publication date for story ID:', iStoryId);
                });
            }
        });
    }

})();