Last active
October 15, 2023 13:12
-
-
Save whiteball/17b85e1ed55542e94a4298ad9e1e8481 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.4 | |
// @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/17b85e1ed55542e94a4298ad9e1e8481/raw/ai_novelist_prevent_scroll.user.js | |
// @downloadURL https://gist.github.com/whiteball/17b85e1ed55542e94a4298ad9e1e8481/raw/ai_novelist_prevent_scroll.user.js | |
// @supportURL https://gist.github.com/whiteball/17b85e1ed55542e94a4298ad9e1e8481 | |
// @grant none | |
// ==/UserScript== | |
/* | |
更新履歴 | |
2023/10/15 本文の装飾タグ表示がブロックされていたのを修正。 | |
2023/05/15 そもそもスクロールバーの幅の計算方法が間違っていたのを修正。 | |
2023/05/02 まだスクロールバーを消したときに本文の入力枠の横幅が変わってしまうのを改善。 | |
2023/04/26 スクロールバーを消したときに本文の入力枠の横幅が変わってしまうのを修正。 | |
*/ | |
(function() { | |
'use strict'; | |
const data_container = document.getElementById('data_container') | |
if (!data_container) { | |
return | |
} | |
let barWidth = 0 | |
const disableBar = function () { | |
data_container.style.overflow = 'hidden' | |
data_container.style['padding-right'] = '' + (barWidth + 9.05) + 'px' | |
data_container.style['overscroll-behavior-block'] = 'auto' | |
}, enableBar = function () { | |
data_container.style.overflow = 'visible auto' | |
data_container.style['padding-right'] = '15px' | |
barWidth = data_container.offsetWidth - data_container.clientWidth | |
data_container.style['overscroll-behavior-block'] = 'none' | |
} | |
const installFocusEvent = function () { | |
for (const data_edit of document.getElementsByClassName('data_edit')) { | |
data_edit.addEventListener('focus', enableBar) | |
data_edit.addEventListener('blur', disableBar) | |
} | |
if (document.activeElement.className === 'data_edit') { | |
enableBar() | |
} else { | |
disableBar() | |
} | |
} | |
const originalTextSharding = window.TextSharding | |
window.TextSharding = function TextSharding(orig_text = null,nospan = true,noscroll = false, tagreplace = 0) { | |
originalTextSharding(orig_text, nospan, noscroll, tagreplace) | |
installFocusEvent() | |
} | |
installFocusEvent() | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment