commit da2cfb1bb8da9239cb9869292562f085bc1a67bd Author: Ludger Sicking Date: Tue Aug 20 11:35:23 2024 +0200 initial nostreratu diff --git a/background.js b/background.js new file mode 100644 index 0000000..bc816b3 --- /dev/null +++ b/background.js @@ -0,0 +1,7 @@ +// background.js + +chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { + if (message.type === "ldJsonData") { + chrome.storage.local.set({ ldJsonData: message.data }); + } +}); diff --git a/contentScript.js b/contentScript.js new file mode 100644 index 0000000..ab909d8 --- /dev/null +++ b/contentScript.js @@ -0,0 +1,55 @@ +// contentScript.js + +// Function to find and return the content of ld+json scripts +function findLDJSONScripts() { + const scripts = document.querySelectorAll('script[type="application/ld+json"]'); + //const scripts = document.querySelectorAll('class'); + const jsonData = []; + + //console.log(scripts); // Steffen debugging + + scripts.forEach(script => { + try { + const json = JSON.parse(script.textContent); + jsonData.push(json); + } catch (e) { + console.error("Error parsing JSON-LD", e); + } + }); + + return jsonData; +} + +window.addEventListener('load', myMain); + +function myMain() { + //alert('Die Seite wurde vollständig geladen!'); + + console.log("DOM fully loaded and parsed"); + + const ldJsonData = findLDJSONScripts(); + + if (ldJsonData.length > 0) { + + console.log("LD+JSON scripts found:", ldJsonData); + + // Option 1: Render on the same page (e.g., append to body) + const pre = document.createElement('pre'); + pre.textContent = JSON.stringify(ldJsonData, null, 2); + document.body.appendChild(pre); + + // Option 2: Send data to the background script for the popup + chrome.runtime.sendMessage({type: "ldJsonData", data: ldJsonData}); + } +} + +// //window.onload +// window.addEventListener('load', Meldung); +// //document.addEventListener("DOMContentLoaded", function() { +// //window.addEventListener("load", function() { +// //document.addEventListener("DOMContentLoaded", function() { +// // Your code here will run after the DOM is fully loaded +// }); +// Send the extracted JSON-LD data to the popup or render it directly +//const ldJsonData = findLDJSONScripts(); + diff --git a/icons/icon128.png b/icons/icon128.png new file mode 100644 index 0000000..7e3bba0 Binary files /dev/null and b/icons/icon128.png differ diff --git a/icons/icon48.png b/icons/icon48.png new file mode 100644 index 0000000..dfed4b8 Binary files /dev/null and b/icons/icon48.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..b3887c8 --- /dev/null +++ b/manifest.json @@ -0,0 +1,26 @@ +{ + "manifest_version": 3, + "name": "LD+JSON Script Checker", + "version": "1.0", + "description": "Checks for ld+json script tags and renders their content.", + "permissions": [ + "activeTab" + ], + "action": { + "default_popup": "popup.html", + "default_icon": { + "48": "icons/icon48.png", + "128": "icons/icon128.png" + } + }, + "background": { + "service_worker": "background.js" + }, + "content_scripts": [ + { + "matches": [""], + "js": ["contentScript.js"] + } + ] + } + \ No newline at end of file diff --git a/popup.html b/popup.html new file mode 100644 index 0000000..f910e1c --- /dev/null +++ b/popup.html @@ -0,0 +1,19 @@ + + + + + + LD+JSON Content + + + +

LD+JSON Content

+
+ + + \ No newline at end of file diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..b94b823 --- /dev/null +++ b/popup.js @@ -0,0 +1,12 @@ +// popup.js + +chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { + if (request.type === "ldJsonData") { + const contentDiv = document.getElementById('content'); + request.data.forEach(json => { + const pre = document.createElement('pre'); + pre.textContent = JSON.stringify(json, null, 2); + contentDiv.appendChild(pre); + }); + } +});