Skip to content

Commit

Permalink
Merge pull request #2 from pyanderson/porting-to-firefox
Browse files Browse the repository at this point in the history
Porting to Firefox
  • Loading branch information
pyanderson committed Feb 14, 2022
2 parents 8ac2c29 + 770ddc1 commit 76d9a56
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
*.zip
*.xpi
*.crx
*.pem
src/manifest.json
# editors
*.swp
*.sublime-project
*.sublime-workspace
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Grimório do Tormenta20 para o Roll20

[Roll20: Grimório do Tormenta20](https://chrome.google.com/webstore/detail/roll20-grim%C3%B3rio-do-tormen/lplnbanhibpehlmiiakcacambjleeeng).
[Chrome Extension](https://chrome.google.com/webstore/detail/roll20-grim%C3%B3rio-do-tormen/lplnbanhibpehlmiiakcacambjleeeng)
[Firefox Extension](https://addons.mozilla.org/pt-BR/firefox/addon/roll20-grim%C3%B3rio-do-tormenta20/)

Todo o conteúdo do arquivo [src/data/spells.json](src/data/spells.json) está sob a licença [OPEN GAME LICENSE](OPEN_GAME_LICENSE).

Icons from [freepik](https://www.freepik.com).

## Notas do Desenvolvedor
- O firefox ainda não tem suporte para a versão 3 do manifest, por isso é necessário ter as duas versões disponíveis.
2 changes: 1 addition & 1 deletion src/manifest.json → chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Roll20: Grimório do Tormenta20",
"description": "Escolha magias diretamente na sua ficha!",
"version": "0.0.2",
"version": "0.0.3",
"manifest_version": 3,
"content_scripts": [
{
Expand Down
35 changes: 35 additions & 0 deletions firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "Roll20: Grimório do Tormenta20",
"description": "Escolha magias diretamente na sua ficha!",
"version": "0.0.3",
"manifest_version": 2,
"content_scripts": [
{
"matches": [
"https://app.roll20.net/editor*"
],
"js": [
"third-party/jquery-3.6.0.min.js",
"third-party/jquery-ui-1.12.1.min.js",
"jquery-patch.js",
"render.js",
"sheet.js",
"index.js"
],
"run_at": "document_end"
}
],
"web_accessible_resources": [
"data/*",
"index.css"
],
"icons": {
"16": "images/16.png",
"32": "images/32.png",
"48": "images/48.png",
"128": "images/128.png"
},
"permissions": [
"activeTab"
]
}
13 changes: 13 additions & 0 deletions prepare.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

if [[ "$1" =~ ^(chrome|firefox)$ ]]; then
echo "preparing $1"
cp "$1"/manifest.json src/manifest.json
[ -e "$1".zip ] && rm "$1".zip
cd src && zip -r ../"$1".zip * && cd ..
echo "$1 done"
else
echo "invalid option: $1"
fi
21 changes: 20 additions & 1 deletion src/jquery-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// https://stackoverflow.com/a/49023264
function add_on_create_event() {
const observers = [];
let observers = [];
$.event.special.create = {

setup: function setup() {
Expand Down Expand Up @@ -37,8 +37,27 @@ function add_on_create_event() {
}
};

/*
To improve in memory usage and to prevent memory leaks, Firefox disallows add-ons to
keep strong references to DOM objects after their parent document has been destroyed.
A dead object, is holding a strong (keep alive) reference to a DOM element that persists
even after it was destroyed in the DOM.
More info here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Dead_object
*/
function removeDeadObjectsReferences() {
observers = observers.filter(function (element) {
try {
return element[0].location != null;
}
catch (e) {
return false;
}
});
}

function getObserverData(element) {
const $el = $(element);
removeDeadObjectsReferences();
return $.grep(observers, function (item) {
return $el.is(item[0]);
})[0];
Expand Down
4 changes: 2 additions & 2 deletions src/sheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class CharacterSheet {
render_buttons() {
const sheet = this;
sheet.spells_div.on('click', 'button.repcontrol_add', function () {
sheet.render_dialogs();
sheet.render_dialogs(); // render dialogs to new spells.
});
sheet.render_dialogs();
sheet.render_dialogs(); // render dialogs to speels that already exists.
}

render_dialogs() {
Expand Down

0 comments on commit 76d9a56

Please sign in to comment.