Conversation
|
I have tried multiple approach for text transformation. As it transform the text as per function deined in index.js but the previous selected not removed from edit text. After selecting those text and then calling AnkiJSFunction from index.js function using js-evaluator, it transform the text return the following string to caller function The text |
Codecov Report
@@ Coverage Diff @@
## master #8011 +/- ##
============================================
- Coverage 37.02% 36.59% -0.43%
+ Complexity 3847 3801 -46
============================================
Files 361 360 -1
Lines 36337 36384 +47
Branches 4804 4798 -6
============================================
- Hits 13453 13316 -137
- Misses 21352 21552 +200
+ Partials 1532 1516 -16
Continue to review full report at Codecov.
|
|
Needs improvement |
Update addon info popup layout and remove prefs when addon delete
- added volley library for downloading json from npmjs - code cleanup
send deck name, model name, fields count, fields name and selected text in json format to js addon receive json format data with changed text and data that needs to be inserted to fields with index
|
Update: provide these to js addon in json format and receive changed data in json format data changed by js addon and pass to AnkiDroid To be implemented Usage of above implementation in new AnkiDroid Cloze Overlapper Mini JS Addon View index.jsfunction AnkiJSFunction(data) {
var jsonData = JSON.parse(data);
var selectedText = jsonData['selectedText'];
var newJsonData = {};
var fieldsData = {};
if (jsonData['noteType'] == "ocloze-infi" && jsonData["fieldsCount"] == 26) {
newJsonData["changedText"] = ""; // intentionally empty
var list = selectedText.split("\n");
var fullText = "";
var len = list.length;
var startField = 5;
for (i = 0; i < len; i++) {
var text = "";
fullText += "<div>{{c21::" + list[i] + "}}</div>";
for (j = 0; j < len; j++) {
if (i == j) {
if (j > 0) {
text += "<div>" + list[j - 1] + "</div>";
}
text += "<div>{{c" + (j + 1) + "::" + list[j] + "}}</div>";
} else {
text += "<div>...</div>";
}
}
fieldsData[startField] = text;
startField++;
}
fieldsData[25] = fullText;
newJsonData["addToFields"] = fieldsData;
}
return JSON.stringify(newJsonData);
}Cloze generated by js addon |
option to change selected text with following option : replace, append, clear, default
|
Implemented: change selected text according to option : Click to view index.jsAnkiDroid <-- JS Addon
function AnkiJSFunction(data) {
var jsonData = JSON.parse(data);
var selectedText = jsonData['selectedText'];
var newJsonData = {};
newJsonData["changedText"] = "<sub>"+ selectedText +"</sub>";
// changeType options - replace, append, clear, default
newJsonData["changeType"] = "replace";
return JSON.stringify(newJsonData);
} |
|
This continuation of previous PR #7958. So, I will mark it ready for review after merge of previous one. Some files are same in both PR. |
…to note-editor-addon
|
Hello 👋, this PR has been opened for more than 2 months with no activity on it. If you think this is a mistake please comment and ping a maintainer to get this merged ASAP! Thanks for contributing! You have 7 days until this gets closed automatically |
|
Ugh - not stale just so maxed out stabilizing all the GSoC work on the release-2.15 branch |
|
I will re-implement this js addons feature with more number of PR. I will divide this PR in small part so reviewing will take less time. |


Pull Request template
Purpose / Description
This continuation of previous PR #7958. As Anki desktop have python for creating addons. But in AnkiDroid Java and JavaScript can be used to create addons. This PR is implemented for running JavaScript addon.
Fixes
Fixes #7959
Approach
Most of enable and disable logic part and code of PR #7958 is used in this. But for note editor tool bar.
Created Horizontal recycler view at bottom
Added button when SharedPreferences have enable status of addons.
Copy the index.js file code and pass to js-evaluator function.
When a string selected in Note editor and Addon button pressed then selected text in FieldEditText passed to
js-evaluatorand the function defined in index.js file perform logic on that string then return it to caller.How Has This Been Tested?
AnkiDroid / addons / ankidroid-js-addon-some-nameThe
package.jsonfile contains following for converting space separated text to list.Note: The package.json must contains
name, ankidroid_js_api, addon_type, addon_icon.Here addon icon single letter.index.jsfile contains followingNote: The name in index.js must be
AnkiJSFunctionit will be called byjs-evaluator.Demo

Learning (optional, can help others)
https://github.com/evgenyneu/js-evaluator-for-android/
https://developer.android.com/guide/topics/ui/layout/recyclerview
Checklist
Please, go through these checks before submitting the PR.
ifstatements)