Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions extensions/nodebb-thread-exporter/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ turndownService.addRule('absoluteImages', {
if (src && !src.startsWith('http')) {
try {
// ה-API מחזיר כתובות יחסיות, לכן נשתמש במיקום הנוכחי כבסיס
src = new URL(src, location.origin).href;
const baseUrl = location.href.split('/topic/')[0];
src = new URL(src, baseUrl).href;
} catch (e) {
console.error("Could not create absolute URL for image:", src, e);
}
Expand Down Expand Up @@ -43,8 +44,10 @@ turndownService.addRule('userMentions', {
* פונקציה ראשית לאיסוף ועיבוד השרשור דרך ה-API
*/
async function fetchAndProcessThread() {
// חישוב כתובת הבסיס לתמיכה בפורומים המותקנים בתתי-תיקיות
const baseUrl = location.href.split('/topic/')[0];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

החישוב של baseUrl מופיע כעת בשני מקומות שונים בקובץ (גם בשורות 15-16 וגם כאן). כדי לשפר את התחזוקה ולמנוע כפילות קוד, מומלץ להגדיר את baseUrl כמשתנה const גלובלי בחלק העליון של הקובץ content.js. לאחר מכן, ניתן להשתמש במשתנה הגלובלי הזה במקום לחשב אותו מחדש בכל פונקציה. זה יבטיח עקביות ויפשט את הקוד.


// שלב 1: חילוץ מזהה השרשור (TID) וכותרת
// --- התיקון כאן: שינוי const ל-let ---
let tid = window.ajaxify?.data?.tid;
let title = window.ajaxify?.data?.title;

Expand All @@ -65,7 +68,7 @@ async function fetchAndProcessThread() {


// שלב 2: קבלת מידע על מספר העמודים בשרשור
const paginationResponse = await fetch(`${location.origin}/api/topic/pagination/${tid}`);
const paginationResponse = await fetch(`${baseUrl}/api/topic/pagination/${tid}`);
if (!paginationResponse.ok) throw new Error(`שגיאה בקבלת מידע על עמודים: ${paginationResponse.statusText}`);
const paginationData = await paginationResponse.json();
const pageCount = paginationData.pagination.pageCount;
Expand All @@ -74,7 +77,7 @@ async function fetchAndProcessThread() {
const pagePromises = [];
for (let i = 1; i <= pageCount; i++) {
pagePromises.push(
fetch(`${location.origin}/api/topic/${tid}?page=${i}`).then(res => {
fetch(`${baseUrl}/api/topic/${tid}?page=${i}`).then(res => {
if (!res.ok) throw new Error(`שגיאה בטעינת עמוד ${i}`);
return res.json();
})
Expand Down Expand Up @@ -117,4 +120,4 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
});
}
return true; // נדרש עבור תגובה אסינכרונית
});
});