From 7903f427765be52a1cacfa4adf319de86de052a0 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 7 Mar 2024 14:49:22 +0800 Subject: [PATCH] Improve read autofill contents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化自动填写表单的获取(YouTube --- contents/read.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/contents/read.ts b/contents/read.ts index 689c16d..ff76850 100644 --- a/contents/read.ts +++ b/contents/read.ts @@ -1,5 +1,15 @@ const getTitle = () => { const title = document.title; + const metaTitle = document.querySelector(`meta[name="title"]`); + const metaOgTitle = document.querySelector(`meta[name="og:title"]`); + + if (metaOgTitle) { + return metaOgTitle.getAttribute("content");; + } + + if (metaTitle) { + return metaTitle.getAttribute("content");; + } if (title.includes(" - ")) { const end = title.lastIndexOf(" - "); @@ -47,7 +57,7 @@ const getFrom = () => { const getAuthor = () => { const metaAuthor = document.querySelector(`meta[name="author"]`); const metaOgAuthor = document.querySelector(`meta[property="og:article:author"]`); - const itemPropAuthor = document.querySelector(`[itemprop="author"] meta[itemprop="name"]`); + const itemPropAuthor = document.querySelector(`[itemprop="author"] [itemprop="name"]`); if (metaAuthor) { return metaAuthor.getAttribute("content"); @@ -98,8 +108,13 @@ const getSiteName = () => { } const getTags = () => { + const metaKeywords = document.querySelector(`meta[name="keywords"]`); const itemPropKeywords = document.querySelector(`meta[itemprop="keywords"]`); + if (metaKeywords) { + return metaKeywords.getAttribute("content"); + } + if (itemPropKeywords) { return itemPropKeywords.getAttribute("content"); }