Skip to content

Commit da468b4

Browse files
committed
update
1 parent 565a2a8 commit da468b4

File tree

3 files changed

+89
-81
lines changed

3 files changed

+89
-81
lines changed

Switch Traditional Chinese and Simplified Chinese/lib/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "switch-chinese",
3-
"version": "1.0.7",
4-
"description": "Lightweight Chinese converter library for bidirectional conversion between Simplified and Traditional Chinese with intelligent word segmentation, custom dictionary support, character detection, and multiple output formats. Zero dependencies. 轻量级简繁体中文智能转换库,支持简繁双向转换、智能分词、自定义词库、文本检测及多种输出格式,零依赖。",
3+
"version": "1.0.10",
4+
"description": "簡繁轉換,支援簡繁雙向轉換、智慧分詞、自訂詞庫、文字偵測及多種輸出格式,零依賴。 Lightweight Chinese converter library for conversion between Simplified and Traditional Chinese. 轻量级简繁体中文智能转换库,支持简繁双向转换、智能分词、自定义词库、文本检测及多种输出格式,零依赖。",
55
"main": "stcasc.lib.js",
66
"types": "stcasc.d.ts",
77
"type": "module",

Switch Traditional Chinese and Simplified Chinese/lib/stcasc.lib.js

Lines changed: 79 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -837,84 +837,90 @@ function detect(text) {
837837
}
838838

839839
function stcasc(cache, custom, disableTerms) {
840-
if (!cache) cache = {};
841-
if (cache.sc2tcCombTree && cache.tc2scCombTree) {
842-
sc2tcCombTree = cache.sc2tcCombTree;
840+
if (!cache) cache = {};
841+
if (cache.sc2tcCombTree && cache.tc2scCombTree) {
842+
sc2tcCombTree = cache.sc2tcCombTree;
843843
tc2scCombTree = cache.tc2scCombTree;
844-
} else {
844+
} else {
845845
if (disableTerms) sc2tcComb = {};
846-
if (custom && custom.length) {
847-
for (let sc in custom) {
848-
sc2tcComb[sc] = custom[sc];
849-
}
850-
}
851-
function makeCombTree(key, value) {
852-
let curTree = sc2tcCombTree;
853-
for (let i = 0; i < key.length; i++) {
854-
let newTree = {};
855-
if (i == key.length - 1) {
856-
newTree = {"end": value};
857-
}
858-
let curKey = key.charAt(i);
859-
let branch = curTree[curKey];
860-
if (!branch) {
861-
curTree[curKey] = newTree;
862-
curTree = newTree;
863-
} else {
864-
curTree = branch;
865-
}
866-
}
867-
curTree = tc2scCombTree;
868-
for (let i = 0; i < value.length; i++) {
869-
let newTree = {};
870-
if (i == value.length - 1) {
871-
newTree = {"end": key};
872-
}
873-
let curKey = value.charAt(i);
874-
let branch = curTree[curKey];
875-
if (!branch) {
876-
curTree[curKey] = newTree;
877-
curTree = newTree;
878-
} else {
879-
curTree = branch;
880-
}
881-
}
882-
}
883-
for (let key in sc2tcComb) {
884-
let value = sc2tcComb[key];
885-
if (Array.isArray(value)) {
886-
value.forEach(v => {
887-
makeCombTree(key, v);
888-
});
889-
} else {
890-
makeCombTree(key, value);
891-
}
892-
}
893-
cache.sc2tcCombTree = sc2tcCombTree;
846+
if (custom && custom.length) {
847+
for (let sc in custom) {
848+
sc2tcComb[sc] = custom[sc];
849+
}
850+
}
851+
function makeCombTree(key, value) {
852+
let curTree = sc2tcCombTree;
853+
for (let i = 0; i < key.length; i++) {
854+
let curKey = key.charAt(i);
855+
let branch = curTree[curKey];
856+
let newTree = {};
857+
if (i == key.length - 1) {
858+
newTree = {"end": value};
859+
if (branch) {
860+
branch.end = value;
861+
}
862+
}
863+
if (branch) {
864+
curTree = branch;
865+
} else {
866+
curTree[curKey] = newTree;
867+
curTree = newTree;
868+
}
869+
}
870+
curTree = tc2scCombTree;
871+
for (let i = 0; i < value.length; i++) {
872+
let curKey = value.charAt(i);
873+
let branch = curTree[curKey];
874+
let newTree = {};
875+
if (i == value.length - 1) {
876+
newTree = {"end": key};
877+
if (branch) {
878+
branch.end = value;
879+
}
880+
}
881+
if (branch) {
882+
curTree = branch;
883+
} else {
884+
curTree[curKey] = newTree;
885+
curTree = newTree;
886+
}
887+
}
888+
}
889+
for (let key in sc2tcComb) {
890+
let value = sc2tcComb[key];
891+
if (Array.isArray(value)) {
892+
value.forEach(v => {
893+
makeCombTree(key, v);
894+
});
895+
} else {
896+
makeCombTree(key, value);
897+
}
898+
}
899+
cache.sc2tcCombTree = sc2tcCombTree;
894900
cache.tc2scCombTree = tc2scCombTree;
895-
}
896-
if (cache.stDict && cache.tsDict) {
897-
stDict = cache.stDict;
901+
}
902+
if (cache.stDict && cache.tsDict) {
903+
stDict = cache.stDict;
898904
tsDict = cache.tsDict;
899-
} else {
900-
for (let i = 0; i < scStr.length; i++) {
901-
let _sc = scStr[i];
902-
let _tc = tcStr[i];
903-
if (!stDict[_sc]) stDict[_sc] = _tc;
904-
if (!tsDict[_tc]) tsDict[_tc] = _sc;
905-
}
906-
Object.keys(oc2tc).forEach(key => {
907-
let ocList = oc2tc[key];
908-
for (let i = 0; i < ocList.length; i++) {
909-
let oc = ocList[i];
910-
stDict[oc] = key;
911-
tsDict[oc] = tsDict[key] || key;
912-
}
913-
})
914-
cache.stDict = stDict;
905+
} else {
906+
for (let i = 0; i < scStr.length; i++) {
907+
let _sc = scStr[i];
908+
let _tc = tcStr[i];
909+
if (!stDict[_sc]) stDict[_sc] = _tc;
910+
if (!tsDict[_tc]) tsDict[_tc] = _sc;
911+
}
912+
Object.keys(oc2tc).forEach(key => {
913+
let ocList = oc2tc[key];
914+
for (let i = 0; i < ocList.length; i++) {
915+
let oc = ocList[i];
916+
stDict[oc] = key;
917+
tsDict[oc] = tsDict[key] || key;
918+
}
919+
})
920+
cache.stDict = stDict;
915921
cache.tsDict = tsDict;
916-
}
917-
return {simplized, traditionalized, detect, cache};
922+
}
923+
return {simplized, traditionalized, detect, cache};
918924
}
919925

