使文本区域框可扩展的用户脚本

我经常使用带有大量文本区域框的网站,但愚蠢的是它们不可扩展,因此向其中添加大量文本(我经常这样做)感觉非常局促,并且比我想要的更困难成为。我想制作一个greasemonkey脚本/UserScript或某种javascript,我可以将其粘贴到Chrome控制台中以更改HTML/CSS的这一部分:

resize: none

到:

resize: true

这使得文本区域框底部有小抓手并解决了问题

https://img4.mukewang.com/64ded7f100013f0800800057.jpg

需要注意的一些事情是 1. 该网站似乎是从某种 CMS 动态生成的,2. 我无法更改此 CMS 上的任何内容。另外,我确信有更好的方法来问这个问题。

另一件事是,我想要的只是文本区域始终足够大以容纳所有文本,因此如果有一种方法可以自动扩展到文本,那就太好了。另外,如果 stackoverflow 新帖子文本框上有 textarea 抓取器那就太好了!

https://img4.mukewang.com/64ded7fd00016f1901620027.jpg

完整的示例代码如下,您将在其中找到“resize:none”非常感谢!


<!DOCTYPE html>

<html>

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Document</title>

</head>

<body>

<tr>

    <td valign="top" class="content_tab_bg_padding">

        <table cellspacing="0" cellpadding="0" border="0" width="100%">

            <tbody>

                <tr>

                    <td class="height2"></td>

                </tr>


                <tr>

                    <td class="form_label_text" valign="top">Gotta change this text box to be permanently expandable. Ideally automatically expandable. 

                    </td>

                </tr>

                <tr>

                    <td valign="top" width="100%" style="padding-top: 2px;">

                        <textarea

                            name="ctl00$ContentPlaceHolderPageContents$ctl00$ctl00$TextArea_CustomDocumentNoteGenerals_PersonPresent"

                            id="ctl00_ContentPlaceHolderPageContents_ctl00_ctl00_TextArea_CustomDocumentNoteGenerals_PersonPresent"

                            class="form_textareaWithoutWidth element" rows="4" style="width: 95%; resize: none;"

                            spellcheck="True" data-preventexpand="PreventExpand" tabindex="0"></textarea>

                    </td>

                </tr>

            </tbody>

        </table>

    </td>

</tr>

</body>

</html>


慕标5832272
浏览 106回答 1
1回答

杨魅力

这是基于您的帖子的示例:const textarea = document.querySelector('#ctl00_ContentPlaceHolderPageContents_ctl00_ctl00_TextArea_CustomDocumentNoteGenerals_PersonPresent');if (textarea) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// check if found&nbsp; textarea.style.resize = 'both';}更新评论textarea对于一页上的多个document.querySelectorAll('textarea').forEach(item => item.style.resize = 'both');
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript