From 64ad026e050266ffad7dab46c4d8a84f99486e14 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Sun, 13 Feb 2022 17:17:03 -0300 Subject: [PATCH 1/8] add handle dead objects to the create observer --- src/jquery-patch.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/jquery-patch.js b/src/jquery-patch.js index a8cb0a5..00e65c4 100644 --- a/src/jquery-patch.js +++ b/src/jquery-patch.js @@ -2,7 +2,7 @@ // https://stackoverflow.com/a/49023264 function add_on_create_event() { - const observers = []; + let observers = []; $.event.special.create = { setup: function setup() { @@ -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]; From 3441be2dd9bfe824cb3ef552f3d673ab8f617da1 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Sun, 13 Feb 2022 17:17:21 -0300 Subject: [PATCH 2/8] update gitignore --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.gitignore b/.gitignore index 54e9e18..352d204 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,9 @@ *.zip +*.xpi +*.crx +*.pem +src/manifest.json +# editors *.swp +*.sublime-project +*.sublime-workspace \ No newline at end of file From d4396002e3ee10890087af16ae5669df63db4ea0 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Sun, 13 Feb 2022 17:17:44 -0300 Subject: [PATCH 3/8] add comments to sheet.js --- src/sheet.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sheet.js b/src/sheet.js index 8ddc7e6..75b22da 100644 --- a/src/sheet.js +++ b/src/sheet.js @@ -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() { From 7ac496701c9d8a5a3f442eb72d39806b3e0c8801 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Sun, 13 Feb 2022 17:18:04 -0300 Subject: [PATCH 4/8] add firefox and chrome manifests --- chrome/manifest.json | 42 ++++++++++++++++++++++++++++++++++++++++++ firefox/manifest.json | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 chrome/manifest.json create mode 100644 firefox/manifest.json diff --git a/chrome/manifest.json b/chrome/manifest.json new file mode 100644 index 0000000..e73029f --- /dev/null +++ b/chrome/manifest.json @@ -0,0 +1,42 @@ +{ + "name": "Roll20: Grimório do Tormenta20", + "description": "Escolha magias diretamente na sua ficha!", + "version": "0.0.2", + "manifest_version": 3, + "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": [ + { + "resources": [ + "data/*", + "index.css" + ], + "matches": [ + "" + ] + } + ], + "icons": { + "16": "images/16.png", + "32": "images/32.png", + "48": "images/48.png", + "128": "images/128.png" + }, + "permissions": [ + "activeTab" + ] +} diff --git a/firefox/manifest.json b/firefox/manifest.json new file mode 100644 index 0000000..e3336db --- /dev/null +++ b/firefox/manifest.json @@ -0,0 +1,35 @@ +{ + "name": "Roll20: Grimório do Tormenta20", + "description": "Escolha magias diretamente na sua ficha!", + "version": "0.0.2", + "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" + ] +} From ec3fe272c3e0286c1a3cd7248ed8ced90651d889 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Sun, 13 Feb 2022 17:18:31 -0300 Subject: [PATCH 5/8] remove the single manuifest --- src/manifest.json | 42 ------------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 src/manifest.json diff --git a/src/manifest.json b/src/manifest.json deleted file mode 100644 index e73029f..0000000 --- a/src/manifest.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "name": "Roll20: Grimório do Tormenta20", - "description": "Escolha magias diretamente na sua ficha!", - "version": "0.0.2", - "manifest_version": 3, - "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": [ - { - "resources": [ - "data/*", - "index.css" - ], - "matches": [ - "" - ] - } - ], - "icons": { - "16": "images/16.png", - "32": "images/32.png", - "48": "images/48.png", - "128": "images/128.png" - }, - "permissions": [ - "activeTab" - ] -} From 8e7997832751e59307766a089e2d868842e88e20 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Sun, 13 Feb 2022 17:23:06 -0300 Subject: [PATCH 6/8] update version --- chrome/manifest.json | 2 +- firefox/manifest.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/manifest.json b/chrome/manifest.json index e73029f..ad12f83 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -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": [ { diff --git a/firefox/manifest.json b/firefox/manifest.json index e3336db..079d0d5 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -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": 2, "content_scripts": [ { From f28bb13e61ce329db87810d80211e31c2714d539 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Sun, 13 Feb 2022 17:48:26 -0300 Subject: [PATCH 7/8] add script to handle multiple manifests --- prepare.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100755 prepare.sh diff --git a/prepare.sh b/prepare.sh new file mode 100755 index 0000000..d8e353e --- /dev/null +++ b/prepare.sh @@ -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 \ No newline at end of file From 770ddc17eeb437e68545c393906272dbd4658c93 Mon Sep 17 00:00:00 2001 From: Anderson Lima Date: Mon, 14 Feb 2022 19:59:12 -0300 Subject: [PATCH 8/8] update readme --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 24f859c..c831a8d 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file