MCPcopy Create free account
hub / github.com/debbide/GeoFill / fillSelect

Function fillSelect

scripts/content.js:208–238  ·  view source on GitHub ↗

* 处理 select 元素(增强版)

(element, value)

Source from the content-addressed store, hash-verified

206 * 处理 select 元素(增强版)
207 */
208function fillSelect(element, value) {
209 const options = element.options;
210 const searchValue = value.toLowerCase();
211
212 // 首先尝试精确匹配
213 for (let i = 0; i < options.length; i++) {
214 const optionText = options[i].text.toLowerCase();
215 const optionValue = options[i].value.toLowerCase();
216
217 if (optionText === searchValue || optionValue === searchValue) {
218 element.selectedIndex = i;
219 element.dispatchEvent(new Event('change', { bubbles: true }));
220 return true;
221 }
222 }
223
224 // 然后尝试包含匹配
225 for (let i = 0; i < options.length; i++) {
226 const optionText = options[i].text.toLowerCase();
227 const optionValue = options[i].value.toLowerCase();
228
229 if (optionText.includes(searchValue) || optionValue.includes(searchValue) ||
230 searchValue.includes(optionText) || searchValue.includes(optionValue)) {
231 element.selectedIndex = i;
232 element.dispatchEvent(new Event('change', { bubbles: true }));
233 return true;
234 }
235 }
236
237 return false;
238}
239
240/**
241 * 处理 radio 按钮

Callers 2

fillFormFunction · 0.85
fillFormSmartFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected