MCPcopy Create free account
hub / github.com/XIU2/UserScript / sortByName

Function sortByName

Lanzou-Enhanced.user.js:660–691  ·  view source on GitHub ↗
(name1, name2)

Source from the content-addressed store, hash-verified

658
659 // 文件名排序
660 function sortByName(name1, name2) {
661 function sort(a, b) {
662 const strA = a.toLocaleLowerCase().split('');
663 const strB = b.toLocaleLowerCase().split('');
664 for (let i = 0; i < strA.length; i++) {
665 if (strA[i] === strB[i]) {
666 continue;
667 }
668 if (strB[i] === undefined) return 1;
669 if (notChinese(strA[i]) && notChinese(strB[i])) {
670 return strA[i] < strB[i] ? -1 : 1;
671 } else if (notChinese(strA[i])) {
672 return -1;
673 } else if (notChinese(strB[i])) {
674 return 1;
675 } else {
676 return strA[i].localeCompare(strB[i]);
677 }
678 }
679 if (strA.length === strB.length) {
680 return 0;
681 } else if (strA.length < strB.length) {
682 return -1;
683 }
684 return 1;
685 }
686 function notChinese(char) {
687 const charCode = char.charCodeAt(0)
688 return charCode >= 0 && charCode <= 128
689 }
690 return sort(name1, name2);
691 }
692
693 // 创建排序按鈕
694 function createAllButtons() {

Callers 1

sortItemsFunction · 0.85

Calls 1

sortFunction · 0.85

Tested by

no test coverage detected