mirror of
https://github.com/fireinrain/JHS-enhance.git
synced 2026-10-11 04:06:37 +08:00
修复磁力排序刷新失效
This commit is contained in:
@@ -7,15 +7,28 @@ class HighlightMagnetPlugin extends BasePlugin {
|
||||
}
|
||||
|
||||
parseDateFromAttr(dateStr) {
|
||||
if (!dateStr || dateStr.length !== 8) {
|
||||
const d = new Date(dateStr);
|
||||
return isNaN(d.getTime()) ? 0 : d.getTime();
|
||||
if (!dateStr) return 0;
|
||||
if (dateStr.length === 8) {
|
||||
const y = parseInt(dateStr.substring(0, 4), 10);
|
||||
const m = parseInt(dateStr.substring(4, 6), 10) - 1;
|
||||
const d = parseInt(dateStr.substring(6, 8), 10);
|
||||
const date = new Date(y, m, d);
|
||||
return isNaN(date.getTime()) ? 0 : date.getTime();
|
||||
}
|
||||
const y = parseInt(dateStr.substring(0, 4), 10);
|
||||
const m = parseInt(dateStr.substring(4, 6), 10) - 1;
|
||||
const d = parseInt(dateStr.substring(6, 8), 10);
|
||||
const date = new Date(y, m, d);
|
||||
return isNaN(date.getTime()) ? 0 : date.getTime();
|
||||
const d = new Date(dateStr);
|
||||
return isNaN(d.getTime()) ? 0 : d.getTime();
|
||||
}
|
||||
|
||||
parseSizeToBytes(sizeText) {
|
||||
if (!sizeText) return 0;
|
||||
const s = sizeText.trim().toUpperCase();
|
||||
const num = parseFloat(s);
|
||||
if (isNaN(num)) return 0;
|
||||
if (s.includes('TB')) return num * 1024 * 1024 * 1024 * 1024;
|
||||
if (s.includes('GB')) return num * 1024 * 1024 * 1024;
|
||||
if (s.includes('MB')) return num * 1024 * 1024;
|
||||
if (s.includes('KB')) return num * 1024;
|
||||
return num;
|
||||
}
|
||||
|
||||
getRowInfo(row) {
|
||||
@@ -42,7 +55,33 @@ class HighlightMagnetPlugin extends BasePlugin {
|
||||
};
|
||||
}
|
||||
|
||||
getRowInfoForBus(row) {
|
||||
const $row = $(row);
|
||||
const $nameCell = $row.find('td:first-child');
|
||||
const nameText = ($nameCell.find('a:first-child').text() || '').toLowerCase().trim();
|
||||
const sizeText = ($row.find('td:nth-child(2)').text() || '').trim();
|
||||
const dateText = ($row.find('td:nth-child(3)').text() || '').trim();
|
||||
const hasHDButton = $nameCell.find('a.btn-primary').text().includes('高清');
|
||||
return {
|
||||
row: row,
|
||||
$row: $row,
|
||||
nameText: nameText,
|
||||
date: this.parseDateFromAttr(dateText),
|
||||
dateStr: dateText,
|
||||
size: this.parseSizeToBytes(sizeText),
|
||||
files: 0,
|
||||
tags: [],
|
||||
is4K: nameText.includes('4k') || nameText.includes('[4k]'),
|
||||
isHD: hasHDButton || nameText.includes('高清'),
|
||||
isSubtitle: nameText.includes('字幕') || nameText.includes('-c') || nameText.includes('.chs') || nameText.includes('.cht') || nameText.includes('.chi'),
|
||||
isUncensored: nameText.includes('无码') || nameText.includes('無碼') || nameText.includes('-u') || nameText.includes('-uc'),
|
||||
};
|
||||
}
|
||||
|
||||
async applySortAndFilter(settings) {
|
||||
if (isJavBus) {
|
||||
return this.applySortAndFilterForBus(settings);
|
||||
}
|
||||
if (!isJavDb) return;
|
||||
const $container = $("#magnets-content");
|
||||
const $rows = $container.find(".item[data-rank]");
|
||||
@@ -103,6 +142,61 @@ class HighlightMagnetPlugin extends BasePlugin {
|
||||
hiddenInfos.forEach(info => $(info.row).hide());
|
||||
}
|
||||
|
||||
applySortAndFilterForBus(settings) {
|
||||
const $table = $("#magnet-table");
|
||||
if (!$table.length) return;
|
||||
const allRows = $table.find("tr").toArray();
|
||||
const headerRow = allRows.find(r => $(r).find('td').length === 0 || $(r).css('font-weight') === 'bold' || $(r).css('fontWeight') === 'bold' || $(r).css('font-weight') === '700');
|
||||
const dataRows = headerRow ? allRows.filter(r => r !== headerRow) : allRows.slice(1);
|
||||
if (0 === dataRows.length) return;
|
||||
const rowInfos = dataRows.map(row => this.getRowInfoForBus(row));
|
||||
const {filterHD, filter4K, filterSubtitle, filterUncensored, sortOrder} = settings;
|
||||
const anyFilterEnabled = filterHD || filter4K || filterSubtitle || filterUncensored;
|
||||
let visibleInfos = rowInfos;
|
||||
if (anyFilterEnabled) {
|
||||
visibleInfos = rowInfos.filter(info => {
|
||||
if (filterHD && info.isHD) return !0;
|
||||
if (filter4K && info.is4K) return !0;
|
||||
if (filterSubtitle && info.isSubtitle) return !0;
|
||||
if (filterUncensored && info.isUncensored) return !0;
|
||||
return !1;
|
||||
});
|
||||
}
|
||||
if (sortOrder && sortOrder.length > 0) {
|
||||
visibleInfos.sort((a, b) => {
|
||||
for (const key of sortOrder) {
|
||||
let cmp = 0;
|
||||
switch (key) {
|
||||
case 'date':
|
||||
cmp = b.date - a.date;
|
||||
break;
|
||||
case 'size':
|
||||
cmp = b.size - a.size;
|
||||
break;
|
||||
}
|
||||
if (0 !== cmp) return cmp;
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
const hiddenInfos = rowInfos.filter(info => !visibleInfos.includes(info));
|
||||
const fragment = document.createDocumentFragment();
|
||||
visibleInfos.forEach(info => fragment.appendChild(info.row));
|
||||
hiddenInfos.forEach(info => fragment.appendChild(info.row));
|
||||
const insertAnchor = headerRow || $table.find("tr").first()[0];
|
||||
if (insertAnchor && insertAnchor.nextSibling) {
|
||||
$(insertAnchor).after(fragment);
|
||||
} else {
|
||||
$table.append(fragment);
|
||||
}
|
||||
visibleInfos.forEach(info => {
|
||||
if (info.is4K) {
|
||||
info.$row.addClass('magnet-4k-highlight');
|
||||
}
|
||||
});
|
||||
hiddenInfos.forEach(info => $(info.row).hide());
|
||||
}
|
||||
|
||||
showAll() {
|
||||
if (isJavDb) {
|
||||
$("#magnets-content .item[data-rank]").toArray().forEach((el => {
|
||||
@@ -111,7 +205,10 @@ class HighlightMagnetPlugin extends BasePlugin {
|
||||
}));
|
||||
}
|
||||
if (isJavBus) {
|
||||
$("#magnet-table tr").toArray().forEach((el => $(el).show()));
|
||||
$("#magnet-table tr").toArray().forEach((el => {
|
||||
$(el).show();
|
||||
$(el).removeClass('magnet-4k-highlight');
|
||||
}));
|
||||
}
|
||||
}
|
||||
handleBus() {
|
||||
|
||||
Reference in New Issue
Block a user