hinatazaka46-ext-schedule

Insert extra schedules

当前为 2025-08-17 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/546136/1643394/hinatazaka46-ext-schedule.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name:en         hinatazaka46-ext-schedule
// @name:ja         日向坂46関連 追加スケジュール挿入
// @namespace       https://greasyfork.org/ja/users/1328592-naoqv
// @description:en  Insert extra schedules
// @description:ja  日向坂46関連 追加スケジュール挿入
// @version         0.01
// @icon            https://cdn.hinatazaka46.com/files/14/hinata/img/favicons/favicon-32x32.png
// @compatible      chrome
// @compatible      firefox
// @grant           none
// @license         MIT
// ==/UserScript==
"use strict";

const START_YEARMONTH = "202501";

const DAY_OF_WEEK = {'日': 0, '月': 1, '火': 2, '水': 3, '木': 4, '金': 5, '土': 6};

const EX_SCHEDULE =  {
  '0': [{categ: 'ラジオ', start: '19:30', end: '20:00', title: 'DARAZFM「おひさまコネクト」', link: 'https://x.com/ohisamaconnect'}],
  '1': [{categ: 'ラジオ', start: '20:00', end: '20:30', title: 'DARAZFM「おひさまコネクト」(再)', link: 'https://x.com/ohisamaconnect'}]
};

/**
 *
 * @param {HTMLElement} lMainContentsUl
 * @param {HTMLElement} dayElem
 */ 
const insertSchedule = (dispYearMonth, lMainContentsUl, dayElem) => {

  if (dispYearMonth < START_YEARMONTH) return;

  const dow = DAY_OF_WEEK[dayElem.querySelector('b').innerText];

  Array.prototype.some.call(Object.keys(EX_SCHEDULE), (dayOfWeek) => {
    if (dow == dayOfWeek) {
      Array.prototype.forEach.call(EX_SCHEDULE[dow], (x) => {
        insert(dayElem, x);
      });
    }
  });

  void lMainContentsUl.offsetHeight;
}

/**
 *
 * @param {HTMLElement} dayElem
 * @param {[key: string]: string}
 */ 
const insert = (dayElem, schedule) => {

  const items = dayElem.getElementsByClassName('p-schedule__item');

  Array.prototype.some.call(Array.prototype.slice.call(items).reverse(), (item, i) => {

    const timeElem = item.querySelector('.c-schedule__time--list');

    if (timeElem.innerText != '') {
      const time = timeElem.innerText.match(/[0-9]{1,2}:[0-9]{2}/)[0];
      const start = schedule.start;

      if (time < start || i == items.length - 1) {

        item.insertAdjacentHTML('afterend',
                                `<li class="p-schedule__item">
                 <a href="${schedule.link}">
                   <div class="p-schedule__head">
                     <div class="c-schedule__category category_media">
                       ${schedule.categ}
                     </div>
                     <div class="c-schedule__time--list">
                       ${start + '〜' + schedule.end}
                     </div>
                   </div>
                   <p class="c-schedule__text">
                     ${schedule.title}
                   </p>
                 </a>
               </li>`);
        return true;
      }
    }
    return false;
  });
};