1(function () { 2 /** 3 * â¼å®åã§å¤æ´ããããè¨å® 4 */ 5 6 // ãè¦å¤æ´ãé·ç§»å ãã¼ã¸å´ã¨åããã¼ã«ãã 7 const STORAGE_KEY = 'prev_page_title'; 8 9 const TITLE_TO_OPTION = [ 10 // ãè¦å¤æ´ã 11 // keyword: é·ç§»å ãã¼ã¸ã®<title>ã«å«ã¾ãã¦ãããåå¿ããããæåå 12 // optionText: ãã©ã¼ã ã®ãã«ãã¦ã³ã§é¸ã°ããã表示æåå 13 { keyword: 'ãã¸ã«ã«ã·ã³ãã³ã°', optionText: 'ãã¸ã«ã«ã·ã³ãã³ã°' }, 14 { keyword: 'ãã¼ã±ãã£ã³ã°', optionText: 'ãã¼ã±ãã£ã³ã°' }, 15 { keyword: 'ãã¬ã¼ã³ãã¼ã·ã§ã³ã¨ãã¸ã«ã«ã©ã¤ãã£ã³ã°', optionText: 'ãã¬ã¼ã³ãã¼ã·ã§ã³ã¨ãã¸ã«ã«ã©ã¤ãã£ã³ã°' } 16 ]; 17 18 // ãè¦å¤æ´ããã©ã¼ã é ç®ã®ã©ãã«å 19 const FIELD_LABEL_TEXT = 'ãåãåãããµã¼ãã¹'; 20 21 function normalize(str) { 22 return (str || '').replace(/\s+/g, '').trim(); 23 } 24 25 function getOptionTextFromStoredTitle() { 26 const prevTitle = localStorage.getItem(STORAGE_KEY) || ''; 27 const hit = TITLE_TO_OPTION.find(item => 28 prevTitle.includes(item.keyword) || prevTitle.includes(item.optionText) 29 ); 30 return hit ? hit.optionText : null; 31 } 32 33 function findSelectByLabelText(labelText) { 34 const labels = Array.from(document.querySelectorAll('label')); 35 36 for (const label of labels) { 37 if (!normalize(label.textContent).includes(normalize(labelText))) continue; 38 39 if (label.htmlFor) { 40 const el = document.getElementById(label.htmlFor); 41 if (el && el.tagName === 'SELECT') return el; 42 } 43 44 // ãç°å¢ã«ãã調æ´åè£ã 45 const group = label.closest('.satori__input_group, .form-group, .field, div, li'); 46 const selectInGroup = group ? group.querySelector('select') : null; 47 if (selectInGroup) return selectInGroup; 48 49 const selectInParent = label.parentElement 50 ? label.parentElement.querySelector('select') 51 : null; 52 if (selectInParent) return selectInParent; 53 } 54 55 return null; 56 } 57 58 function setSelectByVisibleText(select, optionText) { 59 const options = Array.from(select.options); 60 const target = options.find(opt => { 61 const text = normalize(opt.textContent); 62 63 // ç¾å¨ã¯ãå®å ¨ä¸è´ or é¨åä¸è´ã 64 return text === normalize(optionText) || text.includes(normalize(optionText)); 65 }); 66 67 if (!target) return false; 68 69 select.value = target.value; 70 target.selected = true; 71 72 select.dispatchEvent(new Event('input', { bubbles: true })); 73 select.dispatchEvent(new Event('change', { bubbles: true })); 74 75 return true; 76 } 77 78 function lockSelect(select, lockedValue) { 79 if (select.dataset.autoLocked === '1') return; 80 select.dataset.autoLocked = '1'; 81 82 const restoreValue = () => { 83 if (select.value !== lockedValue) { 84 select.value = lockedValue; 85 select.dispatchEvent(new Event('input', { bubbles: true })); 86 select.dispatchEvent(new Event('change', { bubbles: true })); 87 } 88 }; 89 90 select.style.pointerEvents = 'none'; 91 select.style.backgroundColor = '#f5f5f5'; 92 select.style.cursor = 'not-allowed'; 93 select.setAttribute('tabindex', '-1'); 94 select.setAttribute('aria-readonly', 'true'); 95 96 select.addEventListener('change', restoreValue); 97 select.addEventListener('input', restoreValue); 98 select.addEventListener('keydown', function (e) { e.preventDefault(); }); 99 select.addEventListener('mousedown', function (e) { e.preventDefault(); }); 100 select.addEventListener('focus', function () { select.blur(); }); 101 102 restoreValue(); 103 } 104 105 function applyAutoSelect() { 106 const targetOptionText = getOptionTextFromStoredTitle(); 107 if (!targetOptionText) return false; 108 109 const select = findSelectByLabelText(FIELD_LABEL_TEXT); 110 if (!select) return false; 111 112 const setOk = setSelectByVisibleText(select, targetOptionText); 113 if (!setOk) return false; 114 115 lockSelect(select, select.value); 116 return true; 117 } 118 119 let applied = false; 120 121 function tryApply() { 122 if (applied) return; 123 applied = applyAutoSelect(); 124 } 125 126 if (document.readyState === 'loading') { 127 document.addEventListener('DOMContentLoaded', tryApply); 128 } else { 129 tryApply(); 130 } 131 132 const observer = new MutationObserver(function () { 133 tryApply(); 134 if (applied) observer.disconnect(); 135 }); 136 137 observer.observe(document.body, { 138 childList: true, 139 subtree: true 140 }); 141 142 setTimeout(tryApply, 500); 143 setTimeout(tryApply, 1500); 144 setTimeout(tryApply, 3000); 145})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.