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