-
Notifications
You must be signed in to change notification settings - Fork 1
/
1000char.html
118 lines (118 loc) · 11.2 KB
/
1000char.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdn.staticfile.org/twitter-bootstrap/5.0.2/js/bootstrap.bundle.min.js"></script>
<link rel="stylesheet" href="https://bootswatch.com/_vendor/bootstrap/dist/css/bootstrap.min.css" />
<link id="css" data-theme="bootstrap" rel="stylesheet" crossorigin="anonymous" />
<link rel="stylesheet" href="/basis/css/bootstrap-init.css" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css" />
</head>
<body>
<div class="container-fluid">
<title class="h4">《千字文》编号</title>
<meta name="discription" class="h6" content="余藏特贵" class="mb-3" />
<div class="list-group mb-3">
<a href="https://www.zhihu.com/question/24371856/answer/1431910214" class="list-group-item list-group-item-action" target="_blank"><i class="bi bi-box-arrow-right" style="margin-right: .5rem;"></i>使用说明:知乎 @韩德雨 的回答</a>
</div>
<div class="mb-2">
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="chinese-type" id="traditionalChineseRadio" value="option1" checked>
<label class="form-check-label" for="traditionalChineseRadio">繁體</label>
</div>
<div class="form-check form-check-inline" title="由于汉字简化会造成多对一的情况。<br>仅对数字转千字文编号生效。" data-bs-toggle="tooltip" data-bs-html="true">
<input class="form-check-input" type="radio" name="chinese-type" id="simplifiedChineseRadio" value="option2">
<label class="form-check-label" for="simplifiedChineseRadio">简体</label>
</div>
</div>
<div class="input-group mb-2">
<label class="input-group-text input-group-addon" for="digitTxt">输一个整数</label>
<textarea type="text" class="form-control" id="digitTxt" rows="7"></textarea>
</div>
<div class="input-group mb-2">
<label class="input-group-text input-group-addon" for="charkTxt">千字文编号</label>
<textarea type="text" class="form-control" id="charkTxt" rows="7" title="《千字文》中没有的字将会被移除" data-bs-toggle="tooltip"></textarea>
</div>
<button type="button" class="btn btn-danger mb-3 font-weight-bold float-right btm-sm" id="clearAllBtn">清空</button>
</div>
<script>
const THOUSAND_CHARACTER_CLASSIC = "\0天地玄黃宇宙洪荒日月盈昃辰宿列張寒來暑往秋收冬藏閏馀成歲律呂調陽雲騰致雨露結爲霜金生麗水玉出崑岡劍號巨阙珠稱夜光果珍李柰菜重芥姜海鹹河淡鱗潛羽翔龍師火帝鳥官人皇始制文字乃服衣裳推位讓國有虞陶唐弔民伐罪周發殷湯坐朝問道垂拱平章愛育黎首臣伏戎羌遐迩一體率賓歸王鳴鳳在竹白駒食場化被草木賴及萬方蓋此身髮四大五常恭惟鞠養豈敢毀傷女慕貞潔男效才良知過必改得能莫忘罔談彼短靡恃己長信使可複器欲難量墨悲絲染詩贊羔羊景行維賢克念作聖德建名立形端表正空谷傳聲虛堂習聽禍因惡積福緣善慶尺璧非寶寸陰是競資父事君曰嚴與敬孝當竭力忠則盡命臨深履薄夙興溫凊似蘭斯馨如松之盛川流不息淵澄取映容止若思言辭安定笃初誠美慎終宜令榮業所基籍甚無竟學優登仕攝職從政存以甘棠去而益詠樂殊貴賤禮別尊卑上和下睦夫唱婦隨外受傅訓入奉母儀諸姑伯叔猶子比兒孔懷兄弟同氣連枝交友投分切磨箴規仁慈隱恻造次弗離節義廉退顛沛匪虧性靜情逸心動神疲守真志滿逐物意移堅持雅操好爵自縻都邑華夏東西二京背邙面洛浮渭據泾宮殿盤欎樓觀飛驚圖寫禽獸畫彩仙靈丙舍傍啓甲帳對楹肆筵設席鼓瑟吹笙升階納陛弁轉疑星右通廣內左達承明既集墳典亦聚群英杜稿鍾隸漆書壁經府羅將相路俠槐卿戶封八縣家給千兵高冠陪辇驅轂振纓世祿侈富車駕肥輕策功茂實勒碑刻銘磻溪伊尹佐時阿衡奄宅曲阜微旦孰營桓公匡合濟弱扶傾绮回漢惠說感武丁俊乂密勿多士寔甯晉楚更霸趙魏困橫假途滅虢踐土會盟何遵約法韓弊煩刑起翦頗牧用軍最精宣威沙漠馳譽丹青九州禹迹百郡秦並嶽宗泰岱禅主云亭雁門紫塞雞田赤城昆池碣石鉅野洞庭曠遠綿邈岩岫杳冥治本於農務兹稼穑俶載南畝我藝黍稷稅熟貢新勸賞黜陟孟轲敦素史魚秉直庶幾中庸勞謙謹敕聆音察理鑒貌辨色贻厥嘉猷勉其祗植省躬譏誡寵增抗極殆辱近恥林臯幸即兩疏見機解組誰逼索居閑處沉默寂寥求古尋論散慮逍遙欣奏累遣慼謝歡招渠荷的歴園莽抽條枇杷晚翠梧桐蚤凋陳根委翳落葉飄颻遊鹍獨運淩摩绛霄耽讀玩市寓目囊箱易輏攸畏屬耳垣牆具膳餐飯適口充腸飽饫烹宰饑厭糟糠親戚故舊老少異糧妾御績紡侍巾帷房纨扇圓絜銀燭炜煌晝眠夕寐藍筍象床弦歌酒宴接杯舉觞矯手頓足悅豫且康嫡後嗣續祭祀烝嘗稽颡再拜悚懼恐惶箋牒簡要顧答審詳骸垢想浴執熱願涼驢騾犢特駭躍超骧誅斬賊盜捕獲叛亡布射僚丸嵇琴阮嘯恬筆倫紙鈞巧任釣釋紛利俗竝皆佳妙毛施淑姿工颦妍笑年矢每催曦晖朗曜璇玑懸斡晦魄環照指薪修祜永綏吉劭矩步引領俯仰廊廟束帶矜莊徘徊瞻眺孤陋寡聞愚蒙等诮謂語助者焉哉乎也";
const THOUSAND_CHARACTER_CLASSIC_SIMPLIFIED = "\0天地玄黄宇宙洪荒日月盈昃辰宿列张寒来暑往秋收冬藏闰余成岁律吕调阳云腾致雨露结为霜金生丽水玉出昆冈剑号巨阙珠称夜光果珍李柰菜重芥姜海咸河淡鳞潜羽翔龙师火帝鸟官人皇始制文字乃服衣裳推位让国有虞陶唐吊民伐罪周发殷汤坐朝问道垂拱平章爱育黎首臣伏戎羌遐迩一体率宾归王鸣凤在竹白驹食场化被草木赖及万方盖此身发四大五常恭惟鞠养岂敢毁伤女慕贞洁男效才良知过必改得能莫忘罔谈彼短靡恃己长信使可覆器欲难量墨悲丝染诗赞羔羊景行维贤克念作圣德建名立形端表正空谷传声虚堂习听祸因恶积福缘善庆尺璧非宝寸阴是竞资父事君曰严与敬孝当竭力忠则尽命临深履薄夙兴温凊似兰斯馨如松之盛川流不息渊澄取映容止若思言辞安定笃初诚美慎终宜令荣业所基籍甚无竟学优登仕摄职从政存以甘棠去而益咏乐殊贵贱礼别尊卑上和下睦夫唱妇随外受傅训入奉母仪诸姑伯叔犹子比儿孔怀兄弟同气连枝交友投分切磨箴规仁慈隐恻造次弗离节义廉退颠沛匪亏性静情逸心动神疲守真志满逐物意移坚持雅操好爵自縻都邑华夏东西二京背邙面洛浮渭据泾宫殿盘郁楼观飞惊图写禽兽画彩仙灵丙舍旁启甲帐对楹肆筵设席鼓瑟吹笙升阶纳陛弁转疑星右通广内左达承明既集坟典亦聚群英杜稿钟隶漆书壁经府罗将相路侠槐卿户封八县家给千兵高冠陪辇驱毂振缨世禄侈富车驾肥轻策功茂实勒碑刻铭磻溪伊尹佐时阿衡奄宅曲阜微旦孰营桓公匡合济弱扶倾绮回汉惠说感武丁俊义密勿多士实宁晋楚更霸赵魏困横假途灭虢践土会盟何遵约法韩弊烦刑起翦颇牧用军最精宣威沙漠驰誉丹青九州禹迹百郡秦并岳宗泰岱禅主云亭雁门紫塞鸡田赤城昆池碣石钜野洞庭旷远绵邈岩岫杳冥治本于农务兹稼穑俶载南亩我艺黍稷税熟贡新劝赏黜陟孟轲敦素史鱼秉直庶几中庸劳谦谨敕聆音察理鉴貌辨色贻厥嘉猷勉其祗植省躬讥诫宠增抗极殆辱近耻林皋幸即两疏见机解组谁逼索居闲处沉默寂寥求古寻论散虑逍遥欣奏累遣戚谢欢招渠荷的历园莽抽条枇杷晚翠梧桐蚤凋陈根委翳落叶飘摇游鹍独运凌摩绛霄耽读玩市寓目囊箱易輶攸畏属耳垣墙具膳餐饭适口充肠饱饫烹宰饥厌糟糠亲戚故旧老少异粮妾御绩纺侍巾帷房纨扇圆絜银烛炜煌昼眠夕寐蓝笋象床弦歌酒宴接杯举觞矫手顿足悦豫且康嫡后嗣续祭祀烝尝稽颡再拜悚惧恐惶笺牒简要顾答审详骸垢想浴执热愿凉驴骡犊特骇跃超骧诛斩贼盗捕获叛亡布射僚丸嵇琴阮啸恬笔伦纸钧巧任钓释纷利俗并皆佳妙毛施淑姿工颦妍笑年矢每催曦晖朗曜璇玑悬斡晦魄环照指薪修祜永绥吉劭矩步引领俯仰廊庙束带矜庄徘徊瞻眺孤陋寡闻愚蒙等诮谓语助者焉哉乎也";
$(document).ready(() => {
$('[data-bs-toggle="tooltip"]').tooltip();
});
$("#digitTxt").on("input propertychange change", function () {
this.value = this.value.replace(/[^0-9]/g, "").replace(/^0+(?!$)/g, "");
$("#charkTxt").val(digit2chark(this.value));
});
$("#digitTxt").keydown(function (e) {
if (e.originalEvent.key === "ArrowUp") this.value++;
if (e.originalEvent.key === "ArrowDown") this.value--;
if (this.value - 0 < 0) this.value = 0;
$(this).change();
});
$("#charkTxt").on("input propertychange change", function (e) {
const value = this.value.replace(new RegExp(`[^${THOUSAND_CHARACTER_CLASSIC.slice(1) + THOUSAND_CHARACTER_CLASSIC_SIMPLIFIED.slice(1)}]`, 'g'), "");
$("#digitTxt").val(chark2digit(value));
if ((e.type == "input" && e.originalEvent.inputType == "insertLineBreak") || this.value.includes('\n') || e.type == "change") {
this.value = value;
}
});
$("#clearAllBtn").click(() => $("textarea").val(""));
$("[name=chinese-type").click(() => $("#digitTxt").change());
function toBigInt(digit) {
if (typeof digit == "bigint");
else if (typeof digit == "number") digit = BigInt(Math.floor(digit));
else if (typeof digit == "string") digit = BigInt(digit.replace(/\..*/g, ''))
else throw new TypeError("Please enter a valid number");
return digit;
}
function digit2chark(digit) {
if (["", "0", 0, 0n].includes(digit)) return "";
digit = toBigInt(digit);
// digit--; // 因为千字文编号是从 1 开始计数
const BASE = 1000n;
let chark = "";
const chars = $("#traditionalChineseRadio")[0].checked ? THOUSAND_CHARACTER_CLASSIC : THOUSAND_CHARACTER_CLASSIC_SIMPLIFIED;
while (digit > 0n) {
let bit = digit % BASE;
if (bit === 0n) bit = BASE;
chark = chars[bit] + chark;
digit = (digit - bit) / BASE;
}
return chark;
}
function chark2digit(chark) {
if (typeof chark != "string") throw new TypeError("Please enter a valid number");
let digit = 0n;
for (let i = chark.length - 1, j = 1n; i >= 0; i--, j *= 1000n) {
const bit = chark[i];
let chars;
if (bit === ' ') continue;
else if (THOUSAND_CHARACTER_CLASSIC.includes(bit)) chars = THOUSAND_CHARACTER_CLASSIC;
else if (THOUSAND_CHARACTER_CLASSIC_SIMPLIFIED.includes(bit)) chars = THOUSAND_CHARACTER_CLASSIC_SIMPLIFIED;
else return "";
digit += BigInt(chars.indexOf(bit)) * j;
}
return digit;
}
function fixZero(num) {
num = toBigInt(num);
let sign = false;
if (num < 0n) {
sign = true;
num = -num;
}
let j = 0n;
while (num--) {
j++;
while (String(j).includes('0')) j++;
}
return j;
}
</script>
<script src="/basis/NightTime.js"></script>
</body>
</html>