920926
export default stcasc;

X-Downloader/X-Downloader.user.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,20 @@
1515
// @match https://twitter.com/*
1616
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
1717
// @grant none
18-
// @downloadURL https://update.greasyfork.org/scripts/545186/X-Downloader.user.js
19-
// @updateURL https://update.greasyfork.org/scripts/545186/X-Downloader.meta.js
18+
// @downloadURL https://update.greasyfork.org/scripts/545186/X-Downloader-Script.user.js
19+
// @updateURL https://update.greasyfork.org/scripts/545186/X-Downloader-Script.meta.js
2020
// ==/UserScript==
2121

2222
(function() {
2323
'use strict';
24-
let downloadBtn = document.createElement("a"), touch = false;
24+
let downloadBtn = document.createElement("a"), touch = false, simpleClick = false;
2525
downloadBtn.target = "_blank";
2626
downloadBtn.style.cssText = "background: #000000aa; border-radius: 50%; transition: opacity ease 0.3s; position: absolute; top: 0; right: 0px; cursor: pointer; opacity: 0; padding: 5px;";
2727
downloadBtn.innerHTML = `<svg width="25" height="25" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z" clip-rule="evenodd"></path></svg>`;
2828
downloadBtn.addEventListener("mousedown", e => {
2929
let parent = downloadBtn.parentNode;
3030
if (!parent) return;
31+
simpleClick = false;
3132
let img = parent.querySelector('[data-testid="tweetPhoto"]>img,[data-testid="card.layoutLarge.media"] img');
3233
if (img) {
3334
let newsrc = img.src.replace("_normal.",".").replace("_200x200.",".").replace("_mini.",".").replace("_bigger.",".").replace(/_x\d+\./,"."), imgname;
@@ -59,7 +60,8 @@
5960
imgname = `${user.innerText} ${time.innerText.replace(/(.*) · (.*)/, "$2 $1")}.${ext}`;
6061
}
6162
downloadBtn.href = newsrc;
62-
if (e.altKey || touch) {
63+
if ((e.button === 0 && !e.ctrlKey) || touch) {
64+
simpleClick = true;
6365
downloadByFetch(newsrc, imgname);
6466
}
6567
} else {
@@ -72,15 +74,15 @@
7274
if (parent) {
7375
downloadBtn.removeAttribute('download');
7476
let link = parent.querySelector('a[role="link"][aria-label][href^="/"]');
75-
downloadBtn.href = `https://twitter.hoothin.com/?url=${encodeURIComponent(link ? link.href : document.location.href)}`;
77+
downloadBtn.href = `https://twitter.luopo.org/?url=${encodeURIComponent(link ? link.href : document.location.href)}`;
7678
if (e.altKey || touch) {
7779
window.open(downloadBtn.href, "_blank");
7880
}
7981
}
8082
}
8183
});
8284
downloadBtn.addEventListener("click", e => {
83-
if (e.altKey || touch) {
85+
if (simpleClick || e.altKey || touch) {
8486
e.preventDefault();
8587
e.stopPropagation();
8688
}

0 commit comments

Comments
 (0)