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

Function filesSort

Lanzou-Enhanced.user.js:648–947  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

646
647 // 文件排序
648 function filesSort() {
649 const frame = mainframe;
650 const frameDoc = frame.document;
651
652 const currentStatus = {
653 by: 'name',
654 order: 'asc',
655 }
656
657 let allButtons = undefined;
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() {
695 const tabTitle = frameDoc.querySelector('#container > div.n1 > div.f_th');
696 const name = tabTitle.querySelector('div.f_name');
697 const size = tabTitle.querySelector('div.f_size');
698 const time = tabTitle.querySelector('div.f_time');
699 const down = tabTitle.querySelector('div.f_down'); // 下载量
700 return {
701 name: {
702 el: createButton(name, 'name', '按 文件名称 排序'),
703 order: 'asc',
704 },
705 size: {

Callers

nothing calls this directly

Calls 2

createAllButtonsFunction · 0.85
menu_valueFunction · 0.70

Tested by

no test coverage detected