-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoogletranslate-paster.js
43 lines (37 loc) · 1.6 KB
/
googletranslate-paster.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// ==UserScript==
// @name Auto Paste Clipboard to Google Translate (Japanese Only)
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Continuously check the clipboard and paste Japanese text into the Google Translate input box.
// @match https://translate.google.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let lastClipboardText = '';
// Function to check if the text contains Japanese characters
function isJapanese(text) {
// This regex checks for the presence of Hiragana, Katakana, or Kanji characters.
const japaneseRegex = /[\u3040-\u30FF\u4E00-\u9FFF]/;
return japaneseRegex.test(text);
}
// Function to paste clipboard content into the textarea
function pasteClipboard() {
// Find the text area for input
const textArea = document.querySelector('textarea.er8xn');
if (textArea) {
// Read the clipboard content
navigator.clipboard.readText().then(clipText => {
if (clipText && clipText !== lastClipboardText && isJapanese(clipText)) {
// Update the text area value and trigger an input event if the text is Japanese
textArea.value = clipText;
textArea.dispatchEvent(new Event('input', { bubbles: true }));
// Save the current clipboard text to avoid duplicate pasting
lastClipboardText = clipText;
}
});
}
}
// Check clipboard content every second
setInterval(pasteClipboard, 1000);
})();