Skip to content

Instantly share code, notes, and snippets.

@whiteball
Last active March 30, 2022 09:29
Show Gist options
  • Save whiteball/1f46b7b9bb6dbefed302be6baafb091a to your computer and use it in GitHub Desktop.
Save whiteball/1f46b7b9bb6dbefed302be6baafb091a to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AIのべりすと ローカル作品データをすべてエクスポート
// @namespace https://ai-novelist-share.geo.jp/
// @version 0.1.2
// @description 作品リストページにローカルのデータをZIPでまとめてエクスポートするボタンを検索ボックスの上に追加します。※cloudflareのCDNからJSZipを読み込んできます。
// @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/1f46b7b9bb6dbefed302be6baafb091a/raw/ai_novelist_local_download.user.js
// @downloadURL https://gist.github.com/whiteball/1f46b7b9bb6dbefed302be6baafb091a/raw/ai_novelist_local_download.user.js
// @supportURL https://gist.github.com/whiteball/1f46b7b9bb6dbefed302be6baafb091a
// @grant none
// ==/UserScript==
(function() {
'use strict';
const element = document.createElement('script')
element.src = 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.7.1/jszip.min.js'
document.head.append(element)
const search_area = document.getElementById('works_find')
if (search_area) {
search_area.insertAdjacentHTML('beforebegin', `<div style="max-width:500px; color:#777777; margin-top: 5px; margin-left:14vw;"><button id="export_all">ZIPですべてエクスポート</button></div>`)
const export_all = document.getElementById('export_all')
export_all.addEventListener('click', function () {
const now = new Date(),
date_str = '_' + now.getFullYear() + ('0' + (now.getMonth()+1)).slice(-2) + ('0' + now.getDate()).slice(-2) + now.getHours() + now.getMinutes() + now.getSeconds(),
zip = new JSZip(),
folder = zip.folder('AIのべりすと作品データ' + date_str),
max_id = Number(localStorage.max_works_id)
for (let i = 0; i <= max_id; i++) {
const item =localStorage.getItem('works' + i)
if (item) {
const temp = item.split('<|endofsection|>'),
title = temp[6].replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, '')
folder.file('ID' + i + '_' + title + '.novel', item)
}
}
zip.generateAsync({type:'blob'}).then(function (blob) {
const a = document.createElement('a')
a.href = URL.createObjectURL(blob)
document.body.appendChild(a)
a.download = 'AIのべりすと作品データ' + date_str + '.zip'
a.click()
document.body.removeChild(a)
URL.revokeObjectURL(a.href)
})
})
}
const refreshlist_remote_orig = window.refreshlist_remote
window.refreshlist_remote = function () {
refreshlist_remote_orig()
const export_all = document.getElementById('export_all')
if (export_all) {
export_all.style.display = 'none'
}
}
const refreshlist_orig = window.refreshlist
window.refreshlist = function () {
refreshlist_orig()
const export_all = document.getElementById('export_all')
if (export_all) {
export_all.style.display = ''
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment