diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000..e340799 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,3 @@ +module.exports = { + singleQuote: true, +}; diff --git a/package.json b/package.json index 0402eb0..5c71c28 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.0.1", "description": "", "scripts": { - "build": "parcel build src/manifest.json --no-content-hash --no-source-maps --dist-dir distribution --no-cache --detailed-report 0", + "build": "parcel build src/manifest.json --no-content-hash --no-source-maps --dist-dir distribution --detailed-report 0", "watch": "parcel watch src/manifest.json --dist-dir distribution --no-cache --no-hmr", "run:chromium": "web-ext run -t chromium" }, @@ -17,14 +17,21 @@ "@parcel/config-webextension": "^2.8.0", "@types/chrome": "^0.0.200", "parcel": "^2.8.0", + "prettier": "^2.7.1", "typescript": "^4.8.4" }, + "browserslist": [ + "since 2017-06" + ], "webExt": { "sourceDir": "distribution", "run": { "startUrl": [ - "https://pl181.plemiona.pl/game.php?screen=info_player" + "https://www.tribalwars.net" ] } + }, + "dependencies": { + "webext-options-sync": "^4.0.0" } } diff --git a/src/background.ts b/src/background.ts index b611819..e69de29 100644 --- a/src/background.ts +++ b/src/background.ts @@ -1 +0,0 @@ -chrome.cookies.onChanged.addListener(console.log); diff --git a/src/content.ts b/src/content.ts new file mode 100644 index 0000000..47704ab --- /dev/null +++ b/src/content.ts @@ -0,0 +1,36 @@ +const handleClick = (e: MouseEvent) => { + if (!(e.currentTarget instanceof HTMLAnchorElement)) { + return; + } + + e.preventDefault(); + + console.log(e.currentTarget.href); +}; + +const renderUI = () => { + document + .querySelectorAll('.worlds-container:first-of-type .world-select') + .forEach((el) => { + const cloned = el.cloneNode(true); + if (!(cloned instanceof HTMLAnchorElement)) { + return; + } + + cloned.addEventListener('click', handleClick); + + const span = cloned.childNodes.item(1); + if (!span) { + return; + } + span.textContent += ' (SS)'; + + el.parentNode?.insertBefore(cloned, el.nextSibling); + }); +}; + +const init = () => { + renderUI(); +}; + +init(); diff --git a/src/manifest.json b/src/manifest.json index c7c4a4c..b4d181b 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -8,17 +8,19 @@ "icons": { "128": "icon.png" }, - "permissions": [ - "storage", - "cookies" - ], - "host_permissions": [ - "https://*.plemiona.pl/*" - ], - "options_ui": { - "browser_style": true, - "page": "options.html" + "action": { + "default_title": "Sessions", + "default_popup": "popup.html" }, + "permissions": ["storage", "cookies"], + "host_permissions": ["https://*.tribalwars.net/*"], + "content_scripts": [ + { + "matches": ["https://www.tribalwars.net/*"], + "js": ["content.ts"], + "run_at": "document_end" + } + ], "background": { "service_worker": "background.ts", "type": "module" diff --git a/src/options-storage.ts b/src/options-storage.ts new file mode 100644 index 0000000..29c355c --- /dev/null +++ b/src/options-storage.ts @@ -0,0 +1,10 @@ +import OptionsSync from 'webext-options-sync'; + +export const optionsStorage = new OptionsSync({ + defaults: { + apiUrl: 'https://tribalwarshelp.com', + apiToken: '', + encryptionPassword: 'password', + }, + migrations: [OptionsSync.migrations.removeUnused], +}); diff --git a/src/options.html b/src/options.html deleted file mode 100644 index 17b2a8d..0000000 --- a/src/options.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - Sessions - - -

Test

- - diff --git a/src/popup.html b/src/popup.html new file mode 100644 index 0000000..364b36a --- /dev/null +++ b/src/popup.html @@ -0,0 +1,34 @@ + + + + + + + Sessions + + +
+

Hello

