infinite scroll reading mode,Arrow keys to switch chapters,Background preload image,Auto reload image with error.
< Feedback on Happymh reading aid
const createPageElement = (data, isFirst = 0) => { const fragment = new DocumentFragment(); let mainContent = ge("#mainContent"); if (!mainContent) { const targetElement = ge("article"); //ge("article:has(>div[id^='imageLoader'])"); mainContent = document.createElement("div"); mainContent.id = "mainContent"; targetElement.insertAdjacentElement("afterend", mainContent); }
if (isFirst === 0) { const title = document.createElement("div"); title.className = "chapterTitle"; title.innerText = data.chapter_name; // 設置章節名稱 // 使用正則表達式過濾,僅保留中英文字符 let filteredTitle = title.innerText.replace(/[^A-Za-z\u4E00-\u9FFF\s]+/g, ''); console.log("過濾非中英文字符後的標題:", filteredTitle); // 打印過濾後的標題 // 定義關鍵字列表含通配符 const keywordsToExclude = [ "第.*話", "第.*话", "第.*章", "第.*回", ".*話", ".*话", ".*章", ".*回" ]; // 在這裡添加想要排除的關鍵字 console.log("關鍵字列表:", keywordsToExclude); // 打印關鍵字列表含通配符 // 循環檢查並移除關鍵字 keywordsToExclude.forEach(keyword => { // 創建正則表達式 const keywordRegex = new RegExp(keyword, 'g'); // 檢查並打印匹配結果 const matches = filteredTitle.match(keywordRegex); if (matches) { console.log(`移除關鍵字 "${keyword}" 前的標題:`, filteredTitle); // 打印移除前的標題 } // 只移除匹配的部分 filteredTitle = filteredTitle.replace(keywordRegex, ''); // 移除關鍵字 }); // 去除多餘的空格 filteredTitle = filteredTitle.replace(/\s+/g, ' ').trim(); // 將多餘空格替換為單個空格並去掉首尾空格 console.log("最終過濾後的標題:", filteredTitle); // 打印最終顯示的標題 title.innerText = filteredTitle; fragment.append(title); // 將標題添加到文檔片段中 }
Sign in to post a reply.
const createPageElement = (data, isFirst = 0) => { const fragment = new DocumentFragment(); let mainContent = ge("#mainContent"); if (!mainContent) { const targetElement = ge("article"); //ge("article:has(>div[id^='imageLoader'])"); mainContent = document.createElement("div"); mainContent.id = "mainContent"; targetElement.insertAdjacentElement("afterend", mainContent); }