hinatazaka46-dateutil

Hinatazak46 dateeutil

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/537734/1600643/hinatazaka46-dateutil.js

// ==UserScript==
// @name        hinatazaka46-dateutil
// @namespace   https://gf.qytechs.cn/ja/users/1328592-naoqv
// @description  Hinatazak46 dateeutil
// @description:ja  日向坂46 日付ユーティリティライブラリ
// @version     0.02
// @icon        https://cdn.hinatazaka46.com/files/14/hinata/img/favicons/favicon-32x32.png
// @compatible  chrome
// @compatible  firefox
// @grant       none
// @license     MIT
// ==/UserScript==

"use strict";

/*
 * 年表示を短縮表記に変更 yyyy → 'yy
 * @param {string} yearSelector - 年表示要素セレクタ
 */
const shortenYear = (yearSelector) => {
  Array.prototype.forEach.call(document.querySelectorAll(yearSelector), (x) => {
    const text = x.innerText;
    x.innerText = "'" + text.replace(/\d{2}(\d{2}\.)/, '$1');
  });
};

/*
 * Excel日付型のシリアル値からDateオブジェクトを生成
 * @param {string} seria - シリアル値
 */
const excelSerialToDate = (serial) => {
  // Excelは1900年1月1日を1として扱うが、JSのDateは1970年が起点
  // 1900-01-01 から 1970-01-01 までの日数 = 25569日(ただし、Excelの1900年はうるう年として誤認しているので補正必要)
  const msPerDay = 24 * 60 * 60 * 1000;
  const excelEpochOffset = 25569;

  // Excelのシリアル値が整数の場合も小数(時間付き)でも対応
  const date = new Date((parseInt(serial) - excelEpochOffset) * msPerDay);
  return date;
};

/*
 * 黄道12星座 定数クラス
 */
class ZODIAC {
  static AQUARIUS = "みずがめ座";
  static PISCES = "うお座";
  static ARIES = "おひつじ座";
  static TAURUS = "おうし座";
  static GEMINI = "ふたご座";
  static CANCER = "かに座";
  static LEO = "しし座";
  static VIRGO = "おとめ座";
  static LIBRA = "てんびん座";
  static SCORPIO = "さそり座";
  static SAGITTARIUS = "いて座";
  static CAPRICORN = "やぎ座";
  
  static list = () => new Array(ZODIAC.AQUARIUS, ZODIAC.PISCES, ZODIAC.ARIES, ZODIAC.TAURUS, ZODIAC.GEMINI, ZODIAC.CANCER,
                                  ZODIAC.LEO, ZODIAC.VIRGO, ZODIAC.LIBRA, ZODIAC.SCORPIO, ZODIAC.SAGITTARIUS, ZODIAC.CAPRICORN);
}

/*
 * 誕生日日付に該当する星座を返す
 * @param {date} date - 誕生日
 */
const getZodiacSign = (date) => {
  const month = date.getMonth() + 1;
  const day = date.getDate();

  if ((month === 1 && day >= 20) || (month === 2 && day <= 18)) return ZODIAC.AQUARIUS;
  if ((month === 2 && day >= 19) || (month === 3 && day <= 20)) return ZODIAC.PISCES;
  if ((month === 3 && day >= 21) || (month === 4 && day <= 19)) return ZODIAC.ARIES;
  if ((month === 4 && day >= 20) || (month === 5 && day <= 20)) return ZODIAC.TAURUS;
  if ((month === 5 && day >= 21) || (month === 6 && day <= 20)) return ZODIAC.GEMINI;
  if ((month === 6 && day >= 21) || (month === 7 && day <= 22)) return ZODIAC.CANCER;
  if ((month === 7 && day >= 23) || (month === 8 && day <= 22)) return ZODIAC.LEO;
  if ((month === 8 && day >= 23) || (month === 9 && day <= 22)) return ZODIAC.VIRGO;
  if ((month === 9 && day >= 23) || (month === 10 && day <= 22)) return ZODIAC.LIBRA;
  if ((month === 10 && day >= 23) || (month === 11 && day <= 21)) return ZODIAC.SCORPIO;
  if ((month === 11 && day >= 22) || (month === 12 && day <= 21)) return ZODIAC.SAGITTARIUS;
  return ZODIAC.CAPRICORN; // (12/22〜1/19)
};

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址