diff --git a/NewClient/public/scripts/background/eventPage.js b/NewClient/public/scripts/background/eventPage.js index 78e7bfd1..912320dd 100644 --- a/NewClient/public/scripts/background/eventPage.js +++ b/NewClient/public/scripts/background/eventPage.js @@ -275,20 +275,30 @@ chrome.contextMenus.onClicked.addListener(function(clickData){ // ############################# summarizar ############################ if (clickData.menuItemId === 'summarizar') { let targetUrl = clickData.selectionText; + fetch(`${CONFIG.SUMMARIZE_API_URL}/pred?text=` + encodeURIComponent(targetUrl)) - .then(response => response.json()) - .then(data => { - // Extract the result from the response - let resultText = data.Result; - - chrome.windows.create({ - url: 'scripts/content/summarizar/summarizar.html?summary=' + encodeURIComponent(resultText), - focused: true, - type: 'popup' - }); - }) - .catch(error => console.error('Error fetching the summary:', error)); - } + .then(response => { + if (!response.ok) { + throw new Error('Failed to fetch the summary. Server responded with ' + response.status); + } + return response.json(); + }) + .then(data => { + if (data.Result) { + // Extract the result from the response + let resultText = data.Result; + + chrome.windows.create({ + url: 'scripts/content/summarizar/summarizar.html?summary=' + encodeURIComponent(resultText), + focused: true, + type: 'popup' + }); + } else { + console.error('No summary result found:', data); + } + }) + .catch(error => console.error('Error fetching the summary:', error)); +} // // ######################### Fake News New API ################################## diff --git a/NewClient/public/scripts/content/summarizar/populateContent.js b/NewClient/public/scripts/content/summarizar/populateContent.js index 49e77b85..38a52ec9 100644 --- a/NewClient/public/scripts/content/summarizar/populateContent.js +++ b/NewClient/public/scripts/content/summarizar/populateContent.js @@ -1,9 +1,28 @@ -// Function to get the query parameter from the URL +// Function to get query parameter function getQueryParam(param) { - let urlParams = new URLSearchParams(window.location.search); + const urlParams = new URLSearchParams(window.location.search); return urlParams.get(param); } -// Get the summary from the URL and display it -let summaryText = getQueryParam('summary'); -document.getElementById('summary').textContent = decodeURIComponent(summaryText); +// Function to parse markdown and render HTML +function parseMarkdown(markdown) { + return markdown + .replace(/^# (.*$)/gim, '

$1

') // H1 + .replace(/^## (.*$)/gim, '

$1

') // H2 + .replace(/^### (.*$)/gim, '

$1

') // H3 + .replace(/^\* (.*$)/gim, '') // Bullet list + .replace(/^\d+\. (.*$)/gim, '
  1. $1
') // Numbered list + .replace(/`([^`]+)`/g, '$1') // Inline code + .replace(/\*\*(.*?)\*\*/g, '$1') // Bold + .replace(/\*(.*?)\*/g, '$1') // Italics + .replace(/\n/gim, '
'); // Line breaks +} + +// Render the parsed content +const summaryText = getQueryParam('summary'); +if (summaryText) { + const parsedHTML = parseMarkdown(decodeURIComponent(summaryText)); + document.getElementById('content').innerHTML = parsedHTML; +} else { + document.getElementById('content').innerHTML = "

No summary content provided.

"; +} \ No newline at end of file diff --git a/NewClient/public/scripts/content/summarizar/style.css b/NewClient/public/scripts/content/summarizar/style.css new file mode 100644 index 00000000..aed0511b --- /dev/null +++ b/NewClient/public/scripts/content/summarizar/style.css @@ -0,0 +1,75 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + font-family: 'Arial', sans-serif; + background-color: #f4f6f9; + color: #333; + line-height: 1.6; + padding: 20px; +} + +/* Header */ +header { + text-align: center; + margin-bottom: 20px; +} + +header h1 { + font-size: 2.5rem; + color: #2c3e50; +} + +header .tagline { + font-size: 1.2rem; + color: #7f8c8d; + margin-top: 5px; +} + +/* Content Styling */ +main { + background: #fff; + border-radius: 8px; + box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); + padding: 20px; +} + +main h2 { + color: #34495e; + margin-bottom: 10px; +} + +main ul { + list-style: disc inside; + margin-bottom: 20px; + padding-left: 20px; +} + +main ol { + list-style: decimal inside; + margin-bottom: 20px; + padding-left: 20px; +} + +main li { + margin-bottom: 5px; +} + +main pre { + background: #ecf0f1; + padding: 15px; + border-radius: 5px; + overflow-x: auto; + font-family: monospace; +} + +main code { + font-family: monospace; + background: #e8f7ff; + padding: 2px 4px; + border-radius: 4px; + color: #2c3e50; +} \ No newline at end of file diff --git a/NewClient/public/scripts/content/summarizar/summarizar.html b/NewClient/public/scripts/content/summarizar/summarizar.html index 9c95b315..76a34c1d 100644 --- a/NewClient/public/scripts/content/summarizar/summarizar.html +++ b/NewClient/public/scripts/content/summarizar/summarizar.html @@ -3,20 +3,17 @@ - Summary - + Social Street Smart: Summary + -

Summary

-
- +
+

Social Street Smart

+

A Safer Internet Experience

+
+
+
+
+ - + \ No newline at end of file