Skip to content

Instantly share code, notes, and snippets.

@koseki
Last active October 16, 2023 00:29
Show Gist options
  • Save koseki/d377f8f2e6df6655a1e160a4e03421d1 to your computer and use it in GitHub Desktop.
Save koseki/d377f8f2e6df6655a1e160a4e03421d1 to your computer and use it in GitHub Desktop.
macOS の Edge で Bing chat を使うと日本語入力確定時に勝手に送信されてしまう問題に対応する userscript
// ==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