代码: 全选
改進以下代碼,要求:
一,把寫進textarea的方式改為用js string的方式。
二,css美化下面的幾個點擊按鈕和下載鏈接。
給出所有的代碼,不需要注釋,不能有空行。
```
<p>導入lime5:格式為</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-plain" data-lang="Plain Text"><code>@VERSION@哈哈倉頡
a|是|3
b|同|2
c|分|1</code></pre>
</div>
<p>導入ibus:用<code>ibus-table-createdb -s</code> 碼表,生成db之後,放進「/usr/share/ibus-table/tables/」,之後在設置->鍵盤裏面,就可以添加尹倉。</p>
<p>導入rime:把haha.schema.yaml和haha.rime.yaml放入rime目錄,再在default.custom.yaml加入:</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-plain" data-lang="Plain Text"><code>patch:
schema_list:
- {schema: haha}</code></pre>
</div>
<p>trime倉頡鍵盤:複製build/trime.yaml到上層目錄,再在「preset_keyboards:」添加:</p>
<div class="hcb_wrap">
<pre class="prism undefined-numbers lang-plain" data-lang="Plain Text"><code> haha:
ascii_mode: 0
author: "尹卂"
height: 50
name: "哈哈倉頡鍵盤"
keys: [{click: "Up", width: "25", height: "30"}, {click: "Down", width: "25", height: "30"}, {click: "Left", width: "25", height: "30"}, {click: "Right", width: "25", height: "30"}, {click: q, label: "手", long_click: "!"}, {click: w, label: "田", long_click: "@"}, {click: e, label: "水", long_click: "#"}, {click: r, label: "口", long_click: "$"}, {click: t, label: "廿", long_click: "%"}, {click: y, label: "卜", long_click: "^"}, {click: u, label: "山", long_click: "&"}, {click: i, label: "戈", long_click: "*"}, {click: o, label: "人", long_click: "("}, {click: p, label: "心", long_click: ")"}, {width: 5}, {click: a, label: "日", long_click: "`"}, {click: s, label: "尸", long_click: "~"}, {click: d, label: "木", long_click: "-"}, {click: f, label: "火", long_click: "_"}, {click: g, label: "土", long_click: "="}, {click: h, label: "竹", long_click: "+"}, {click: j, label: "十", long_click: ";"}, {click: k, label: "大", long_click: ":"}, {click: l, label: "中", long_click: "'"}, {click: Shift_L, send_bindings: false, width: "15"}, {click: z, label: "重", long_click: "\""}, {click: x, label: "難", long_click: "{"}, {click: c, label: "金", long_click: "}"}, {click: v, label: "女", long_click: "|"}, {click: b, label: "月", long_click: "\\"}, {click: n, label: "弓", long_click: "["}, {click: m, label: "一", long_click: "]"}, {click: BackSpace, width: 15}, {click: Mode_switch, width: "15"}, {click: Keyboard_symbols}, {ascii: ",", click: ",", long_click: "<"}, {click: space, width: 30}, {ascii: ".", click: ".", long_click: ">"}, {ascii: "/", click: "/", long_click: "?"}, {click: Return, composing: Return1, long_click: Escape, width: 15}]
width: 10</code></pre>
</div>
<p><style>
.hide {display: none;}
</style> <button id="resetButton">清空並復原</button><br /><br /><label id="selectcinfilelabel" for="cinfile">【碼表選擇】</label> <input class="hide" id="cinfile" type="file" accept=".txt,.cin" /><br /><br /></p>
<div class="hide"><label for="rimeschema">Rime Schema 內容:</label><br /><textarea id="rimeschema" rows="10" cols="50"># haha.schema.yaml
#
schema:
schema_id: haha
name: "哈哈倉頡"
version: "4"
author: "尹卂"
description: "https://ejsoon.vip/haha"
engine:
processors:
- ascii_composer
- speller
- selector
- punctuator
- express_editor
segmentors:
- ascii_segmentor
- abc_segmentor
- punct_segmentor
- fallback_segmentor
translators:
- punct_translator
- table_translator
switches:
- name: ascii_mode
reset: 0
states: [ 中文, 西文 ]
- name: ascii_punct
states: ["。,", ".,"]
translator:
dictionary: haha
enable_completion: false
enable_user_dict: false
enable_sentence: false
preedit_format:
- xform/^([a-z]*)$/\U$1\E/
#- xform/^([a-z]*)$/$1|\U$1\E/
- "xlit|ABCDEFGHIJKLMNOPQRSTUVWXYZ|日月金木水火土竹戈十大中一弓人心手口尸廿山女田難卜重|"
comment_format:
- "xlit|abcdefghijklmnopqrstuvwxyz~|日月金木水火土竹戈十大中一弓人心手口尸廿山女田難卜重~|"
menu:
page_size: 9
alternative_select_keys: " ;'456789"
punctuator:
full_shape:
",": {commit: ","}
".": {commit: "。"}
"/": {commit: "、"}
"!": {commit: "!"}
"@": {commit: "•"}
"^": {commit: "……"}
"$": {commit: "¥"}
"_": {commit: "——"}
"-": {commit: "―"}
"|": {commit: "︱"}
"?": {commit: "?"}
":": {commit: ":"}
";": {commit: ";"}
"[": {commit: "「"}
"]": {commit: "」"}
"{": {commit: "『"}
"}": {commit: "』"}
"(": {commit: "("}
")": {commit: ")"}
"\"": {commit: "“”"}
"'": {commit: "‘’"}
"<": {commit: "《"}
">": {commit: "》"}
half_shape:
",": {commit: ","}
".": {commit: "。"}
"/": {commit: "、"}
"!": {commit: "!"}
"@": {commit: "•"}
"^": {commit: "……"}
"$": {commit: "¥"}
"_": {commit: "——"}
"-": {commit: "―"}
"|": {commit: "︱"}
"?": {commit: "?"}
":": {commit: ":"}
";": {commit: ";"}
"[": {commit: "「"}
"]": {commit: "」"}
"{": {commit: "『"}
"}": {commit: "』"}
"(": {commit: "("}
")": {commit: ")"}
"\"": {commit: "“”"}
"'": {commit: "‘’"}
"<": {commit: "《"}
">": {commit: "》"}
</textarea><br /><br /><label for="rimedict">Rime Dict 內容:</label><br /><textarea id="rimedict" rows="10" cols="50"># haha.dict.yaml
#
---
name: haha
version: "1"
sort: original
...
# no comment
</textarea><br /><br /><label for="ibustmp">IBus 模板內容:</label><br /><textarea id="ibustmp" rows="10" cols="50">### File header must not be modified
### This file must be encoded into UTF-8.
### This table under LGPL
### comments start with ### not single #
### Derive from the format of SCIM Table, so you can modify the table from
### scim-tables' table
Ejsoon_Cangjie_Table_Phrase_Library_TEXT
VERSION_202208
### Begin Table definition.
BEGIN_DEFINITION
### License
LICENSE = LGPL
### An unique id to distinguish this table among others.
### Use uuidgen to generate this kind of id.
UUID = 41d16dbb-3765-4b30-8547-9fc7379930f1
### A unique number indicates the version of this file.
### For example the last modified date of this file.
### This number must be less than 2^32.
### Just make your table version-able
SERIAL_NUMBER = 20220805
### ICON can be any format as long as your pygtk can recognized
### the most widely ones are "png" and "svg", letter one is recommended
ICON = ibus-table.svg
### The symbol to be displayed in IM switchers
SYMBOL = 尹
### The default name of this table, this is needed
NAME = Table
### The local names of this table, this is optional
NAME.zh_CN = 尹倉
NAME.zh_HK = 尹倉
NAME.zh_TW = 尹倉
### Description
DESCRIPTION = This is a template engine table for IBus Table.
### Supported languages of this table
### sigle "zh_CN" just be recognized as zh_CN,
### but "zh_CN, zh_HK" or more zh_XX will be recognized as zh;
### and "en_US, zh_CN" will be just ignored.
LANGUAGES = zh_CN,zh_SG,zh_TW,zh_HK
### The author of this table
AUTHOR = Ejsoon <ejsoon@outlook.com>
### Prompt string to be displayed in the status area, CN will be replaced by
### the gettext tools in runtime as 中.
STATUS_PROMPT = CN
### Valid input chars.
VALID_INPUT_CHARS = abcdefghijklmnopqrstuvwxyz
### Layout
LAYOUT = us
### The max number of input keys for every phrase or character.
MAX_KEY_LENGTH = 4
### Use auto_commit mode as default
AUTO_COMMIT = FALSE
### Automatically selects the first phrase when typing
AUTO_SELECT = FALSE
### Use full width punctuation by default
DEF_FULL_WIDTH_PUNCT = TRUE
### Not use full width letter by default
DEF_FULL_WIDTH_LETTER = FALSE
### Whether user are allow to define phrase, default is true
### You have to define the word construction rules below.
### For input methods which do not input phrases, set this to False
USER_CAN_DEFINE_PHRASE = FALSE
### Whether support PinYin Mode, default is true.
### this feature is just for Chinese, set it to False if your IM is not
### Chinese.
PINYIN_MODE = FALSE
### If true then the phrases' frequencies will be adjusted dynamically
### according your using frequency.
DYNAMIC_ADJUST = FALSE
### Some characters whose frequencies should be fix all the time, e.g.
### some punctuations
### NO_CHECK_CHARS =
### Rules for constructing user defined phrase
### "ce" stands for "ci equal", a Chinese English :), means "phrase length
### equal to", thus ce2 -> phrase length equal to 2; and "ca" means "phrase
### length equal or above", so ca4 -> phrase length equal or above 4.
### p21 -> the 1st key of 2nd character in the phrase, and so on.
### Each rule separate via ";".
### Example below is a complete rule-set,
### becuase [2,2] ∩ [3,3] ∩ [4,+∞] = [2,+∞], which is the range of length
### of phrase. This have to be satisfied if you need ibus-table to build up
### your own inputed phrase via your daily using.
RULES = ce2:p11+p12+p21+p22;ce3:p11+p21+p22+p31;ca4:p11+p21+p31+p41
### The key strokes to page up the lookup table.
PAGE_UP_KEYS = Page_Up,KP_Page_Up,minus,comma
### The key strokes to page down.
PAGE_DOWN_KEYS = Page_Down,KP_Page_Down,equal,period
### The key strokes to select candidiate phrases.
### Usually "1,2,3,4,5,6,7,8,9" but if this conflicts with
### characters one wants to use for input one can also
### use something like “F1,F2,F3,F4,F5,F6,F7,F8,F9”
SELECT_KEYS = 1,semicolon,apostrophe,4,5,6,7,8,9
### The default orientation of the candidate list
### TRUE means the candidate list is vertical, FALSE means it is vertical
ORIENTATION=FALSE
END_DEFINITION
### Begin Table data.
### Format of every line whose formated in "input_keys\tphrase\tfreq\n" is an
### entry.
### From left to right, the 1st column are the input key combination that you
### entered via keyboard; the 2nd column are presented character or phrase of
### the key combination you want; the 3rd column are frequency of the character
### or phrase.
BEGIN_TABLE
a 日 20902
a 曰 20901
...
yyyb 髙 1
END_TABLE</textarea><br /><br /></div>
<div id="downloadLinks"></div>
<p><script>
var UUID=(()=>{var e=[];for(let t=0;t<256;++t)e.push((t+256).toString(16).slice(1));function m(t,r=0){return(e[t[r+0]]+e[t[r+1]]+e[t[r+2]]+e[t[r+3]]+"-"+e[t[r+4]]+e[t[r+5]]+"-"+e[t[r+6]]+e[t[r+7]]+"-"+e[t[r+8]]+e[t[r+9]]+"-"+e[t[r+10]]+e[t[r+11]]+e[t[r+12]]+e[t[r+13]]+e[t[r+14]]+e[t[r+15]]).toLowerCase()}var u,l=new Uint8Array(16);function a(){if(!u){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");u=crypto.getRandomValues.bind(crypto)}return u(l)}var x=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),i={randomUUID:x};function c(t,r,o){if(i.randomUUID&&!r&&!t)return i.randomUUID();t=t||{};let n=t.random??t.rng?.()??a();if(n.length<16)throw new Error("Random bytes length must be >= 16");if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,r){if(o=o||0,o<0||o+16>r.length)throw new RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`);for(let d=0;d<16;++d)r[o+d]=n[d];return r}return m(n)}var p=c;window.uuidv4=p;})();
document.getElementById('cinfile').addEventListener('change', handleFileSelect);
function handleFileSelect(event) {
const file = event.target.files[0];
if (!file) return;
document.getElementById('selectcinfilelabel').classList.add("hide");
const reader = new FileReader();
reader.onload = function(e) {
const content = e.target.result;
const versionMatch = content.match(/%version\s+(.+)/);
const fileVersion = versionMatch ? versionMatch[1].trim() : yyyymmdd;
const cinfilename = file.name;
const topname = cinfilename.split('_')[0];
// 生成 .schema.yaml
let schemaContent = document.getElementById('rimeschema').value;
schemaContent = removebr(schemaContent).replace(/(version:\s*)"\d*"/, `$1"${fileVersion}"`);
createDownloadLink(`${topname}.schema.yaml`, schemaContent);
// 處理 .dict.yaml
let rimedictvalue = document.getElementById('rimedict').value;
rimedictvalue = removebr(rimedictvalue).replace(/(version:\s*)"\d*"/, `$1"${fileVersion}"`);
const chardefContent = extractChardef(content);
const cinforrime = chardefContent
.split('\n')
.filter(line => line.trim())
.map(line => {
const [left, right] = line.split('\t');
return `${right}\t${left}`;
})
.join('\n');
const dictContent = rimedictvalue + '\n' + cinforrime;
createDownloadLink(`${topname}.dict.yaml`, dictContent);
// 生成 ibus 碼表
let ibustmpvalue = document.getElementById('ibustmp').value;
ibustmpvalue = removebr(ibustmpvalue);
// 更新 VERSION
const fileVerRe = fileVersion.replace('_', '');
ibustmpvalue = ibustmpvalue.replace(/(VERSION_)\d+/, `$1${fileVerRe}`);
// 更新 UUID
const newUuid = uuidv4();
ibustmpvalue = ibustmpvalue.replace(/(UUID = ).+/, `$1${newUuid}`);
// 更新 SERIAL_NUMBER
ibustmpvalue = ibustmpvalue.replace(/(SERIAL_NUMBER = )\d+/, `$1${fileVerRe}`);
// 處理碼表內容
const tableLines = chardefContent.split('\n').filter(line => line.trim());
const totalLines = tableLines.length;
const tableContent = tableLines
.map((line, index) => `${line}\t${totalLines - index}`)
.join('\n');
// 替換 BEGIN_TABLE 到 END_TABLE
ibustmpvalue = ibustmpvalue.replace(
/BEGIN_TABLE[\s\S]*END_TABLE/,
`BEGIN_TABLE\n${tableContent}\nEND_TABLE`
);
createDownloadLink(`${topname}_ibus.txt`, ibustmpvalue);
// 生成 lime 年月日_時分.txt
const limeFilename = `lime_${fileVersion}.txt`;
const limeContent = `@${fileVersion}@哈哈倉頡\n` +
tableLines
.map((line, index) => {
const [code, char] = line.split('\t');
return `${code}|${char}|${totalLines - index}`;
})
.join('\n');
createDownloadLink(limeFilename, limeContent);
};
reader.readAsText(file);
}
function extractChardef(content) {
const beginMarker = '%chardef begin';
const endMarker = '%chardef end';
const start = content.indexOf(beginMarker) + beginMarker.length;
const end = content.indexOf(endMarker);
return content.slice(start, end).trim();
}
function createDownloadLink(filename, content) {
const blob = new Blob([content], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const size = blob.size;
const link = document.createElement('a');
link.href = url;
link.download = filename;
link.textContent = `下載 ${filename} (${size} bytes)`;
const div = document.createElement('div');
div.appendChild(link);
document.getElementById('downloadLinks').appendChild(div);
}
document.getElementById('resetButton').addEventListener('click', resetForm);
function resetForm() {
// 清空 cinfile 輸入欄位
document.getElementById('cinfile').value = '';
document.getElementById('selectcinfilelabel').classList.remove("hide");
// 清空下載鏈接容器
const downloadLinks = document.getElementById('downloadLinks');
downloadLinks.innerHTML = '';
}
function removebr (thechar) {
let lt = String.fromCharCode(60);
let gt = String.fromCharCode(62);
let pattern = new RegExp(lt + "br /" + gt, "g")
return thechar.replace(pattern, "");
};
</script></p>
```