This commit is contained in:
MDeeApp
2025-10-23 20:32:31 +02:00
parent 36dff70f98
commit cd5a179125
2 changed files with 75 additions and 17 deletions

View File

@@ -13,7 +13,7 @@ const LAST_SELECTION_MAX_AGE = 5000;
let selectionCacheTimeout = null; let selectionCacheTimeout = null;
let lastGlobalSelection = { text: '', timestamp: 0 }; let lastGlobalSelection = { text: '', timestamp: 0 };
const processedPostUrls = new Map(); const processedPostUrls = new Map();
const SEARCH_RESULTS_PATH = '/search/top'; const SEARCH_RESULTS_PATH_PREFIX = '/search';
const FEED_HOME_PATHS = ['/', '/home.php']; const FEED_HOME_PATHS = ['/', '/home.php'];
const sessionSearchRecordedUrls = new Set(); const sessionSearchRecordedUrls = new Set();
const sessionSearchInfoCache = new Map(); const sessionSearchInfoCache = new Map();
@@ -869,6 +869,41 @@ function matchesKeyword(label, keywords) {
return keywords.some((keyword) => label.includes(keyword)); return keywords.some((keyword) => label.includes(keyword));
} }
function styleIndicatesLiked(styleValue) {
if (!styleValue || typeof styleValue !== 'string') {
return false;
}
const normalized = styleValue.toLowerCase();
return (
normalized.includes('reaction-like')
|| normalized.includes('#0866ff')
|| normalized.includes('rgb(8, 102, 255)')
|| normalized.includes('--reaction-like')
);
}
function elementIndicatesLiked(element) {
if (!element) {
return false;
}
const inlineStyle = (element.getAttribute('style') || '').trim();
if (styleIndicatesLiked(inlineStyle)) {
return true;
}
try {
const computed = window.getComputedStyle(element);
if (computed && computed.color && styleIndicatesLiked(computed.color)) {
return true;
}
} catch (error) {
console.debug('[FB Tracker] Unable to inspect computed style:', error);
}
return false;
}
function isPostLikedByCurrentUser(likeButton, postElement) { function isPostLikedByCurrentUser(likeButton, postElement) {
const candidates = []; const candidates = [];
if (likeButton) { if (likeButton) {
@@ -887,27 +922,28 @@ function isPostLikedByCurrentUser(likeButton, postElement) {
continue; continue;
} }
if (elementIndicatesLiked(candidate)) {
return true;
}
const styleTarget = candidate.matches('[data-ad-rendering-role*="gefällt" i]') const styleTarget = candidate.matches('[data-ad-rendering-role*="gefällt" i]')
? candidate ? candidate
: candidate.querySelector && candidate.querySelector('[data-ad-rendering-role*="gefällt" i]'); : candidate.querySelector && candidate.querySelector('[data-ad-rendering-role*="gefällt" i]');
if (styleTarget) { if (styleTarget) {
const inlineStyle = (styleTarget.getAttribute('style') || '').trim(); if (elementIndicatesLiked(styleTarget)) {
if (inlineStyle && /(#0?866ff|reaction-like)/i.test(inlineStyle)) {
return true; return true;
} }
}
try { const styledDescendant = candidate.querySelector && candidate.querySelector('[style*="reaction-like"], [style*="#0866FF"], [style*="rgb(8, 102, 255)"], [style*="--reaction-like"]');
const computed = window.getComputedStyle(styleTarget); if (styledDescendant && elementIndicatesLiked(styledDescendant)) {
if (computed && computed.color) { return true;
const color = computed.color.toLowerCase(); }
if (color.includes('rgb(8, 102, 255)') || color.includes('rgba(8, 102, 255')) {
return true; const pressedAncestor = candidate.closest && candidate.closest('[aria-pressed="true"]');
} if (pressedAncestor && pressedAncestor !== candidate) {
} return true;
} catch (error) {
console.debug('[FB Tracker] Unable to inspect computed style for like button:', error);
}
} }
const ariaPressed = candidate.getAttribute && candidate.getAttribute('aria-pressed'); const ariaPressed = candidate.getAttribute && candidate.getAttribute('aria-pressed');
@@ -1722,7 +1758,7 @@ function extractDeadlineFromPostText(postElement) {
const extractTimeAfterIndex = (text, index) => { const extractTimeAfterIndex = (text, index) => {
const tail = text.slice(index, index + 80); const tail = text.slice(index, index + 80);
const timeMatch = /^\s*(?:[,;:-]|\b)?\s*(?:um|ab|bis|gegen|spätestens)?\s*(?:den|dem|am)?\s*(?:ca\.?)?\s*(\d{1,2})(?:[:.](\d{2}))?\s*(?:uhr|h)?/i.exec(tail); const timeMatch = /^\s*(?:\(|\[)?\s*(?:[,;:-]|\b)?\s*(?:um|ab|bis|gegen|spätestens)?\s*(?:den|dem|am)?\s*(?:ca\.?)?\s*(\d{1,2})(?:[:.](\d{2}))?\s*(?:uhr|h)?\s*(?:\)|\])?/i.exec(tail);
if (!timeMatch) { if (!timeMatch) {
return null; return null;
} }
@@ -1783,7 +1819,7 @@ function extractDeadlineFromPostText(postElement) {
} }
// Pattern for "12. Oktober" or "12 Oktober" // Pattern for "12. Oktober" or "12 Oktober"
const monthPattern = /\b(\d{1,2})\.?\s+(januar|jan|februar|feb|märz|mär|maerz|april|apr|mai|juni|jun|juli|jul|august|aug|september|sep|sept|oktober|okt|november|nov|dezember|dez)\b/gi; const monthPattern = /\b(\d{1,2})\.?\s*(januar|jan|februar|feb|märz|mär|maerz|april|apr|mai|juni|jun|juli|jul|august|aug|september|sep|sept|oktober|okt|november|nov|dezember|dez)\b/gi;
let monthMatch; let monthMatch;
while ((monthMatch = monthPattern.exec(fullText)) !== null) { while ((monthMatch = monthPattern.exec(fullText)) !== null) {
const day = parseInt(monthMatch[1], 10); const day = parseInt(monthMatch[1], 10);
@@ -2682,7 +2718,8 @@ function findPosts() {
console.log('[FB Tracker] Found', postContainers.length, 'candidate containers'); console.log('[FB Tracker] Found', postContainers.length, 'candidate containers');
let processed = 0; let processed = 0;
const isSearchResultsPage = window.location.pathname.startsWith(SEARCH_RESULTS_PATH); const pathname = window.location.pathname || '';
const isSearchResultsPage = typeof pathname === 'string' && pathname.startsWith(SEARCH_RESULTS_PATH_PREFIX);
for (const { container: originalContainer, likeButton, buttonBar: precomputedButtonBar } of postContainers) { for (const { container: originalContainer, likeButton, buttonBar: precomputedButtonBar } of postContainers) {
let container = ensurePrimaryPostElement(originalContainer); let container = ensurePrimaryPostElement(originalContainer);

View File

@@ -1526,6 +1526,27 @@ function calculateUrgencyScore(postItem) {
} }
} }
// Recent participation (<24h) should lower urgency regardless of deadline pressure
if (hoursSinceLastCheck < 24) {
const freshnessRatio = (24 - hoursSinceLastCheck) / 24; // 0 (at 24h) to 1 (just now)
const recencyPenalty = 60 + Math.round(freshnessRatio * 120); // 60-180 point penalty
score += recencyPenalty;
}
// Give extra priority to posts with deadlines approaching soon
if (hoursUntilDeadline < Infinity && remaining > 0) {
const urgencyWindowHours = 72;
const cappedHours = Math.min(hoursUntilDeadline, urgencyWindowHours);
const closenessRatio = 1 - (cappedHours / urgencyWindowHours); // 0-1
if (closenessRatio > 0) {
const baseBoost = Math.round(closenessRatio * 120); // Up to 120 points
const remainingFactor = Math.min(1.6, 0.7 + remaining * 0.3); // 1.0 (1 remaining) .. 1.6 (>=3 remaining)
const deadlineBoost = Math.round(baseBoost * remainingFactor);
score -= deadlineBoost;
}
}
return score; return score;
} }