Last active
October 16, 2023 00:29
-
-
Save koseki/d377f8f2e6df6655a1e160a4e03421d1 to your computer and use it in GitHub Desktop.
macOS の Edge で Bing chat を使うと日本語入力確定時に勝手に送信されてしまう問題に対応する userscript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Bing Chat IME fix | |
// @namespace https://gist.github.com/koseki/d377f8f2e6df6655a1e160a4e03421d1 | |
// @version 0.4 | |
// @description macOS の Edge で Bing chat を使うと日本語入力確定時に勝手に送信されてしまう問題の対応です | |
// @author koseki | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net | |
// @match https://www.bing.com/* | |
// @grant none | |
// ==/UserScript== | |
// Original: https://qiita.com/NOSP/items/81fc3ec5bb1b7dd3d561 | |
(function() { | |
'use strict'; | |
const setEventListeners = () => { | |
let lastKeyDownIME = false; | |
let input = document.getElementsByClassName('cib-serp-main')[0].shadowRoot.getElementById('cib-action-bar-main').shadowRoot.getElementById('searchbox'); | |
console.log('Bing Chat IME Fix: addEventListeners'); | |
input.addEventListener('keydown', e => { | |
// console.log(e.isComposing, e.key, e.keyCode); | |
if (e.isComposing) { | |
lastKeyDownIME = true; | |
if (e.key === 'Enter') { | |
e.stopPropagation(); | |
} | |
} else { | |
lastKeyDownIME = false; | |
} | |
}, true); | |
input.addEventListener('keyup', e => { | |
// console.log(e.isComposing, e.key, e.keyCode, lastKeyDownIME); | |
if (e.key === 'Enter' && lastKeyDownIME) { | |
e.stopPropagation(); | |
} | |
}, true); | |
}; | |
const waitInputField = (wait) => { | |
setTimeout(() => { | |
try { | |
setEventListeners(); | |
} catch { | |
if (wait < 5000) { | |
// console.log('waiting'); | |
waitInputField(wait + 500); | |
} | |
} | |
}, wait); | |
}; | |
waitInputField(500); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment