Last active
January 15, 2021 15:06
-
-
Save optozorax/6fa9ad98ff653846246f4fc0b1921397 to your computer and use it in GitHub Desktop.
kg script for new layout
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 KG show tips how to type with new layout | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author You | |
// @match http://klavogonki.ru/* | |
// @grant none | |
// ==/UserScript== | |
let english_russian_leters = { | |
"x": "х", | |
"y": "у", | |
"p": "р", | |
"a": "а", | |
"o": "о", | |
"c": "с", | |
}; | |
let obj = { | |
// левая рука: | |
"по": [1], | |
"цо": [1], | |
"ко": [1], | |
"мо": [1], | |
"во": [1], | |
"чо": [1], | |
"со": [1], | |
// правая рука: | |
"га": [2], | |
"на": [2], | |
"та": [2], | |
"жа": [2], | |
"ра": [2], | |
"да": [2], | |
"ла": [2], | |
"фа": [2], | |
"ха": [2], | |
"ша": [2], | |
"ба": [2], | |
// фенеходинамика: | |
// левая: | |
"её": [3], | |
"ее": [3], | |
"ые": [3], | |
"ие": [3], | |
// правая: | |
"за": [3], | |
"ью": [3], | |
}; | |
let exceptions = { | |
"она": ["о", "н", "а"], | |
}; | |
function change(current_word) { | |
current_word = current_word.split('').map(x => { | |
let new_letter = english_russian_leters[x]; | |
if (new_letter === undefined) { | |
return x; | |
} else { | |
return new_letter; | |
} | |
}).join(''); | |
let result = []; | |
let exception = exceptions[current_word]; | |
if (exception) { | |
for (let piece of exception) { | |
let color = obj[piece]; | |
if (color !== undefined) { | |
color = color[0]; | |
result.push({color, piece}); | |
} else { | |
result.push({color: 0, piece}); | |
} | |
} | |
} else { | |
while (current_word.length != 0) { | |
if (current_word.length >= 2) { | |
let piece = current_word.charAt(0) + current_word.charAt(1); | |
let color = obj[piece]; | |
if (color !== undefined) { | |
color = color[0]; | |
result.push({color, piece}); | |
current_word = current_word.substr(2); | |
} else { | |
result.push({color: 0, piece: current_word[0]}); | |
current_word = current_word.substr(1); | |
} | |
} else { | |
result.push({color: 0, piece: current_word[0]}); | |
current_word = current_word.substr(1); | |
} | |
} | |
} | |
let s = "<span id='racing_time'>"; | |
for (let elem of result) { | |
if (elem.color == 0) { | |
s += elem.piece; | |
} else if (elem.color == 1) { | |
s += "<span style='color: #0000FF;'>" + elem.piece + "</span>"; | |
} else if (elem.color == 2) { | |
s += "<span style='color: #FF0000;'>" + elem.piece + "</span>"; | |
} else { | |
s += "<span style='color: #00FF00;'>" + elem.piece + "</span>"; | |
} | |
} | |
s += "</span>"; | |
var div = document.createElement('div'); | |
div.innerHTML = "<div style='float: right; font-size: 2em'>" + s + "</div>"; | |
return div; | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
async function demo() { | |
let previous_word = ""; | |
while (true) { | |
let doc = document.getElementById("typefocus"); | |
if (doc) { | |
let current_word = Array.from(doc.childNodes).filter(function(element, index, array) { return (index % 2 === 0); }).map(elem => elem.textContent).join(""); | |
if (current_word != previous_word) { | |
previous_word = current_word; | |
var select = document.getElementById("racing"); | |
if (select.lastChild.localName == "div") { | |
select.removeChild(select.lastChild); | |
} | |
document.getElementById("racing").appendChild(change(current_word)); | |
} | |
} | |
await sleep(100); | |
} | |
} | |
(async function() { | |
'use strict'; | |
await demo(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment