import { BasePlugin } from '../core/base-plugin.js'; import { __publicField } from '../core/constants.js'; class NavBarPlugin extends BasePlugin { getName() { return "NavBarPlugin"; } async initCss() { return "\n .highlight-red {\n /* 核心要求:高亮红色文本 */\n color: red !important; \n \n /* 建议:增加字体加粗,效果更明显 */\n font-weight: bold;\n \n /* 建议:增加背景色,效果更突出 */\n /* background-color: yellow; */ \n}\n "; } handle() { this.margeNav(); this.hookSearch(); this.hookOldSearch(); this.toggleOtherNavItem(); $(window).resize(this.toggleOtherNavItem); if (window.location.href.includes("/search")) { const urlParams = new URLSearchParams(window.location.search); let q = urlParams.get("q"), f = urlParams.get("f"); $("#search-keyword").val(q); f && $("#search-type").val(f); q && this.highlightKeyword(q); } } highlightKeyword(keyword) { const trimedKeyword = keyword.trim(); if (!trimedKeyword) return; const lowerCaseKeyword = trimedKeyword.toLowerCase(); $(".video-title strong, .actor-box strong").each((function() { const $strongElement = $(this); $strongElement.text().toLowerCase().includes(lowerCaseKeyword) && $strongElement.addClass("highlight-red"); })); } hookSearch() { $("#navbar-menu-hero").after('\n \n '); $("#search-keyword").on("paste", (event => { const items = event.originalEvent.clipboardData.items; for (let i = 0; i < items.length; i++) if (-1 !== items[i].type.indexOf("image")) { const blob = items[i].getAsFile(); $("#search-keyword").blur(); const imageRecognitionPlugin = this.getBean("ImageRecognitionPlugin"); imageRecognitionPlugin.open((() => { imageRecognitionPlugin.handleImageFile(blob); imageRecognitionPlugin.resetSearchUI(); })); return; } setTimeout((() => { $("#search-btn").click(); }), 0); })).on("keypress", (event => { "Enter" === event.key && setTimeout((() => { $("#search-btn").click(); }), 0); })); $("#search-btn").on("click", (event => { let keyword = $("#search-keyword").val(), searchCurrentType = $("#search-type option:selected").val(); "" !== keyword && (window.location.href.includes("/search") ? window.location.href = "/search?q=" + keyword + "&f=" + searchCurrentType : window.open("/search?q=" + keyword + "&f=" + searchCurrentType)); })); $("#search-img-btn").on("click", (() => { this.getBean("ImageRecognitionPlugin").open(); })); } hookOldSearch() { const searchImage = document.querySelector(".search-image"); if (!searchImage) return; const clonedImage = searchImage.cloneNode(!0); searchImage.parentNode.replaceChild(clonedImage, searchImage); $("#button-search-image").attr("data-tooltip", "以图识图"); $(".search-image").on("click", (event => { this.getBean("ImageRecognitionPlugin").open(); })); } margeNav() { $('a[href*="/feedbacks/new"]').remove(); $('a[href*="theporndude.com"]').remove(); $('a.navbar-link[href="/makers"]').parent().after('\n \n '); } toggleOtherNavItem() { let $searchBox = $("#search-box"), $oldSearchBox = $("#search-bar-container"); if ($(window).width() < 1600 && $(window).width() > 1023) { $searchBox.hide(); $oldSearchBox.show(); } if ($(window).width() > 1600) { $searchBox.show(); $oldSearchBox.hide(); } } } export { NavBarPlugin };