Skip to content

Commit

Permalink
Filter paragraphs and Wikipedia icon
Browse files Browse the repository at this point in the history
  • Loading branch information
bsogulcan committed Sep 6, 2022
1 parent bb690d7 commit b93c082
Show file tree
Hide file tree
Showing 15 changed files with 21 additions and 50 deletions.
12 changes: 0 additions & 12 deletions browserAction/index.html

This file was deleted.

Empty file removed browserAction/script.js
Empty file.
3 changes: 0 additions & 3 deletions browserAction/style.css

This file was deleted.

21 changes: 18 additions & 3 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ function onDataReceived(contentInfo) {
el.innerHTML = contentInfo.data;
paragraphs = el.getElementsByTagName('p');

const paragraphList = Object.keys(paragraphs).map(index => {
let paragraph = paragraphs[index];
return paragraph;
});

paragraphs = paragraphList.filter(x => x.innerText.length > 0 && x.className != 'mw-empty-elt' && !x.innerText.includes('Other reasons this message may be displayed'));

let wikiResultHtml = wikiResultBaseHtml.replace('{{top}}', (clientY - 40))
.replace('{{left}}', clientX);
const wikiResult = document.createElement('span');
Expand All @@ -64,15 +71,23 @@ function onDataReceived(contentInfo) {

const wikiResultTitle = document.getElementById('wiki-result-title');
wikiResultTitle.innerText = contentInfo.selectedText;
wikiResultTitle.href = 'www.google.com';

const wikiResultContent = document.getElementById('wiki-result-content');
const contentItem = document.createElement('p');
contentItem.innerText = paragraphs[0]?.innerText;
wikiResultContent.appendChild(contentItem);
lastParagraphIndex = 0;

const wikiResultLoadModeButton = document.getElementById('wiki-result-load-more');
wikiResultLoadModeButton.addEventListener("click", wikiLoadMore.bind(null), false);

if (paragraphs.length != 0) {
contentItem.innerText = paragraphs[0]?.innerText;
} else {
contentItem.innerText = 'Wikipedia does not have an article with this exact name.';
wikiResultLoadModeButton.remove();
}

wikiResultContent.appendChild(contentItem);
lastParagraphIndex = 0;
};

function wikiResultClose() {
Expand Down
Binary file removed icons/icon.png
Binary file not shown.
Binary file added icons/wikipedia-0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/wikipedia-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/wikipedia-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"manifest_version": 3,
"name": "AskWiki",
"description": "Learn from Wikipedia",
"version": "0.4.1",
"version": "0.4.2",
"icons": {
"64": "icons/icon.png"
"64": "icons/wikipedia-0.png"
},
"background": {
"service_worker": "background_script.js"
Expand All @@ -24,9 +24,8 @@
}
],
"action": {
"default_popup": "browserAction/index.html",
"default_icon": {
"64": "icons/icon.png"
"64": "icons/wikipedia-0.png"
},
"default_title": "AskWiki"
},
Expand Down
11 changes: 0 additions & 11 deletions options/index.html

This file was deleted.

Empty file removed options/script.js
Empty file.
3 changes: 0 additions & 3 deletions options/style.css

This file was deleted.

11 changes: 0 additions & 11 deletions pageAction/index.html

This file was deleted.

Empty file removed pageAction/script.js
Empty file.
3 changes: 0 additions & 3 deletions pageAction/style.css

This file was deleted.

0 comments on commit b93c082

Please sign in to comment.