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