CISTポータルの振り返りの文字数制限を超えても入力できるようにする
Twitterでは600文字を超えている部分文字列にマーカーが引かれる MDNに関連する記述があった
以下のように書けば良いだろうか?
code:remove_maxlength.js
const textareas = document.querySelectorAll("textarea");
const getLengthAsCRLF = (text) => {
const lengthAsCRLF = text.length + newlineCount;
return lengthAsCRLF;
}
textareas.forEach(textarea => {
const maxLength = textarea.maxLength;
const currentLengthBox = textarea.parentElement.querySelector("span:nth-of-type(1)");
/* Replace limitation logic of textarea length */
textarea.removeAttribute("maxlength");
textarea.addEventListener("change", e => {
const inputValue = e.target.value;
const lengthAsCRLF = getLengthAsCRLF(inputValue);
const isOverLength = lengthAsCRLF > maxLength
const validity = isOverLength ? この振り返りには、${inputValue}文字以下のメッセージのみ送信できます。 : "";
textarea.setCustomValidity(validity);
currentLengthBox.textContent = lengthAsCRLF;
});
});
code:helper_lecture.js
const getSubmenuTitle = () => {
return document.querySelector(".submenuttl")?.textContent ?? null
}
const isLecurePage = () => {
const title = getSubmenuTitle();
return title == "授業";
}
おおむねできたt6o_o6t.icon
現在文字数の誤った実装を無効化しなければ不可解な動作になる
change時ではなくkeydown時に処理することで回避できた
なぜcontent scriptが必ず後に実行されるのかは分からない
バックエンドにて、先頭と末尾の空白 / 改行が削除される仕様があったt6o_o6t.icon
バックエンドに保存する際に切り捨てられているものと考えられる
フロントエンドの文字数カウントも、事前にtrim()してから実行する必要がある
文字数制限を越えているときに送信をさせないのは難しい?t6o_o6t.icon
PortalのデフォルトのEventListenerに先回りして、ExtensionのEventListenerを登録できたと仮定した場合
この仮定を実現するのは難しい?
未検証
必須ではないため、考えないことにする