diff --git a/src/extractor.ts b/src/extractor.ts index 7733055..5733e2c 100644 --- a/src/extractor.ts +++ b/src/extractor.ts @@ -143,16 +143,27 @@ class Extractor implements ExtractorInterface { extractArticleInfo (): ArticleInfo { const articleInfoSelectors = ['query', 'edition', 'date'] const articleInfo: RawArticleInfo = {} - for (const key of articleInfoSelectors) { - if (this.site.selectors[key]) { - const selector = this.site.selectors[key] - let result = this.runSelectorQuery(selector) - if (result instanceof window.HTMLElement) { - result = result.innerText + + if (this.site.extractId) { + const idFromCustomFunc = this.site.extractId() + if (idFromCustomFunc) { + articleInfo.query = idFromCustomFunc + } + } + + if (!articleInfo.query) { + for (const key of articleInfoSelectors) { + if (this.site.selectors[key]) { + const selector = this.site.selectors[key] + let result = this.runSelectorQuery(selector) + if (result instanceof window.HTMLElement) { + result = result.innerText + } + articleInfo[key] = result } - articleInfo[key] = result } } + return { query: articleInfo.query, edition: articleInfo.edition, diff --git a/src/sites.ts b/src/sites.ts index c3d7a34..20de653 100644 --- a/src/sites.ts +++ b/src/sites.ts @@ -94,7 +94,7 @@ const sites: Sites = { { url: 'https://www.spiegel.de/politik/deutschland/klara-geywitz-ueber-sanierungspflicht-von-immobilien-neuen-wohnraum-und-fluechtlinge-a-6aeb319e-fc25-4efa-a0cf-66e10ed49969', selectors: { - query: 'nicht ohne Ordnungsrecht gehen wenn wir die Klimaziele erreichen wollen«' + query: '6aeb319e-fc25-4efa-a0cf-66e10ed49969' } } ], @@ -104,6 +104,11 @@ const sites: Sites = { main: 'article section.relative', paywall: "div[data-component='Paywall'], div[data-target-id='paywall']" }, + extractId: () => { + const url = window.location.href + const match = url.match(/-([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/) + return match ? match[1] : null + }, mimic: (content) => { return `