+
+
+ + + +
+
+
+ + + diff --git a/src/popup.ts b/src/popup.ts new file mode 100644 index 0000000..93a9bfd --- /dev/null +++ b/src/popup.ts @@ -0,0 +1,7 @@ +import { optionsStorage } from './options-storage'; + +const init = async () => { + await optionsStorage.syncForm('#options form'); +}; + +init(); diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..e1339e0 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,11 @@ +{ + "compilerOptions": { + "target": "es2017", + "strict": true, + "moduleResolution": "Node", + "strictNullChecks": true, + "strictFunctionTypes": true, + "skipLibCheck": true, + "noImplicitAny": true + } +} diff --git a/yarn.lock b/yarn.lock index 46bcccf..2af8bc4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -960,6 +960,11 @@ detect-libc@^1.0.3: resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" integrity sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg== +dom-form-serializer@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/dom-form-serializer/-/dom-form-serializer-2.0.0.tgz#b1550efefa08ebca15547ee1b4c791bf7b45c748" + integrity sha512-HMrrc7gJIBj6sWmnJcO9DLZj8AsdFP60+pZSu0vMJxZhEP3GPfsNE9X1GC95nXZ0SZbS8FYDb/NHW/NArSmu0Q== + dom-serializer@^1.0.1: version "1.4.1" resolved "https://registry.yarnpkg.com/dom-serializer/-/dom-serializer-1.4.1.tgz#de5d41b1aea290215dc45a6dae8adcf1d32e2d30" @@ -1185,6 +1190,11 @@ lmdb@2.5.2: "@lmdb/lmdb-linux-x64" "2.5.2" "@lmdb/lmdb-win32-x64" "2.5.2" +lz-string@^1.4.4: + version "1.4.4" + resolved "https://registry.yarnpkg.com/lz-string/-/lz-string-1.4.4.tgz#c0d8eaf36059f705796e1e344811cf4c498d3a26" + integrity sha512-0ckx7ZHRPqb0oUm8zNr+90mtf9DQB60H1wMCjBtfi62Kl3a7JbHob6gA2bC+xRvZoOL+1hzUK8jeuEIQE8svEQ== + mdn-data@2.0.14: version "2.0.14" resolved "https://registry.yarnpkg.com/mdn-data/-/mdn-data-2.0.14.tgz#7113fc4281917d63ce29b43446f701e68c25ba50" @@ -1334,6 +1344,11 @@ posthtml@^0.16.4, posthtml@^0.16.5: posthtml-parser "^0.11.0" posthtml-render "^3.0.0" +prettier@^2.7.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.7.1.tgz#e235806850d057f97bb08368a4f7d899f7760c64" + integrity sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g== + react-error-overlay@6.0.9: version "6.0.9" resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-6.0.9.tgz#3c743010c9359608c375ecd6bc76f35d93995b0a" @@ -1424,6 +1439,11 @@ terser@^5.2.0: commander "^2.20.0" source-map-support "~0.5.20" +throttle-debounce@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-5.0.0.tgz#a17a4039e82a2ed38a5e7268e4132d6960d41933" + integrity sha512-2iQTSgkkc1Zyk0MeVrt/3BvuOXYPl/R8Z0U2xxo9rjwNciaHDG3R+Lm6dh4EeUci49DanvBnuqI6jshoQQRGEg== + timsort@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/timsort/-/timsort-0.3.0.tgz#405411a8e7e6339fe64db9a234de11dc31e02bd4" @@ -1467,6 +1487,27 @@ weak-lru-cache@^1.2.2: resolved "https://registry.yarnpkg.com/weak-lru-cache/-/weak-lru-cache-1.2.2.tgz#fdbb6741f36bae9540d12f480ce8254060dccd19" integrity sha512-DEAoo25RfSYMuTGc9vPJzZcZullwIqRDSI9LOy+fkCJPi6hykCnfKaXTuPBDuXAUcqHXyOgFtHNp/kB2FjYHbw== +webext-detect-page@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/webext-detect-page/-/webext-detect-page-4.0.1.tgz#124a6802c872fa0bc12549d99b2dd53d18af2ba7" + integrity sha512-Y9Skw6/Uj0dGwOIidc1XqZ3neEbmuuT4BlkL/J4JHAo6fVznHIZq6/MWDsPGOA/jnNowiSXtHHh4S/TOxbl6bQ== + +webext-options-sync@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/webext-options-sync/-/webext-options-sync-4.0.0.tgz#d706aa6f1330c07fb061da541477aa68b8538593" + integrity sha512-00umVaF/jpd3cWyT/9OZJf1CM5Z3AtiIKT/4Fzuhwfe3pg2z84cGz/RwaIRiN60zz7A64ieEG1z9dKT8/cEICQ== + dependencies: + dom-form-serializer "^2.0.0" + lz-string "^1.4.4" + throttle-debounce "^5.0.0" + webext-detect-page "^4.0.1" + webext-polyfill-kinda "^0.10.0" + +webext-polyfill-kinda@^0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/webext-polyfill-kinda/-/webext-polyfill-kinda-0.10.0.tgz#5eb154c581edae827f2832c090811d14dd074ea2" + integrity sha512-Yz5WTwig5byFfMXgagtfaJkVU+RrnVqtL1hmvA+GIbpRaGKU1DIrFYHMUUFkeyFqxRSuhbOdLKzteXxCd6VNzA== + xxhash-wasm@^0.4.2: version "0.4.2" resolved "https://registry.yarnpkg.com/xxhash-wasm/-/xxhash-wasm-0.4.2.tgz#752398c131a4dd407b5132ba62ad372029be6f79"