Last active
January 6, 2023 15:25
-
-
Save whiteball/408b94623a9137553800ad4b67126831 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name AIのべりすと 「[調整日時]」を任意の日時に置換 | |
// @namespace https://ai-novelist-share.geo.jp/ | |
// @version 0.1 | |
// @description テキストを送信する直前と、出力を表示する直前に、「[調整日時」という部分を任意の日時に置換します。それぞれ「【最新】入力文の確定置換」と「出力文の置換」と同じ範囲にあるものを置換します。 | |
// @author しらたま | |
// @match https://ai-novel.com/novel.php | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=ai-novel.com | |
// @updateURL https://gist.github.com/whiteball/408b94623a9137553800ad4b67126831/raw/ai_novelist_insert_adjusted_timestamp.user.js | |
// @downloadURL https://gist.github.com/whiteball/408b94623a9137553800ad4b67126831/raw/ai_novelist_insert_adjusted_timestamp.user.js | |
// @supportURL https://gist.github.com/whiteball/408b94623a9137553800ad4b67126831 | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const formatDate = function (dateTime, no_delimiter = false) { | |
const date_del = no_delimiter ? '' : '/', | |
center_del = no_delimiter ? '' : ' ', | |
time_del = no_delimiter ? '' : ':' | |
return dateTime.getFullYear() + date_del + ('0' + (dateTime.getMonth() + 1)).slice(-2) + date_del + ('0' + dateTime.getDate()).slice(-2) + center_del + ('0' + dateTime.getHours()).slice(-2) + time_del + ('0' + dateTime.getMinutes()).slice(-2) + time_del + ('0' + dateTime.getSeconds()).slice(-2) | |
} | |
// 送信時に割り込む部分 | |
const originalAjax = window.jQuery.ajax | |
window.jQuery.ajax = function (param) { | |
if (param.type === 'POST' && param.data) { | |
if (param.url === 'getrequest_v5.php') { | |
const dataIndex = param.data.findIndex(function (value) { | |
return value.name === 'data' | |
}) | |
const date = getAdjustedDate() | |
param.data[dataIndex].value = param.data[dataIndex].value.replace(/\[調整日時\]/g, formatDate(date)) | |
const all = document.getElementsByClassName('data_edit') | |
all[all.length - 1].innerHTML = all[all.length - 1].innerHTML.replace(/\[調整日時\]/g, formatDate(date)) | |
} | |
} | |
return originalAjax(param) | |
} | |
// 出力文を取得する部分 | |
const originalPushHistory = window.PushHistory | |
window.PushHistory = function (data) { | |
let start = data.lastIndexOf('<span id="ai_output"'), end = data.indexOf('</span>', start) | |
if (start >= 0 && end >= 0) { | |
// 出力した後 | |
const ai = document.getElementById('ai_output') | |
if (ai) { | |
const pos = ai.innerHTML.indexOf('[調整日時]') | |
if (pos >= 0) { | |
ai.innerHTML = ai.innerHTML.replace(/\[調整日時\]/g, formatDate(getAdjustedDate())) | |
window.CopyContent() | |
data = localStorage.textdata | |
} | |
} | |
} | |
originalPushHistory(data) | |
} | |
// 環境設定に選択肢を追加 | |
const gui_disp_docinfo = document.getElementById('gui_disp_docinfo') | |
if (gui_disp_docinfo) { | |
gui_disp_docinfo.parentElement.insertAdjacentHTML('afterend', `<div style="margin-top:1rem;margin-bottom:1rem" id="mod_range2button_area"><div style="font-size: 16px;" class="options_title">[調整日時]の増減(ユーザースクリプト)</div> | |
<input type="number" value="0" style="width: 3rem" id="mod_insert_adjusted_timestamp_year"> 年 | |
<input type="number" value="0" style="width: 3rem" id="mod_insert_adjusted_timestamp_month"> 月 | |
<input type="number" value="0" style="width: 3rem" id="mod_insert_adjusted_timestamp_date"> 日 | |
<input type="number" value="0" style="width: 3rem" id="mod_insert_adjusted_timestamp_hours"> 時 | |
<input type="number" value="0" style="width: 3rem" id="mod_insert_adjusted_timestamp_minutes"> 分 | |
<input type="number" value="0" style="width: 3rem" id="mod_insert_adjusted_timestamp_seconds"> 秒 | |
<div style="margin-top:0.75rem;"><button id="mod_insert_adjusted_timestamp_check">調整日時を確認</button> <span id="mod_insert_adjusted_timestamp_confirm">ここ調整日時が出ます</span></div> | |
</div>`) | |
const mod_insert_adjusted_timestamp_check = document.getElementById('mod_insert_adjusted_timestamp_check') | |
if (mod_insert_adjusted_timestamp_check) { | |
mod_insert_adjusted_timestamp_check.addEventListener('click', function () { | |
const mod_insert_adjusted_timestamp_confirm = document.getElementById('mod_insert_adjusted_timestamp_confirm') | |
if (mod_insert_adjusted_timestamp_confirm) { | |
mod_insert_adjusted_timestamp_confirm.innerText = formatDate(getAdjustedDate()) | |
} | |
}) | |
} | |
} | |
const getAdjustedDate = function () { | |
const date = new Date() | |
for (const elm of ['Year', 'Month', 'Date', 'Hours', 'Minutes', 'Seconds']) { | |
const input = document.getElementById('mod_insert_adjusted_timestamp_' + elm.toLowerCase()) | |
if (input && input.value !== '0' && !isNaN(Number(input.value))) { | |
date['set' + elm](date['get' + elm]() + Number(input.value)) | |
} | |
} | |
return date | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment