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