Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed api call for heading text, icon visibilty for ai summarizer #66

Merged
merged 4 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { getLocale } from '../api/localeAPI'
import { addSiteCosmeticFilter } from '../api/cosmeticFilterAPI'
import { signDocument } from '../docSigner'
import { highContrast } from '../highContrastBg'

export let rule = {
host: '',
Expand Down Expand Up @@ -57,6 +58,13 @@ chrome.contextMenus.create({
contexts: ['all']
})

chrome.contextMenus.create({
title: 'High contrast mode',
id: 'highContrast',
parentId: 'brave',
contexts: ['all']
})

chrome.contextMenus.onClicked.addListener((info: chrome.contextMenus.OnClickData, tab: chrome.tabs.Tab) => {
onContextMenuClicked(info, tab)
})
Expand Down Expand Up @@ -94,6 +102,9 @@ export function onContextMenuClicked (info: chrome.contextMenus.OnClickData, tab
case 'documentSigner':
signDocument();
break
case 'highContrast':
highContrast();
break
default: {
console.warn(`[cosmeticFilterEvents] invalid context menu option: ${info.menuItemId}`)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
//@ts-nocheck
export const highContrast = () => {
chrome.tabs.query({active: true, currentWindow: true}, (tabs:any) => {
chrome.tabs.sendMessage(tabs[0].id, {action: "toggleContrast"});
});
}

chrome.commands.onCommand.addListener((command) => {
if (command === "toggle-contrast") {
chrome.tabs.query({active: true, currentWindow: true}, (tabs:any) => {
Expand Down
58 changes: 58 additions & 0 deletions components/ping_ai_copilot/extension/constants/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export const translations = [
{ language: 'Amharic', code: 'am', translation: 'አንብብ እና አጠቃላይ' },
{ language: 'Arabic', code: 'ar', translation: 'ملخص النص' },
{ language: 'Basque', code: 'eu', translation: 'Testu laburpena' },
{ language: 'Bengali', code: 'bn', translation: 'পাঠের সারসংক্ষেপ' },
{ language: 'English (UK)', code: 'en-GB', translation: 'Text summary' },
{ language: 'Portuguese (Brazil)', code: 'pt-BR', translation: 'Resumo do texto' },
{ language: 'Bulgarian', code: 'bg', translation: 'Резюме на текста' },
{ language: 'Catalan', code: 'ca', translation: 'Resum del text' },
{ language: 'Cherokee', code: 'chr', translation: 'ᏅᏙᎢ ᏣᎳᎩ' },
{ language: 'Croatian', code: 'hr', translation: 'Sažetak teksta' },
{ language: 'Czech', code: 'cs', translation: 'Shrnutí textu' },
{ language: 'Danish', code: 'da', translation: 'Tekstoversigt' },
{ language: 'Dutch', code: 'nl', translation: 'Tekstsamenvatting' },
{ language: 'English (US)', code: 'en', translation: 'Text summary' },
{ language: 'Estonian', code: 'et', translation: 'Teksti kokkuvõte' },
{ language: 'Filipino', code: 'fil', translation: 'Buod ng teksto' },
{ language: 'Finnish', code: 'fi', translation: 'Tekstin yhteenveto' },
{ language: 'French', code: 'fr', translation: 'Résumé du texte' },
{ language: 'German', code: 'de', translation: 'Textzusammenfassung' },
{ language: 'Greek', code: 'el', translation: 'Περίληψη κειμένου' },
{ language: 'Gujarati', code: 'gu', translation: 'પાઠનું સારાંશ' },
{ language: 'Hebrew', code: 'iw', translation: 'סיכום טקסט' },
{ language: 'Hindi', code: 'hi', translation: 'पाठ सारांश' },
{ language: 'Hungarian', code: 'hu', translation: 'Szöveges összefoglaló' },
{ language: 'Icelandic', code: 'is', translation: 'Textayfirlit' },
{ language: 'Indonesian', code: 'id', translation: 'Ringkasan teks' },
{ language: 'Italian', code: 'it', translation: 'Riassunto del testo' },
{ language: 'Japanese', code: 'ja', translation: 'テキストの要約' },
{ language: 'Kannada', code: 'kn', translation: 'ಪಠ್ಯದ ಸಾರಾಂಶ' },
{ language: 'Korean', code: 'ko', translation: '텍스트 요약' },
{ language: 'Latvian', code: 'lv', translation: 'Teksta kopsavilkums' },
{ language: 'Lithuanian', code: 'lt', translation: 'Teksto santrauka' },
{ language: 'Malay', code: 'ms', translation: 'Ringkasan teks' },
{ language: 'Malayalam', code: 'ml', translation: 'പാഠത്തിന്റെ ചുരുക്കം' },
{ language: 'Marathi', code: 'mr', translation: 'पाठ सारांश' },
{ language: 'Norwegian', code: 'no', translation: 'Tekstoppsummering' },
{ language: 'Polish', code: 'pl', translation: 'Podsumowanie tekstu' },
{ language: 'Portuguese (Portugal)', code: 'pt-PT', translation: 'Resumo do texto' },
{ language: 'Romanian', code: 'ro', translation: 'Rezumatul textului' },
{ language: 'Russian', code: 'ru', translation: 'Резюме текста' },
{ language: 'Serbian', code: 'sr', translation: 'Kratak pregled teksta' },
{ language: 'Chinese (PRC)', code: 'zh-CN', translation: '文本摘要' },
{ language: 'Slovak', code: 'sk', translation: 'Súhrn textu' },
{ language: 'Slovenian', code: 'sl', translation: 'Povzetek besedila' },
{ language: 'Spanish', code: 'es', translation: 'Resumen del texto' },
{ language: 'Swahili', code: 'sw', translation: 'Muhtasari wa maandiko' },
{ language: 'Swedish', code: 'sv', translation: 'Textsammanfattning' },
{ language: 'Tamil', code: 'ta', translation: 'உரை சுருக்கம்' },
{ language: 'Telugu', code: 'te', translation: 'పాఠం సంక్షిప్తం' },
{ language: 'Thai', code: 'th', translation: 'สรุปข้อความ' },
{ language: 'Chinese (Taiwan)', code: 'zh-TW', translation: '文本摘要' },
{ language: 'Turkish', code: 'tr', translation: 'Metin özeti' },
{ language: 'Urdu', code: 'ur', translation: 'متن کا خلاصہ' },
{ language: 'Ukrainian', code: 'uk', translation: 'Резюме тексту' },
{ language: 'Vietnamese', code: 'vi', translation: 'Tóm tắt văn bản' },
{ language: 'Welsh', code: 'cy', translation: 'Crynodeb testun' }
];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let summarizer = null;
let summaryBox = null;
let isTextSelected = false;
let lastSelectedText = '';

const initializeExtension = () => {
document.removeEventListener('mouseup', handleTextSelection);
Expand All @@ -11,9 +11,12 @@ const initializeExtension = () => {
const handleTextSelection = (event) => {
const selection = window.getSelection();
const selectedText = selection.toString().trim();
if (selectedText.length > 0 && !(summaryBox && summaryBox.contains(selection.anchorNode))) {
isTextSelected = true
showSummarizeIcon(selectedText, event);
const wordCount = selectedText.split(/\s+/).length;
if (wordCount >= 10 && wordCount <= 1000 && !(summaryBox && summaryBox.contains(selection.anchorNode))) {
if (selectedText !== lastSelectedText) {
showSummarizeIcon(selectedText, event);
lastSelectedText = selectedText;
}
} else {
hideSummarizeIcon();
}
Expand Down Expand Up @@ -49,10 +52,8 @@ const showSummarizeIcon = (selectedText, event) => {
document.body.appendChild(summarizer);
}

if (isTextSelected) {
summarizer.style.top = `${event.clientY}px`;
summarizer.style.left = `${event.clientX}px`;
}
summarizer.style.top = `${event.clientY}px`;
summarizer.style.left = `${event.clientX}px`;

summarizer.style.display = 'inline-block';
}
Expand Down
5 changes: 2 additions & 3 deletions components/ping_ai_copilot/extension/content/ui/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@

#summarizer-icon {
position: fixed;
z-index: 999999;
z-index: 1000000000 !important;
border-radius: 50%;
}

#iconImage {
z-index: 999999;
width: 45px;
height: 45px;
border-radius: 50%;
Expand All @@ -45,7 +44,7 @@
bottom: 20px;
right: 20px;
width: 360px;
z-index: 999999;
z-index: 1000000000 !important;
border-radius: 24px;
border-top: 7px solid #2BB563;
border-bottom: 7px solid #2BB563;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { translations } from "../constants/constants.js"
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'summarize') {
(async () => {
try {
let ln = chrome.i18n.getUILanguage();
let headerText = 'Text summary';
const translation = translations.find(t => t.code === ln);
if (translation) {
headerText = translation.translation;
}
const response = await fetch('https://openai-text-summarizer.azurewebsites.net/summarize', {
method: 'POST',
headers: {
Expand All @@ -12,7 +18,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
});

const data = await response.json();
chrome.tabs.sendMessage(sender.tab.id, { action: 'displaySummary', summary: data.summary, headerText: data.headerText }, response => {
chrome.tabs.sendMessage(sender.tab.id, { action: 'displaySummary', summary: data.summary, headerText: headerText }, response => {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError);
}
Expand Down
Loading