| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| export class ContentFingerprint {
|
| |
| |
| |
| |
| |
|
|
| static generate(element) {
|
| if (!element) return null;
|
|
|
| const tag = element.tagName.toLowerCase();
|
| const text = element.textContent.trim();
|
|
|
|
|
| const contentPreview = text.substring(0, 80);
|
|
|
|
|
| const fingerprint = `${tag}:${contentPreview}:${text.length}`;
|
|
|
|
|
| return this.simpleHash(fingerprint);
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| static generateStable(element) {
|
| if (!element) return null;
|
|
|
| const tag = element.tagName.toLowerCase();
|
| const text = element.textContent.trim();
|
|
|
|
|
| const primary = this.generate(element);
|
|
|
|
|
| const partialText = text.substring(0, 30);
|
| const secondary = this.simpleHash(`${tag}:${partialText}`);
|
|
|
|
|
| const pattern = this.extractPattern(text);
|
| const tertiary = this.simpleHash(`${tag}:${pattern}`);
|
|
|
| return {
|
| primary,
|
| secondary,
|
| tertiary,
|
| tag,
|
| length: text.length,
|
| preview: text.substring(0, 50)
|
| };
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| static extractPattern(text) {
|
| return text
|
| .replace(/\d+/g, '#')
|
| .replace(/[a-zA-Z]{4,}/g, 'W')
|
| .substring(0, 40);
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| static simpleHash(str) {
|
| let hash = 5381;
|
| for (let i = 0; i < str.length; i++) {
|
| hash = ((hash << 5) + hash) + str.charCodeAt(i);
|
| hash = hash & hash;
|
| }
|
| return Math.abs(hash).toString(36);
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
| static match(stableFingerprint, savedSettings) {
|
| if (!stableFingerprint || !savedSettings || !savedSettings.length) {
|
| return null;
|
| }
|
|
|
|
|
| let matched = savedSettings.find(s =>
|
| s.fingerprint?.primary === stableFingerprint.primary
|
| );
|
| if (matched) {
|
| matched.matchConfidence = 'exact';
|
| return matched;
|
| }
|
|
|
|
|
| matched = savedSettings.find(s =>
|
| s.fingerprint?.secondary === stableFingerprint.secondary &&
|
| s.fingerprint?.tag === stableFingerprint.tag
|
| );
|
| if (matched) {
|
| matched.matchConfidence = 'high';
|
| return matched;
|
| }
|
|
|
|
|
| matched = savedSettings.find(s =>
|
| s.fingerprint?.tertiary === stableFingerprint.tertiary &&
|
| s.fingerprint?.tag === stableFingerprint.tag
|
| );
|
| if (matched) {
|
| matched.matchConfidence = 'medium';
|
| return matched;
|
| }
|
|
|
|
|
| matched = savedSettings.find(s =>
|
| s.fingerprint?.tag === stableFingerprint.tag &&
|
| Math.abs(s.fingerprint?.length - stableFingerprint.length) < 10
|
| );
|
| if (matched) {
|
| matched.matchConfidence = 'low';
|
| return matched;
|
| }
|
|
|
| return null;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| static generateSlideFingerprint(sceneElement) {
|
| if (!sceneElement) return null;
|
|
|
| const elements = sceneElement.querySelectorAll('h1, h2, h3, h4, h5, h6, p, li, blockquote');
|
| const fingerprints = Array.from(elements).map(el => this.generate(el));
|
|
|
| return this.simpleHash(fingerprints.join('|'));
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| static hasSlideChanged(oldFingerprint, newFingerprint) {
|
| return oldFingerprint !== newFingerprint;
|
| }
|
|
|
| |
| |
| |
| |
| |
| |
|
|
| static mapSlideElements(sceneElement) {
|
| if (!sceneElement) return [];
|
|
|
| const elements = sceneElement.querySelectorAll('h1, h2, h3, h4, h5, h6, p, li, blockquote');
|
|
|
| return Array.from(elements).map((element, index) => ({
|
| element,
|
| fingerprint: this.generateStable(element),
|
| index,
|
| tag: element.tagName.toLowerCase()
|
| }));
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| static isValid(fingerprint) {
|
| return fingerprint &&
|
| fingerprint.primary &&
|
| fingerprint.secondary &&
|
| fingerprint.tertiary &&
|
| fingerprint.tag;
|
| }
|
|
|
| |
| |
| |
| |
| |
|
|
| static debug(fingerprint) {
|
| if (!fingerprint) return 'null';
|
|
|
| return `
|
| Fingerprint Debug:
|
| - Primary: ${fingerprint.primary}
|
| - Secondary: ${fingerprint.secondary}
|
| - Tertiary: ${fingerprint.tertiary}
|
| - Tag: ${fingerprint.tag}
|
| - Length: ${fingerprint.length}
|
| - Preview: "${fingerprint.preview}"
|
| `.trim();
|
| }
|
| }
|
|
|
|
|
| export default ContentFingerprint;
|
|
|