Skip to content

Instantly share code, notes, and snippets.

@souljazzfunk
Forked from koseki/bingchat-ime-fix.user.js
Last active February 24, 2023 14:03
Show Gist options
  • Select an option

  • Save souljazzfunk/5c9eeec65331fbac0a555e885dd11fa4 to your computer and use it in GitHub Desktop.

Select an option

Save souljazzfunk/5c9eeec65331fbac0a555e885dd11fa4 to your computer and use it in GitHub Desktop.
Prevent ChatGPT/BingChat from submitting LineBreak when using Japanese Input. 日本語変換の確定時に送信されないようにするためのChrome拡張機能です。ChatGPTとBing Chatで使えます。
{
"name": "No-IME-Submit for ChatGPT / Bing Chat",
"version": "1.0",
"manifest_version": 3,
"description": "Prevent ChatGPT/BingChat from submitting LineBreak when using Japanese Input",
"host_permissions": [
"https://chat.openai.com/*",
"https://www.bing.com/*"
],
"content_scripts": [
{
"matches": [
"https://chat.openai.com/*",
"https://www.bing.com/*"
],
"js": ["noIMESubmit.js"]
}
]
}
(function() {
const hostname = window.location.hostname
const suppressSubmit = () => {
let input
let isLastKeyDownIME = false
// console.log(hostname)
if (hostname === 'www.bing.com') {
input = document.getElementsByClassName('cib-serp-main')[0].shadowRoot.getElementById("cib-action-bar-main").shadowRoot.getElementById('searchbox')
}
else if (hostname === 'chat.openai.com') {
input = document.querySelector('textarea')
}
input.addEventListener('keydown', e => {
// console.log('DOWN: ' + e.key, e.keyCode, e.isComposing)
if(e.isComposing) {
isLastKeyDownIME = true
if(e.key === 'Enter') {
e.stopPropagation()
// console.log('IME Enter: DOWN')
}
}
}, true)
input.addEventListener('keyup', e => {
// console.log('UP: ' + e.key, e.keyCode, e.isComposing)
if(e.key === 'Enter' && isLastKeyDownIME) {
e.stopPropagation()
// console.log('IME Enter: UP')
}
}, true)
}
const waitForInput = (wait) => {
setTimeout(() => {
try {
suppressSubmit()
} catch (e) {
console.log(e)
if (wait < 5000) {
waitForInput(wait + 500)
}
}
}, wait)
}
waitForInput(500);
})()
@souljazzfunk
Copy link
Copy Markdown
Author

batman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment