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

[pull] master from ClearlyKyle:master #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
53 changes: 37 additions & 16 deletions content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,11 +287,9 @@
}
else if (window.location.href.includes("netflix.com/watch"))
{
// Replace 'yourElementId' with the ID of your element or use another way to select your element
const dictionary_element = document.getElementsByClassName('lln-full-dict')[0];
const extern_dict_row_element = document.getElementsByClassName('lln-external-dicts-row')[0];

// Send a message to background.js requesting to capture the visible tab

dictionary_element.style.visibility = "hidden";
extern_dict_row_element.style.visibility = "hidden";

Expand All @@ -305,6 +303,7 @@
{
if (response && response.imageData)
{
// Do we need to rest this as visible again?
dictionary_element.style.visibility = "visible";
extern_dict_row_element.style.visibility = "visible";

Expand All @@ -320,7 +319,6 @@
{
reject(new Error('Failed to capture image data'));
}
console.log('Captured image data:', response);
});
}, 500);
});
Expand Down Expand Up @@ -384,7 +382,6 @@
// this is set with the "Translation language" in the options of LLWYT
if (document.getElementsByClassName('lln-whole-title-translation').length)
{
//"var" is FUNCTION scoped and "let" is BLOCK scoped
var subtitle_translation = document.getElementsByClassName('lln-whole-title-translation')[0].innerText;
//let subtitle_translation = document.getElementsByClassName('lln-whole-title-translation')[0].innerText.replace('\n', ' ');
}
Expand All @@ -396,26 +393,50 @@
chrome.storage.local.get("ankiExampleSentenceSource", ({ ankiExampleSentenceSource }) =>
{
console.log("Getting example setting toggle: ", ankiExampleSentenceSource)

// Getting Example sentences
// There are two sets of example sentences, so we can choose between which set we want
// TODO : default to one or none if there is nothing
// const ankiExampleSentenceSource = "Both";
var example_sentences = "";
const example_sentences_element = document.getElementsByClassName('lln-word-examples');
if (example_sentences_element.length)
{
// We default to using current
const current_or_tatoeba = ankiExampleSentenceSource === "Tatoeba" ? 1 : 0;
var example_sentences_list = [];
switch (ankiExampleSentenceSource) {
case "Both":
// Convert HTMLCollections to arrays and remove the first element from each
if (example_sentences_element[0])
{
example_sentences_list = Array.from(example_sentences_element[0].children).slice(1);
}
if (example_sentences_element[1])
{
const tmp = Array.from(example_sentences_element[1].children).slice(1);
example_sentences_list = example_sentences_list.concat(tmp);
}

const example_sentences_list = example_sentences_element[current_or_tatoeba];
if(example_sentences_list)
{
const all_examples = example_sentences_list.children;
for (var i = 1; i != all_examples.length; i++)
{
example_sentences += all_examples[i].innerText + "<br>";
}
break;
case "Current":
if(example_sentences_element[0])
example_sentences_list = Array.from(example_sentences_element[0].children).slice(1);
break;
case "Tatoeba":
if(example_sentences_element[1])
example_sentences_list = Array.from(example_sentences_element[1].children).slice(1);
break;
case "None": // fallthrough
default:
example_sentences_list = []; // Default case if none matches
break;
}

//console.log(example_sentences_list);

example_sentences_list.forEach(element => {
example_sentences += element.innerText + "<br>";
});
}
//console.log(example_sentences);

var fields = {
"image-filename": image_filename || "",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"name": "LLW to Anki",
"description": "Save words from languagereactor video subtitles and send to Anki",
"version": "2.1",
"version": "2.2",
"author": "@clearlykyle",
"permissions": [
"storage"
Expand Down
2 changes: 2 additions & 0 deletions popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
<select id="ankiExampleSentenceSource">
<option value="Current">Current</option>
<option value="Tatoeba">Tatoeba</option>
<option value="Both">Both</option>
<option value="None">None</option>
</select>
</label>
<label>
Expand Down