From ff78899cc72c62114fc0997cac6c72dcc9e9893e Mon Sep 17 00:00:00 2001 From: ItsVipra Date: Tue, 11 Jul 2023 14:26:03 +0200 Subject: [PATCH] search closest article, if element doesn't have an id --- src/content_scripts/protoots.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/content_scripts/protoots.js b/src/content_scripts/protoots.js index d99d005..0946703 100644 --- a/src/content_scripts/protoots.js +++ b/src/content_scripts/protoots.js @@ -215,13 +215,18 @@ async function addProplate(element) { * @returns {string} */ function getID(element) { - const id = element.dataset.id; + let id = element.dataset.id; if (!id) { // We don't have a status ID, pronouns might not be in cache warn( - "The element passed to addProplate does not have a data-id attribute, although it should have one.", + "The element passed to addProplate does not have a data-id attribute, searching for article.", element, ); + //if we couldn't get an id from the div try the closest article + const ArticleElement = element.closest("article"); + if (ArticleElement) { + id = getID(ArticleElement); + } } return id; }