Skip to content

Instantly share code, notes, and snippets.

@whiteball
Last active February 16, 2023 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whiteball/f14ddfc89ed8781d5253314620b63679 to your computer and use it in GitHub Desktop.
Save whiteball/f14ddfc89ed8781d5253314620b63679 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AIのべりすと 自動でZIPですべてエクスポート
// @namespace https://ai-novelist-share.geo.jp/
// @version 0.1
// @description AIのべりすとの作品リストを開いたとき、前回自動ダウンロードから指定日数が経過していれば、自動でダウンロードを開始します。
// @author しらたま
// @match https://ai-novel.com/works.php
// @icon https://www.google.com/s2/favicons?sz=64&domain=ai-novel.com
// @updateURL https://gist.github.com/whiteball/f14ddfc89ed8781d5253314620b63679/raw/ai_novelist_undo_to_head.user.js
// @downloadURL https://gist.github.com/whiteball/f14ddfc89ed8781d5253314620b63679/raw/ai_novelist_undo_to_head.user.js
// @supportURL https://gist.github.com/whiteball/f14ddfc89ed8781d5253314620b63679
// @grant none
// ==/UserScript==
(function() {
'use strict';
const works_find = document.getElementById('works_find')
if (!works_find) {
return
}
const insertDivAndAutoDownload = function () {
const mod_auto_export_all_area = document.getElementById('mod_auto_export_all_area')
if (mod_auto_export_all_area) {
// すでに設定済みなので戻る
return true
}
const export_all_div = document.getElementById('export_all_div')
if (!export_all_div) {
// ダウンロードボタンが見つからないので戻る
return false
}
const span = isNaN(Number(localStorage.mod_auto_export_span)) ? 7 : Number(localStorage.mod_auto_export_span),
last_export = isNaN(Number(localStorage.mod_last_auto_export)) ? 0 : Number(localStorage.mod_last_auto_export),
current_time = (new Date).getTime()
if ((last_export + span * 24 * 60 * 60 * 1000) < current_time) {
// JSZipが準備できるまで待ってからダウンロードボタンを押す
const timer = setInterval(function () {
if (window.JSZip) {
const export_all = document.getElementById('export_all')
if (export_all) {
export_all.dispatchEvent(new Event('click'))
}
localStorage.mod_last_auto_export = current_time
clearInterval(timer)
}
}, 500)
}
export_all_div.insertAdjacentHTML('beforeend',`&nbsp;<span id="mod_auto_export_all_area">自動DL間隔&nbsp;<input id="mod_auto_export_span" type="number" min="1" max="99" value="${span}" placeholder="7" style="width:4rem;text-align:center">&nbsp;日</span>`)
const mod_auto_export_span = document.getElementById('mod_auto_export_span')
if (mod_auto_export_span) {
mod_auto_export_span.addEventListener('change', function () {
const new_span = Number(mod_auto_export_span.value)
localStorage.mod_auto_export_span = isNaN(new_span) ? 7 : new_span
})
}
return true
}
const targetNode = works_find.parentNode;
const observer = new MutationObserver(function(mutationsList, observer) {
for(const mutation of mutationsList) {
if (mutation.type === 'childList') {
if (insertDivAndAutoDownload()) {
break
}
}
}
})
insertDivAndAutoDownload()
observer.observe(targetNode, { attributes: false, childList: true, subtree: true })
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment