Skip to content

Instantly share code, notes, and snippets.

@xnuk
Last active May 13, 2023 06:24
Show Gist options
  • Save xnuk/ff8d198deabdb52d55516881db76faf9 to your computer and use it in GitHub Desktop.
Save xnuk/ff8d198deabdb52d55516881db76faf9 to your computer and use it in GitHub Desktop.
Colemak-DH + 3-P2
(r=>{const x=t=>(t=typeof t=="number"?t:t.charCodeAt(0),4352<=t&&t<=4607||12592<=t&&t<=12687||44032<=t&&t<=55215),d=(t,f)=>{const a=Math.min(t.length,f.length),e=33,l=Array.from({length:126-e+1},(s,o)=>[o+e,0]);for(let s=0;s<a;++s){const o=f[s],n=t[s].charCodeAt(0);if(x(o)){const[u,i,c]=[...o.normalize("NFKD")].map(_=>_.charCodeAt(0));c!=null&&u===4363?(l[n-e]=[c,0],l[r.shift_table[n-e]-e]=[i,c]):i!=null?l[n-e]=[u,i]:l[n-e]=[u,0]}else o.charCodeAt(0)===n?l[n-e]=[n,0]:l[n-e]=[o.codePointAt(0),0]}return l};r.is_left_key=t=>{if(t<33||t>126)return!1;const a=r.find_current_layout_info().layout[t-33]?.[0];return a==null?!1:a>4447};const y={KE:"Ko",type_name:"Sin3-P2-Xnuk",full_name:"\uB51C\uB3C4 P2",layout:d([..."qwfpbjluy;",..."arstgmneio-",..."zxcdvkh,./"],[..."\uC5AB\uC584\uC571\uC5CD\uC604\u3139\u3137\u3141\uCD94\u314D",..."\uC735\uC60C\uC78F\uC55E\uC743\u3134\u3147\u3131\u3148\u3142\u314C",..."\uC768\uC6A8\uC5D1\uC63A\uC6C7\u3145\u314E,.\uCF54"])};r.eval("window.additional_layouts.push("+JSON.stringify(y)+")"),r.ohiChange("Ko","Sin3-P2-Xnuk")})(window);
// ==UserScript==
// @name 3-P2-Xnuk
// @version 1
// @grant none
// @match https://ohi.pat.im/*
// @run-at document-end
// @noframes
// ==/UserScript==
(window => {
/**
* @param {string | number} ch
* @returns {boolean}
*/
const isHangul = ch => {
ch = typeof ch === 'number' ? ch : ch.charCodeAt(0)
return 0x1100 <= ch && ch <= 0x11ff ||
0x3130 <= ch && ch <= 0x318f ||
0xac00 <= ch && ch <= 0xd7af
}
/**
* @param {string[]} base
* @param {string[]} into
* @returns {[number, number][]}
*/
const layout = (base, into) => {
const length = Math.min(base.length, into.length)
const offset = 0x21
/**
* @type {[number, number][]}
*/
const ret = Array.from(
{ length: 0x7e - offset + 1 },
(_, i) => [i + offset, 0],
)
for (let i = 0; i < length; ++i) {
const ch = into[i]
const bs = base[i].charCodeAt(0)
if (isHangul(ch)) {
const [first, second, third] =
[...ch.normalize('NFKD')].map(v => v.charCodeAt(0))
if (third != null && first === 0x110b) { // ㅇ
ret[bs - offset] = [third, 0]
ret[
window.shift_table[bs - offset] - offset
] = [second, third]
} else if (second != null) {
ret[bs - offset] = [first, second]
} else {
ret[bs - offset] = [first, 0]
}
} else if (ch.charCodeAt(0) === bs) {
ret[bs - offset] = [bs, 0]
} else {
ret[bs - offset] = [ch.codePointAt(0), 0]
}
}
return ret
}
window.is_left_key = key => {
if (key < 0x21 || key > 0x7e) return false
const current =
window.find_current_layout_info().layout
const cho = current[key - 0x21]?.[0]
if (cho == null) return false
return cho > 0x115f
}
const lay = {
KE: 'Ko', type_name: 'Sin3-P2-Xnuk', full_name: '딜도 P2',
layout: layout(
[...'qwfpbjluy;', ...'arstgmneio-', ...'zxcdvkh,./'],
[...'얫얄앱엍옄ㄹㄷㅁ추ㅍ', ...'융옌잏앞읃ㄴㅇㄱㅈㅂㅌ', ...'읨욨엑옺웇ㅅㅎ,.코'],
),
}
window.eval('window.additional_layouts.push(' + JSON.stringify(lay) + ')')
window.ohiChange('Ko', 'Sin3-P2-Xnuk')
})(unsafeWindow)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment