JSでinputの変更を受信できない。

前提

下記リンクを参照してくれるとありがたいです。この記事で紹介されているスクリプトはVectorという外装の時のみ動きます。そこで、最新のVector 2022という外装でも改変し実装しようとしたのですが動かなくなってしまいました。

実現したいこと

上記記事の機能をVector 2022でも動作するようにする。

発生している問題・エラーメッセージ

検索ボックスに文字が挿入されない。

該当のソースコード

JavaScript

window.onload=function(){ document.querySelector('.wvui-input__input').oninput=function(){ var a=document.querySelector('.wvui-input__input'); //下記HTML5行目の要素 if((a.value.charAt('0'))=="/" || (a.value.charAt('0'))=="#"){ a.value=mw.config.get('wgPageName')+$('.wvui-input__input').val(); } if((a.value.substring(0,2))=="{{"){ a.value=a.value.replace(/\|(.*)}}/,'').replace('}}', '').substring(2,a.value.length); a.value='Template:'+$('.wvui-input__input').val(); } if((a.value.substring(0,2))=="./"){ var b=mw.config.get('wgPageName').split('/'); b.pop(); b.join("/"); a.value=b+"/"; } };};

HTML

<!-- 一部抜粋、インデントは自作 --> <form id="searchform" action="/index.php" class="wvui-typeahead-search__form"> <div class="wvui-typeahead-search__wrapper"> <div class="wvui-input wvui-input--has-start-icon wvui-typeahead-search__input"> <input type="search" name="search" autocapitalize="off" autocomplete="off" aria-autocomplete="list" aria-controls="searchform-suggestions" aria-activedescendant="" accesskey="f" article-path="/index.php" placeholder="○○内を検索" aria-label="○○内を検索" search-language="ja" class="wvui-input__input"> <span class="wvui-icon wvui-input__start-icon"> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><!----> <path fill="currentColor" d="M12.2 13.6a7 7 0 111.4-1.4l5.4 5.4-1.4 1.4-5.4-5.4zM3 8a5 5 0 1010 0A5 5 0 103 8z"></path> </svg> </span><!----> </div> <input type="hidden" name="title" value="特別:検索"> <input type="hidden" name="wprov" value="acrw1"> <ol id="searchform-suggestions" role="listbox" aria-label="検索結果" class="wvui-typeahead-search__suggestions"> <li role="option"> <a class="wvui-typeahead-search__suggestions__footer" id="searchform-suggestions-footer" tabindex="-1" href="/index.php?title=%E7%89%B9%E5%88%A5%3A%E6%A4%9C%E7%B4%A2&amp;fulltext=1&amp;search=%7B%7B"> <span class="wvui-icon wvui-typeahead-search__suggestions__footer__icon"> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" aria-hidden="true"><!----> <path fill="currentColor" d="M12.43 14.34A5 5 0 0110 15a5 5 0 113.95-2L17 16.09V3a2 2 0 00-2-2H5a2 2 0 00-2 2v14a2 2 0 002 2h10a2 2 0 001.45-.63z M13 10 A3 3 0 0 1 10 13 A3 3 0 0 1 7 10 A3 3 0 0 1 13 10 z"></path> </svg> </span> <span class="wvui-typeahead-search__suggestions__footer__text"> <span> <strong class="wvui-typeahead-search__suggestions__footer__text__query"></strong>を含むページを検索する </span> </span> </a> </li> </ol> </div> <button class="wvui-button wvui-button--action-default wvui-button--type-normal wvui-button--framed wvui-typeahead-search__submit">検索</button> </form>

試したこと

  • window.onload$(document).ready()の形にした

補足情報

-MediaWiki 1.38.4

コメントを投稿

0 コメント