Skip to content

Instantly share code, notes, and snippets.

@whiteball
Last active November 28, 2023 15:39
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/6250defee06ade23b8781bf96435ead3 to your computer and use it in GitHub Desktop.
Save whiteball/6250defee06ade23b8781bf96435ead3 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name AIのべりすと 保存時にお知らせがにゅっと出る
// @namespace https://ai-novelist-share.geo.jp/
// @version 0.2.0
// @description ローカル、またはリモートに保存が実行されたとき、右下に時限で消えるポップアップを出します。なお、ストレージがいっぱいなどの理由で保存時にエラーが出た場合でも、「保存しました」と表示されますが、仕様です。
// @author しらたま
// @match https://ai-novel.com/novel*.php
// @icon https://www.google.com/s2/favicons?sz=64&domain=ai-novel.com
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.js
// @updateURL https://gist.github.com/whiteball/6250defee06ade23b8781bf96435ead3/raw/ai_novelist_toast_on_save.user.js
// @downloadURL https://gist.github.com/whiteball/6250defee06ade23b8781bf96435ead3/raw/ai_novelist_toast_on_save.user.js
// @supportURL https://gist.github.com/whiteball/6250defee06ade23b8781bf96435ead3
// @grant none
// ==/UserScript==
/*
更新履歴
2023/11/29 0.2.0 右下にサイドメニュー開閉ボタンがあるときは、それを避けてポップアップが出現するように調整。
*/
(function() {
'use strict';
document.getElementsByTagName('head')[0].insertAdjacentHTML('beforeend', `<link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.css" rel="stylesheet">`)
const formatTime = function (dateTime, no_delimiter = false) {
const time_del = no_delimiter ? '' : ':'
return ('0' + dateTime.getHours()).slice(-2) + time_del + ('0' + dateTime.getMinutes()).slice(-2) + time_del + ('0' + dateTime.getSeconds()).slice(-2)
}
let localToast = undefined, remoteToast = undefined
const showLocalToast = function (message) {
if (localToast) {
// まだトーストが非表示になっていないなら、そのトーストの内容を書き換える
const exist = document.querySelector('.jq-toast-wrap div[style*="rgb(236, 180, 60)"]:not([style*="display: none"])')
if (exist) {
exist.childNodes[2].nodeValue = 'ローカル保存しました(' + formatTime(new Date()) + ')'
return
}
localToast.reset()
}
localToast = window.jQuery.toast({
text: 'ローカル保存しました(' + formatTime(new Date()) + ')',
showHideTransition: 'slide',
allowToastClose: true,
hideAfter: 2000,
stack: 2,
position: 'bottom-right',
bgColor: '#ecb43c',
textColor: '#404040',
textAlign: 'left',
loader: false,
loaderBg: '#9EC600',
})
const fixed_bottom_right = document.getElementsByClassName('fixed_bottom_right')
if (fixed_bottom_right.length > 0) {
const exist = document.querySelector('.jq-toast-wrap.bottom-right')
if (exist) {
exist.style.right = `${60 + fixed_bottom_right[0].clientWidth}px`
}
}
}
const showRemoteToast = function (message) {
if (remoteToast) {
remoteToast.reset()
}
remoteToast = window.jQuery.toast({
text: 'リモート保存しました(' + formatTime(new Date()) + ')',
showHideTransition: 'slide',
allowToastClose: true,
hideAfter: 4000,
stack: 2,
position: 'bottom-right',
bgColor: '#3cece0',
textColor: '#2e2e2e',
textAlign: 'left',
loader: false,
loaderBg: '#9EC600',
})
const fixed_bottom_right = document.getElementsByClassName('fixed_bottom_right')
if (fixed_bottom_right.length > 0) {
const exist = document.querySelector('.jq-toast-wrap.bottom-right')
if (exist) {
exist.style.right = `${60 + fixed_bottom_right[0].clientWidth}px`
}
}
}
const originalAjax = window.jQuery.ajax
window.jQuery.ajax = function (param) {
if (param.type === 'POST' && param.data) {
if (param.url === '_remotestories.php') {
showRemoteToast()
}
}
return originalAjax(param)
}
const originalStorageSetItem = Storage.prototype.setItem
Storage.prototype.setItem = function (key, value) {
const work_id = localStorage.getItem('current_works_id')
if (this === localStorage && key === 'works' + work_id) {
showLocalToast()
}
return originalStorageSetItem.bind(this)(key, value)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment