diff --git a/store-assets/.gitignore b/store-assets/.gitignore new file mode 100644 index 0000000..02fdc6f --- /dev/null +++ b/store-assets/.gitignore @@ -0,0 +1,3 @@ +node_modules/ +# Popup captures: regenerated by tools/capture.mjs. +raw-ui/ diff --git a/store-assets/README.md b/store-assets/README.md new file mode 100644 index 0000000..dfb4ad4 --- /dev/null +++ b/store-assets/README.md @@ -0,0 +1,103 @@ +# Store screenshots + +Chrome Web Store screenshots for Search automatic rewards, in English and six +translations. All are 1280×800, 24-bit RGB PNGs with no alpha, ready to upload: + +- `chrome//screenshot-1-main.png`: the popup as it opens. +- `chrome//screenshot-2-progress.png`: a run in progress (3/5). +- `chrome//screenshot-3-settings.png`: the search settings. + +Locales: en, zh_CN, zh_TW, pt_BR, es, es_419 (a copy of es), fr, vi. In the Chrome Web +Store dashboard each language of the listing can have its own screenshots; a user +browsing in that language sees those first, then the global ones (upload `en` there). + +Each image is the real popup, captured from the built extension with Chrome itself +running in that language, in a plain browser window on a flat background, with one +headline, one line and callouts. The style follows Free Game Claimer's store images. + +## Trademark rules + +Search automatic rewards works with Microsoft Rewards, but Microsoft's marks stay out +of the store images: + +- No Microsoft or Bing logo, wordmark or domain anywhere in the image: not in the + browser frame, the captions, the callouts or any picture. +- The browser frame shows a neutral new tab: the tab is titled "New Tab" (Chrome's own + wording in each language) and the address bar is empty, with a search icon. Never + bing.com, rewards.bing.com or another Microsoft site. +- Text inside the popup UI, such as "Rewards" in a label or button, is fine. + +`tools/render.mjs` fails if the captions, tab title or address bar name Microsoft or +Bing, and `tools/capture.mjs` fails if the popup shows an image other than its own +coin logo and Free Game Claimer's icon (`ALLOWED_IMAGES`): check any new image for +Microsoft or Bing marks before adding it there. + +## Files + +- `source/screenshot-*.html`: the three images, with the English captions. +- `source/i18n/locales.json`: the locales, the Chrome UI language each is captured in + (`tag`), the new-tab title (`newTab`) and the locales copied from another one + (`copies`: es_419 from es). +- `source/i18n/.json`: the captions per page (`h` headline, `s` subline, + `c` the callouts in the page's order). +- `source/layout.js` and `source/store.css`: the browser window, popup placement, + callout lines and look. A headline or subline that would wrap shrinks in 0.5 px + steps until it fits one line (not below 36 px and 17 px); a callout label that would + leave the image or overlap the popup or another label fails the render. +- `source/fonts/`: Mona Sans (SIL Open Font License, `OFL.txt`), with its latin-ext and + vietnamese subsets. Chinese captions fall back to PingFang SC/TC (Noto Sans SC/TC or + Microsoft YaHei/JhengHei elsewhere). +- `tools/views.mjs`: the popup states (storage for each) and the elements the callouts + point at. `tools/capture.mjs` captures them, `tools/render.mjs` lays out the images + and `tools/finalize.py` saves them without alpha. + +## Regenerating + +You need Node 20.11 or later, Python 3 with Pillow (`pip install pillow`) and, once, +Playwright's Chromium. From `store-assets/`: + +```bash +npm ci +npx playwright install chromium +``` + +The translated popup needs a build with `_locales`: the i18n branch, PR #51 +(`feat/i18n`), isn't merged into `master` yet. Build it in its own worktree and point +the capture at it with `--dist` (or `STORE_DIST`): + +```bash +git fetch origin +git worktree add ../msr-i18n origin/feat/i18n # from the repository root +(cd ../msr-i18n/wxt && npm ci && npm run build) +``` + +Then, from `store-assets/`, one locale: + +```bash +node tools/capture.mjs --locale fr --dist ../../msr-i18n/wxt/dist/chrome-mv3 # -> raw-ui/chrome/fr/ +node tools/render.mjs --locale fr # -> chrome/fr/ +``` + +All of them (`--locale es` also refreshes `chrome/es_419/`): + +```bash +for l in en zh_CN zh_TW pt_BR es fr vi; do + node tools/capture.mjs --locale $l --dist ../../msr-i18n/wxt/dist/chrome-mv3 +done +node tools/render.mjs --locale all +``` + +Once PR #51 is merged, build `wxt/` (`npm ci && npm run build` there) and leave out +`--dist`: it defaults to `../wxt/dist/chrome-mv3`. Without `--locale` both tools use +`en`. + +How the language is set: on macOS Chrome ignores `--lang` and takes its UI language +from the system, so `tools/chrome-applelanguages.sh` starts it with the argument +`-AppleLanguages "()"`, which overrides it for that one run. On Linux and Windows +the capture passes `--lang=` (and `LANGUAGE` on Linux); only the macOS route has +been run so far. Either way the capture stops if `chrome.i18n.getUILanguage()` reports +another language, so a translated popup is never shown in an English browser. + +The committed images were made with Chrome for Testing 157; Playwright's bundled +Chromium can shift anti-aliasing slightly. To add a language, add it to `locales.json` +with its Chrome tag and new-tab title, write `.json`, then capture and render it. diff --git a/store-assets/chrome/en/screenshot-1-main.png b/store-assets/chrome/en/screenshot-1-main.png new file mode 100644 index 0000000..b80d7fd Binary files /dev/null and b/store-assets/chrome/en/screenshot-1-main.png differ diff --git a/store-assets/chrome/en/screenshot-2-progress.png b/store-assets/chrome/en/screenshot-2-progress.png new file mode 100644 index 0000000..a6bccc0 Binary files /dev/null and b/store-assets/chrome/en/screenshot-2-progress.png differ diff --git a/store-assets/chrome/en/screenshot-3-settings.png b/store-assets/chrome/en/screenshot-3-settings.png new file mode 100644 index 0000000..e6867fd Binary files /dev/null and b/store-assets/chrome/en/screenshot-3-settings.png differ diff --git a/store-assets/chrome/es/screenshot-1-main.png b/store-assets/chrome/es/screenshot-1-main.png new file mode 100644 index 0000000..5539a4f Binary files /dev/null and b/store-assets/chrome/es/screenshot-1-main.png differ diff --git a/store-assets/chrome/es/screenshot-2-progress.png b/store-assets/chrome/es/screenshot-2-progress.png new file mode 100644 index 0000000..7d04f30 Binary files /dev/null and b/store-assets/chrome/es/screenshot-2-progress.png differ diff --git a/store-assets/chrome/es/screenshot-3-settings.png b/store-assets/chrome/es/screenshot-3-settings.png new file mode 100644 index 0000000..a9db612 Binary files /dev/null and b/store-assets/chrome/es/screenshot-3-settings.png differ diff --git a/store-assets/chrome/es_419/screenshot-1-main.png b/store-assets/chrome/es_419/screenshot-1-main.png new file mode 100644 index 0000000..5539a4f Binary files /dev/null and b/store-assets/chrome/es_419/screenshot-1-main.png differ diff --git a/store-assets/chrome/es_419/screenshot-2-progress.png b/store-assets/chrome/es_419/screenshot-2-progress.png new file mode 100644 index 0000000..7d04f30 Binary files /dev/null and b/store-assets/chrome/es_419/screenshot-2-progress.png differ diff --git a/store-assets/chrome/es_419/screenshot-3-settings.png b/store-assets/chrome/es_419/screenshot-3-settings.png new file mode 100644 index 0000000..a9db612 Binary files /dev/null and b/store-assets/chrome/es_419/screenshot-3-settings.png differ diff --git a/store-assets/chrome/fr/screenshot-1-main.png b/store-assets/chrome/fr/screenshot-1-main.png new file mode 100644 index 0000000..2632814 Binary files /dev/null and b/store-assets/chrome/fr/screenshot-1-main.png differ diff --git a/store-assets/chrome/fr/screenshot-2-progress.png b/store-assets/chrome/fr/screenshot-2-progress.png new file mode 100644 index 0000000..31bb808 Binary files /dev/null and b/store-assets/chrome/fr/screenshot-2-progress.png differ diff --git a/store-assets/chrome/fr/screenshot-3-settings.png b/store-assets/chrome/fr/screenshot-3-settings.png new file mode 100644 index 0000000..a6c4b73 Binary files /dev/null and b/store-assets/chrome/fr/screenshot-3-settings.png differ diff --git a/store-assets/chrome/pt_BR/screenshot-1-main.png b/store-assets/chrome/pt_BR/screenshot-1-main.png new file mode 100644 index 0000000..f786324 Binary files /dev/null and b/store-assets/chrome/pt_BR/screenshot-1-main.png differ diff --git a/store-assets/chrome/pt_BR/screenshot-2-progress.png b/store-assets/chrome/pt_BR/screenshot-2-progress.png new file mode 100644 index 0000000..9bea41e Binary files /dev/null and b/store-assets/chrome/pt_BR/screenshot-2-progress.png differ diff --git a/store-assets/chrome/pt_BR/screenshot-3-settings.png b/store-assets/chrome/pt_BR/screenshot-3-settings.png new file mode 100644 index 0000000..0d22f66 Binary files /dev/null and b/store-assets/chrome/pt_BR/screenshot-3-settings.png differ diff --git a/store-assets/chrome/vi/screenshot-1-main.png b/store-assets/chrome/vi/screenshot-1-main.png new file mode 100644 index 0000000..2df2807 Binary files /dev/null and b/store-assets/chrome/vi/screenshot-1-main.png differ diff --git a/store-assets/chrome/vi/screenshot-2-progress.png b/store-assets/chrome/vi/screenshot-2-progress.png new file mode 100644 index 0000000..791ae59 Binary files /dev/null and b/store-assets/chrome/vi/screenshot-2-progress.png differ diff --git a/store-assets/chrome/vi/screenshot-3-settings.png b/store-assets/chrome/vi/screenshot-3-settings.png new file mode 100644 index 0000000..3714190 Binary files /dev/null and b/store-assets/chrome/vi/screenshot-3-settings.png differ diff --git a/store-assets/chrome/zh_CN/screenshot-1-main.png b/store-assets/chrome/zh_CN/screenshot-1-main.png new file mode 100644 index 0000000..c1aa47f Binary files /dev/null and b/store-assets/chrome/zh_CN/screenshot-1-main.png differ diff --git a/store-assets/chrome/zh_CN/screenshot-2-progress.png b/store-assets/chrome/zh_CN/screenshot-2-progress.png new file mode 100644 index 0000000..7cadec0 Binary files /dev/null and b/store-assets/chrome/zh_CN/screenshot-2-progress.png differ diff --git a/store-assets/chrome/zh_CN/screenshot-3-settings.png b/store-assets/chrome/zh_CN/screenshot-3-settings.png new file mode 100644 index 0000000..05f503b Binary files /dev/null and b/store-assets/chrome/zh_CN/screenshot-3-settings.png differ diff --git a/store-assets/chrome/zh_TW/screenshot-1-main.png b/store-assets/chrome/zh_TW/screenshot-1-main.png new file mode 100644 index 0000000..f8b4eb2 Binary files /dev/null and b/store-assets/chrome/zh_TW/screenshot-1-main.png differ diff --git a/store-assets/chrome/zh_TW/screenshot-2-progress.png b/store-assets/chrome/zh_TW/screenshot-2-progress.png new file mode 100644 index 0000000..747b260 Binary files /dev/null and b/store-assets/chrome/zh_TW/screenshot-2-progress.png differ diff --git a/store-assets/chrome/zh_TW/screenshot-3-settings.png b/store-assets/chrome/zh_TW/screenshot-3-settings.png new file mode 100644 index 0000000..dbb98ea Binary files /dev/null and b/store-assets/chrome/zh_TW/screenshot-3-settings.png differ diff --git a/store-assets/package-lock.json b/store-assets/package-lock.json new file mode 100644 index 0000000..dab6508 --- /dev/null +++ b/store-assets/package-lock.json @@ -0,0 +1,42 @@ +{ + "name": "search-automatic-rewards-store-assets", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "search-automatic-rewards-store-assets", + "devDependencies": { + "playwright": "1.64.1" + } + }, + "node_modules/playwright": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.64.1.tgz", + "integrity": "sha512-HCrVhHr5QQuwYoswEUGTb7gGp522yflbv/ST8nF4sFWGuLjQCt17Q/EubpGGSNKYn1tsTCPZxqHhHCfVURu7UA==", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "playwright-core": "1.64.1" + }, + "bin": { + "playwright": "cli.js" + }, + "engines": { + "node": ">=20" + } + }, + "node_modules/playwright-core": { + "version": "1.64.1", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.64.1.tgz", + "integrity": "sha512-BC4s8y6SEVA6Q1rSxZTto8hI1KUI3xXlHGZgvGqP4IqPdI/a6FX9H29IDNz7vKo9l21b6LfYosScPL6M3xxyDQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "playwright-core": "cli.js" + }, + "engines": { + "node": ">=20" + } + } + } +} diff --git a/store-assets/package.json b/store-assets/package.json new file mode 100644 index 0000000..2515be5 --- /dev/null +++ b/store-assets/package.json @@ -0,0 +1,13 @@ +{ + "name": "search-automatic-rewards-store-assets", + "private": true, + "description": "Builds the Chrome Web Store screenshots in store-assets/ (see README.md).", + "type": "module", + "scripts": { + "capture": "node tools/capture.mjs", + "render": "node tools/render.mjs" + }, + "devDependencies": { + "playwright": "1.64.1" + } +} diff --git a/store-assets/source/fonts/MonaSans-latin-ext.woff2 b/store-assets/source/fonts/MonaSans-latin-ext.woff2 new file mode 100644 index 0000000..85ea14b Binary files /dev/null and b/store-assets/source/fonts/MonaSans-latin-ext.woff2 differ diff --git a/store-assets/source/fonts/MonaSans-latin.woff2 b/store-assets/source/fonts/MonaSans-latin.woff2 new file mode 100644 index 0000000..88ec89e Binary files /dev/null and b/store-assets/source/fonts/MonaSans-latin.woff2 differ diff --git a/store-assets/source/fonts/MonaSans-vietnamese.woff2 b/store-assets/source/fonts/MonaSans-vietnamese.woff2 new file mode 100644 index 0000000..72d52eb Binary files /dev/null and b/store-assets/source/fonts/MonaSans-vietnamese.woff2 differ diff --git a/store-assets/source/fonts/OFL.txt b/store-assets/source/fonts/OFL.txt new file mode 100644 index 0000000..ccc02aa --- /dev/null +++ b/store-assets/source/fonts/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2022 The Mona Sans Project Authors (https://github.com/github/mona-sans), with Reserved Font Name "Mona" + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +https://openfontlicense.org + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/store-assets/source/i18n/es.json b/store-assets/source/i18n/es.json new file mode 100644 index 0000000..0cdcf0b --- /dev/null +++ b/store-assets/source/i18n/es.json @@ -0,0 +1,26 @@ +{ + "screenshot-1-main": { + "h": "Tus búsquedas diarias, hechas para ti", + "s": "Hace tus búsquedas diarias al abrir el navegador, o con un clic.", + "c": [ + "Empieza con un clic", + "Activa o desactiva cada tarea" + ] + }, + "screenshot-2-progress": { + "h": "Sigue el progreso de cada ronda", + "s": "Las búsquedas se abren de una en una y se cierran al cargar.", + "c": [ + "Progreso de la ronda", + "Detenlo cuando quieras" + ] + }, + "screenshot-3-settings": { + "h": "A tu manera", + "s": "Elige cuántas búsquedas hacer, el intervalo entre ellas y cuánto tiempo queda abierta cada pestaña.", + "c": [ + "Número de búsquedas", + "Pausa entre búsquedas" + ] + } +} diff --git a/store-assets/source/i18n/fr.json b/store-assets/source/i18n/fr.json new file mode 100644 index 0000000..73515ea --- /dev/null +++ b/store-assets/source/i18n/fr.json @@ -0,0 +1,26 @@ +{ + "screenshot-1-main": { + "h": "Vos recherches quotidiennes, faites pour vous", + "s": "Lance vos recherches quotidiennes à l'ouverture du navigateur, ou en un clic.", + "c": [ + "Lancez en un clic", + "Activez ou désactivez chaque tâche" + ] + }, + "screenshot-2-progress": { + "h": "Suivez chaque série", + "s": "Les recherches s'ouvrent une par une et se ferment une fois chargées.", + "c": [ + "Progression de la série", + "Arrêtez à tout moment" + ] + }, + "screenshot-3-settings": { + "h": "Comme vous voulez", + "s": "Choisissez le nombre de recherches, l'intervalle entre elles et la durée d'ouverture de chaque onglet.", + "c": [ + "Nombre de recherches", + "Pause entre les recherches" + ] + } +} diff --git a/store-assets/source/i18n/locales.json b/store-assets/source/i18n/locales.json new file mode 100644 index 0000000..c76bf58 --- /dev/null +++ b/store-assets/source/i18n/locales.json @@ -0,0 +1,36 @@ +{ + "_note": "Store screenshots per language. tag: the Chrome UI language the popup is captured in. newTab: Chrome's own title for a new tab in that language (the browser frame shows a neutral new tab). copies: locales whose images are copied from another one. Captions are in .json, keyed by the page in source/ (h = headline, s = subline, c = callouts in the page's order); English is in the HTML.", + "locales": { + "en": { + "tag": "en-US", + "newTab": "New Tab" + }, + "zh_CN": { + "tag": "zh-CN", + "newTab": "新标签页" + }, + "zh_TW": { + "tag": "zh-TW", + "newTab": "新分頁" + }, + "pt_BR": { + "tag": "pt-BR", + "newTab": "Nova guia" + }, + "es": { + "tag": "es", + "newTab": "Nueva pestaña" + }, + "fr": { + "tag": "fr", + "newTab": "Nouvel onglet" + }, + "vi": { + "tag": "vi", + "newTab": "Thẻ mới" + } + }, + "copies": { + "es_419": "es" + } +} diff --git a/store-assets/source/i18n/pt_BR.json b/store-assets/source/i18n/pt_BR.json new file mode 100644 index 0000000..20f5328 --- /dev/null +++ b/store-assets/source/i18n/pt_BR.json @@ -0,0 +1,26 @@ +{ + "screenshot-1-main": { + "h": "Suas pesquisas diárias, feitas para você", + "s": "Faz suas pesquisas diárias ao abrir o navegador, ou com um clique.", + "c": [ + "Comece com um clique", + "Ligue ou desligue cada tarefa" + ] + }, + "screenshot-2-progress": { + "h": "Acompanhe cada rodada", + "s": "As pesquisas abrem uma aba por vez e fecham depois de carregar.", + "c": [ + "Progresso da rodada", + "Pare quando quiser" + ] + }, + "screenshot-3-settings": { + "h": "Do seu jeito", + "s": "Escolha quantas pesquisas fazer, o intervalo entre elas e quanto tempo cada aba fica aberta.", + "c": [ + "Número de pesquisas", + "Intervalo entre pesquisas" + ] + } +} diff --git a/store-assets/source/i18n/vi.json b/store-assets/source/i18n/vi.json new file mode 100644 index 0000000..465c829 --- /dev/null +++ b/store-assets/source/i18n/vi.json @@ -0,0 +1,26 @@ +{ + "screenshot-1-main": { + "h": "Tìm kiếm hằng ngày, tự động làm giúp bạn", + "s": "Chạy tìm kiếm hằng ngày khi mở trình duyệt, hoặc chỉ với một cú nhấp.", + "c": [ + "Bắt đầu chỉ với một cú nhấp", + "Bật hoặc tắt từng nhiệm vụ" + ] + }, + "screenshot-2-progress": { + "h": "Theo dõi tiến độ từng lần chạy", + "s": "Mỗi lượt tìm mở một thẻ và tự đóng khi tải xong.", + "c": [ + "Tiến độ lần chạy", + "Dừng bất cứ lúc nào" + ] + }, + "screenshot-3-settings": { + "h": "Tùy chỉnh theo ý bạn", + "s": "Chọn số lượt tìm kiếm, khoảng cách giữa các lượt và thời gian mỗi thẻ được mở.", + "c": [ + "Số lượt tìm kiếm", + "Khoảng nghỉ giữa các lượt" + ] + } +} diff --git a/store-assets/source/i18n/zh_CN.json b/store-assets/source/i18n/zh_CN.json new file mode 100644 index 0000000..4fda264 --- /dev/null +++ b/store-assets/source/i18n/zh_CN.json @@ -0,0 +1,26 @@ +{ + "screenshot-1-main": { + "h": "每日搜索,自动帮你完成", + "s": "浏览器启动时自动运行每日搜索,也可以一键运行。", + "c": [ + "一键开始", + "单独开关每项每日任务" + ] + }, + "screenshot-2-progress": { + "h": "每轮进度,一目了然", + "s": "搜索每次打开一个标签页,加载完成后自动关闭。", + "c": [ + "本轮进度", + "随时停止" + ] + }, + "screenshot-3-settings": { + "h": "按你的方式设置", + "s": "选择搜索次数、搜索间隔,以及每个标签页保持打开的时间。", + "c": [ + "搜索次数", + "搜索间隔" + ] + } +} diff --git a/store-assets/source/i18n/zh_TW.json b/store-assets/source/i18n/zh_TW.json new file mode 100644 index 0000000..38538be --- /dev/null +++ b/store-assets/source/i18n/zh_TW.json @@ -0,0 +1,26 @@ +{ + "screenshot-1-main": { + "h": "每日搜尋,自動幫你完成", + "s": "瀏覽器啟動時自動執行每日搜尋,也可以一鍵執行。", + "c": [ + "一鍵開始", + "個別開關每項每日任務" + ] + }, + "screenshot-2-progress": { + "h": "每輪進度,一目了然", + "s": "搜尋每次開啟一個分頁,載入完成後自動關閉。", + "c": [ + "本輪進度", + "隨時停止" + ] + }, + "screenshot-3-settings": { + "h": "依你的方式設定", + "s": "選擇搜尋次數、搜尋間隔,以及每個分頁保持開啟的時間。", + "c": [ + "搜尋次數", + "搜尋間隔" + ] + } +} diff --git a/store-assets/source/icon.png b/store-assets/source/icon.png new file mode 100644 index 0000000..d73d0b1 Binary files /dev/null and b/store-assets/source/icon.png differ diff --git a/store-assets/source/layout.js b/store-assets/source/layout.js new file mode 100644 index 0000000..45ab8b2 --- /dev/null +++ b/store-assets/source/layout.js @@ -0,0 +1,184 @@ +// Lays out one store image: builds the browser window, sizes the popup capture at +// UI_SCALE, places the popup under the toolbar button, and draws callouts to the +// elements recorded in ../raw-ui/chrome//rects.js. Ported from Free Game +// Claimer's store-assets/source/layout.js. ?locale= (tools/render.mjs always +// passes it) picks the captures; for a locale other than English, render.mjs hands +// over the captions from source/i18n/.json in window.STORE_I18N, plus the tab +// title. A headline or subline that would wrap shrinks until it fits one line. +// A browser frame with no data-url shows a neutral new tab: an empty address bar +// with a search icon, so no site or brand appears in the frame (see README). +// Sets body[data-ready] to "1" when done, or to an error message (render.mjs fails on that). +(() => { + const UI_SCALE = 1.05; // popup CSS px -> image px + const CAPTURE_SCALE = 2; // captures are taken at 2x + const LABEL_GAP = 64; // popup edge to the callout labels + const LABEL_SPACING = 16; // minimum gap between two labels + const POPUP_INSET = 12; // popup right edge past the toolbar button's right edge + const ANCHOR_X = 6; // leaders end in the popup's left margin (popup CSS px), crossing no text + const VISIBLE_MARGIN = 10; // a dot stays this far above the image's bottom edge + const LABEL_MARGIN = 16; // and a label this far + const LOCALE = new URLSearchParams(location.search).get("locale") || "en"; + const UI_DIR = `../raw-ui/chrome/${LOCALE}/`; + const MIN_HEADLINE_PX = 36; // a headline that would wrap shrinks to one line, not below this + const MIN_SUBLINE_PX = 17; + + const ICONS = { + back: '', + forward: '', + reload: '', + lock: '', + globe: '', + search: '', + menu: '', + }; + const icon = (name) => ``; + const fail = (message) => { document.body.dataset.ready = `error: ${message}`; }; + + function buildBrowser(el) { + const isOpen = document.querySelector(".popup") ? " is-open" : ""; + el.insertAdjacentHTML("afterbegin", ` +
+ ${icon("globe")}${el.dataset.tab}
+
${icon("back")}${icon("forward")}${icon("reload")} + ${el.dataset.url ? `${icon("lock")}${el.dataset.url}` : icon("search")} + ${icon("menu")}
+
${'
'.repeat(9)}
`); + } + + function placePopup() { + const popup = document.querySelector(".popup"); + const toolbar = document.querySelector(".toolbar"); + if (!popup || !toolbar) return; + const button = document.querySelector(".ext-button").getBoundingClientRect(); + popup.style.left = `${button.right + POPUP_INSET - popup.offsetWidth}px`; + popup.style.top = `${toolbar.getBoundingClientRect().bottom + 3}px`; + } + + function sizeCaptures(images) { + images.forEach((img) => { + img.style.width = `${(img.naturalWidth / CAPTURE_SCALE) * UI_SCALE}px`; + }); + } + + function leaderPath(labelRight, labelY, anchorX, anchorY) { + if (Math.abs(labelY - anchorY) < 1) return `M${labelRight},${labelY} H${anchorX}`; + const bendX = labelRight + 22; + return `M${labelRight},${labelY} H${bendX} V${anchorY} H${anchorX}`; + } + + // Labels sit left of the popup, each level with its element unless that would + // overlap the label above; the leader then bends down to the element's row, and + // ends in the popup's margin rather than running across its text. + // A translation can push an element lower than in English, near or past the + // image's bottom edge: the dot then goes to the middle of the part still in the + // image, and the labels move up (with the ones above them) to stay inside it. + // English images have nothing that low, so they come out as before. + function drawCallouts() { + const popup = document.querySelector(".popup"); + const callouts = [...document.querySelectorAll(".callout")]; + if (!popup || !callouts.length) return; + const rects = (window.RECTS || {})[popup.dataset.ui]; + if (!rects) throw new Error(`no rects for ${popup.dataset.ui}`); + const box = popup.getBoundingClientRect(); + const shot = document.querySelector(".shot").getBoundingClientRect(); + const visibleBottom = shot.bottom - VISIBLE_MARGIN; + const labelBottom = shot.bottom - LABEL_MARGIN; + const svg = document.querySelector(".leaders"); + const items = callouts.map((el) => { + const r = rects[el.dataset.target]; + if (!r) throw new Error(`no rect for ${el.dataset.target}`); + const top = box.top + r.y * UI_SCALE; + const bottom = top + r.h * UI_SCALE; + return { el, x: box.left + ANCHOR_X * UI_SCALE, y: (top + Math.min(bottom, visibleBottom)) / 2, h: el.offsetHeight }; + }).sort((a, b) => a.y - b.y); + + let previousBottom = -Infinity; + for (const item of items) { + item.labelY = Math.max(item.y, previousBottom + LABEL_SPACING + item.h / 2); + previousBottom = item.labelY + item.h / 2; + } + let nextTop = labelBottom + LABEL_SPACING; + for (const item of [...items].reverse()) { + item.labelY = Math.min(item.labelY, nextTop - LABEL_SPACING - item.h / 2); + nextTop = item.labelY - item.h / 2; + } + + const labelRight = box.left - LABEL_GAP; + for (const item of items) { + item.el.style.left = `${labelRight - item.el.offsetWidth}px`; + item.el.style.top = `${item.labelY - item.h / 2}px`; + const d = leaderPath(labelRight, item.labelY, item.x, item.y); + svg.insertAdjacentHTML("beforeend", + ``); + } + } + + // The locale's captions and tab title replace the English ones in the page. + function applyCaptions() { + const i18n = window.STORE_I18N; + if (!i18n) throw new Error(`nothing for ${LOCALE}: render it with tools/render.mjs --locale ${LOCALE}`); + document.documentElement.lang = i18n.lang; + if (i18n.tab) document.querySelector(".browser").dataset.tab = i18n.tab; + if (!i18n.captions) return; // English: the page's own text + const { h, s, c } = i18n.captions; + const callouts = [...document.querySelectorAll(".callout")]; + if (callouts.length !== c.length) throw new Error(`${callouts.length} callouts in the page, ${c.length} captions`); + document.title = h; + document.querySelector(".caption h1").textContent = h; + document.querySelector(".caption p").textContent = s; + callouts.forEach((el, i) => { el.textContent = c[i]; }); + } + + // Shrinks a caption line in 0.5px steps until it fits the caption's width on one line. + function fitOneLine(el, minPx) { + const max = parseFloat(getComputedStyle(el.parentElement).maxWidth); + el.style.whiteSpace = "nowrap"; + const start = parseFloat(getComputedStyle(el).fontSize); + let size = start; + while (el.scrollWidth > max + 0.5 && size > minPx) { + size -= 0.5; + el.style.fontSize = `${size}px`; + } + if (el.scrollWidth > max + 0.5) throw new Error(`"${el.textContent}" doesn't fit one line even at ${minPx}px: shorten it`); + return size === start ? null : `${start}px -> ${size}px`; + } + + function fitCaptions() { + const shrunk = { + headline: fitOneLine(document.querySelector(".caption h1"), MIN_HEADLINE_PX), + subline: fitOneLine(document.querySelector(".caption p"), MIN_SUBLINE_PX), + }; + document.body.dataset.shrunk = JSON.stringify(shrunk); + } + + function start() { + try { + applyCaptions(); + } catch (e) { + fail(e.message); + return; + } + document.querySelectorAll(".browser").forEach(buildBrowser); + const images = [...document.querySelectorAll("img[data-ui]")]; + images.forEach((img) => { img.src = UI_DIR + img.dataset.ui; }); + const script = document.createElement("script"); + script.src = `${UI_DIR}rects.js`; + script.onerror = () => fail(`${UI_DIR}rects.js missing: run tools/capture.mjs --locale ${LOCALE} first`); + // Lay out now, so the fonts the captions need are already loading when + // fonts.ready is read. + void document.body.offsetHeight; + script.onload = () => Promise.all([...[...document.images].map((img) => img.decode()), document.fonts.ready]) + .then(() => { + if (!document.fonts.check('700 46px "Mona Sans"')) throw new Error("Mona Sans not loaded"); + fitCaptions(); + sizeCaptures(images); + placePopup(); + drawCallouts(); + document.body.dataset.ready = "1"; + }) + .catch((e) => fail(e.message)); + document.head.append(script); + } + + document.addEventListener("DOMContentLoaded", start); +})(); diff --git a/store-assets/source/screenshot-1-main.html b/store-assets/source/screenshot-1-main.html new file mode 100644 index 0000000..be8a77a --- /dev/null +++ b/store-assets/source/screenshot-1-main.html @@ -0,0 +1,22 @@ + + + + + + +Your daily searches, done for you + + +
+
+

Your daily searches, done for you

+

Runs your daily searches when the browser opens, or with one click.

+
+
+ + +
Start a run with one click
+
Turn each daily task on or off
+
+ + diff --git a/store-assets/source/screenshot-2-progress.html b/store-assets/source/screenshot-2-progress.html new file mode 100644 index 0000000..7a1cf4a --- /dev/null +++ b/store-assets/source/screenshot-2-progress.html @@ -0,0 +1,22 @@ + + + + + + +See each run's progress + + +
+
+

See each run's progress

+

Searches open one tab at a time and close once they've loaded.

+
+
+ + +
Progress of the current run
+
Stop it any time
+
+ + diff --git a/store-assets/source/screenshot-3-settings.html b/store-assets/source/screenshot-3-settings.html new file mode 100644 index 0000000..8272279 --- /dev/null +++ b/store-assets/source/screenshot-3-settings.html @@ -0,0 +1,22 @@ + + + + + + +Set it up your way + + +
+
+

Set it up your way

+

Choose how many searches to run, the gap between them and how long each tab stays open.

+
+
+ + +
Number of searches
+
Pause between searches
+
+ + diff --git a/store-assets/source/store.css b/store-assets/source/store.css new file mode 100644 index 0000000..3b03c7b --- /dev/null +++ b/store-assets/source/store.css @@ -0,0 +1,291 @@ +/* Chrome Web Store images for Search automatic rewards, in the same style as Free + Game Claimer's (store-assets/source/store.css there). Flat charcoal, Mona Sans + captions, and the real popup where Chrome opens it: under its toolbar button, in a + plain light browser window on a new tab. layout.js builds the window, sizes the + captures and draws the callouts. No gradients, glows or decoration. */ + +@font-face { + font-family: "Mona Sans"; + src: url("fonts/MonaSans-latin.woff2") format("woff2"); + font-weight: 200 900; +} + +/* The rest of Mona Sans for the localized captions: Google Fonts' latin-ext and + vietnamese subsets of the same font (v2.000; the latin file above is its latin + subset). The browser loads them only for characters in their unicode-range, so + English captions render exactly as before. License: fonts/OFL.txt. */ +@font-face { + font-family: "Mona Sans"; + src: url("fonts/MonaSans-latin-ext.woff2") format("woff2"); + font-weight: 200 900; + unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF; +} + +@font-face { + font-family: "Mona Sans"; + src: url("fonts/MonaSans-vietnamese.woff2") format("woff2"); + font-weight: 200 900; + unicode-range: U+0102-0103, U+0110-0111, U+0128-0129, U+0168-0169, U+01A0-01A1, U+01AF-01B0, U+0300-0301, U+0303-0304, U+0308-0309, U+0323, U+0329, U+1EA0-1EF9, U+20AB; +} + +:root { + --canvas: #16171a; + --ink: #16171a; + --caption: "Mona Sans", -apple-system, system-ui, sans-serif; + --os: -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; + --muted: rgba(255, 255, 255, 0.7); +} + +/* Mona Sans has no Chinese: Chinese captions fall back per character to the + matching system font (layout.js sets from the locale's config). */ +:root:lang(zh-CN) { + --caption: "Mona Sans", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif; +} + +:root:lang(zh-TW) { + --caption: "Mona Sans", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif; +} + +* { + box-sizing: border-box; +} + +html, +body { + margin: 0; + padding: 0; + overflow: hidden; + -webkit-font-smoothing: antialiased; +} + +.shot { + position: relative; + width: 1280px; + height: 800px; + overflow: hidden; + background: var(--canvas); + color: #fff; +} + +/* ---------- Caption ---------- */ + +.caption { + position: absolute; + top: 54px; + left: 72px; + max-width: 1136px; + font-family: var(--caption); +} + +.caption h1 { + margin: 0 0 12px; + font-size: 46px; + line-height: 1.1; + font-weight: 700; + letter-spacing: -0.022em; +} + +.caption p { + margin: 0; + font-size: 20px; + line-height: 1.45; + color: var(--muted); +} + +/* ---------- Browser window ---------- */ + +.browser { + position: absolute; + top: 178px; + left: 72px; + width: 1136px; + height: 900px; + overflow: hidden; + border-radius: 12px 12px 0 0; + background: #f8f9fa; + font-family: var(--os); +} + +.tabstrip { + display: flex; + align-items: flex-end; + gap: 16px; + height: 44px; + padding: 0 14px; + background: #dfe2e6; +} + +.lights { + display: flex; + gap: 8px; + align-self: center; +} + +.lights i { + width: 12px; + height: 12px; + border-radius: 50%; + background: #bfc4ca; +} + +.tab { + display: flex; + align-items: center; + gap: 9px; + width: 250px; + height: 35px; + padding: 0 14px; + border-radius: 10px 10px 0 0; + background: #fff; + color: #2b2f33; + font-size: 13.5px; +} + +.tab svg { + flex: none; + width: 16px; + height: 16px; + color: #6b7178; +} + +.toolbar { + display: flex; + align-items: center; + gap: 14px; + height: 48px; + padding: 0 14px; + background: #fff; + border-bottom: 1px solid #e3e6e9; + color: #5f666d; +} + +.toolbar svg { + flex: none; + width: 18px; + height: 18px; +} + +.url { + flex: 1; + display: flex; + align-items: center; + gap: 8px; + height: 32px; + padding: 0 14px; + border-radius: 16px; + background: #f0f2f4; + color: #2b2f33; + font-size: 14px; + white-space: nowrap; +} + +.url svg { + width: 14px; + height: 14px; +} + +.ext-button { + display: grid; + place-items: center; + width: 30px; + height: 30px; + border-radius: 7px; +} + +.ext-button.is-open { + background: #e3e6e9; +} + +.ext-button img { + width: 20px; + height: 20px; +} + +/* A quiet stand-in for the page underneath: a grid of tiles, no real site. */ +.page { + display: grid; + grid-template-columns: repeat(3, 180px); + gap: 22px 20px; + padding: 30px 36px; +} + +.page-head { + grid-column: 1 / -1; + width: 200px; + height: 14px; + margin-bottom: 4px; + border-radius: 7px; + background: #e1e4e8; +} + +.page-tile::before { + content: ""; + display: block; + height: 100px; + margin-bottom: 12px; + border-radius: 8px; + background: #e6e9ec; +} + +.page-tile::after { + content: ""; + display: block; + width: 70%; + height: 10px; + border-radius: 5px; + background: #e6e9ec; +} + +/* ---------- The popup, where Chrome opens it ---------- */ + +.popup { + position: absolute; + display: block; + border-radius: 10px; + box-shadow: + 0 0 0 1px rgba(0, 0, 0, 0.35), + 0 24px 50px -12px rgba(0, 0, 0, 0.5); +} + +/* ---------- Callouts (positioned by layout.js) ---------- */ + +.leaders { + position: absolute; + inset: 0; + width: 1280px; + height: 800px; + overflow: visible; + pointer-events: none; +} + +/* Each leader is drawn twice: a white halo keeps it visible over the dark popup. */ +.leaders .halo { + fill: none; + stroke: #fff; + stroke-width: 5; +} + +.leaders .line { + fill: none; + stroke: var(--ink); + stroke-width: 1.75; +} + +.leaders circle { + fill: #fff; + stroke: var(--ink); + stroke-width: 2.5; +} + +.callout { + position: absolute; + padding: 9px 14px; + white-space: nowrap; + border-radius: 10px; + background: var(--ink); + color: #fff; + font-family: var(--caption); + font-size: 16.5px; + font-weight: 600; + line-height: 1.3; +} diff --git a/store-assets/tools/capture.mjs b/store-assets/tools/capture.mjs new file mode 100644 index 0000000..0959225 --- /dev/null +++ b/store-assets/tools/capture.mjs @@ -0,0 +1,137 @@ +// Captures the real Chrome popup at 2x in each view of views.mjs, with Chrome running +// in a locale's UI language, plus where the elements the callouts point at are. +// node tools/capture.mjs [--locale ] [--dist ] (from store-assets/) +// --locale: a key of source/i18n/locales.json (default en; or STORE_LOCALE). +// --dist: the built extension (default ../wxt/dist/chrome-mv3; or STORE_DIST). The +// translated popup needs a build with _locales: see README. +// Writes raw-ui/chrome//popup-*.png and rects.js. The extension is loaded from a +// copy without its background and content scripts, so nothing is searched. +// Chrome takes its UI language from macOS, not --lang, so on macOS +// tools/chrome-applelanguages.sh starts it with -AppleLanguages "()"; Linux and +// Windows get --lang= (and LANGUAGE on Linux). The run fails if +// chrome.i18n.getUILanguage() reports another language, or if the popup shows an +// image that isn't in ALLOWED_IMAGES (see README, "Trademark rules"). +import { createHash } from "node:crypto"; +import { createRequire } from "node:module"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const { chromium } = createRequire(import.meta.url)("playwright"); +const TOOLS_DIR = import.meta.dirname; +const ROOT = path.join(TOOLS_DIR, ".."); +const POPUP_WIDTH = 340; +const POPUP_MAX_HEIGHT = 600; +const SCALE = 2; +// Every image the popup may show in these views: its own coin logo and Free Game +// Claimer's icon. A new one must be checked for Microsoft or Bing marks first. +const ALLOWED_IMAGES = ["/imgs/logo.png", "/imgs/free-games.png"]; +const { VIEWS, viewStorage } = await import("./views.mjs"); + +function option(name, envName, fallback) { + const i = process.argv.indexOf(`--${name}`); + if (i >= 0 && !process.argv[i + 1]) throw new Error(`--${name} needs a value`); + return i >= 0 ? process.argv[i + 1] : process.env[envName] || fallback; +} + +const LOCALE = option("locale", "STORE_LOCALE", "en"); +const DIST_DIR = path.resolve(option("dist", "STORE_DIST", path.join(ROOT, "..", "wxt", "dist", "chrome-mv3"))); +const CONFIG = JSON.parse(fs.readFileSync(path.join(ROOT, "source", "i18n", "locales.json"), "utf8")); +if (!CONFIG.locales[LOCALE]) throw new Error(`unknown locale ${LOCALE}; source/i18n/locales.json has ${Object.keys(CONFIG.locales).join(", ")}`); +const TAG = CONFIG.locales[LOCALE].tag; +const OUT_DIR = path.join(ROOT, "raw-ui", "chrome", LOCALE); +if (!fs.existsSync(path.join(DIST_DIR, "manifest.json"))) throw new Error(`no built extension in ${DIST_DIR}: build it or pass --dist`); +if (LOCALE !== "en" && !fs.existsSync(path.join(DIST_DIR, "_locales", LOCALE))) { + throw new Error(`${DIST_DIR} has no _locales/${LOCALE}: build the i18n branch and pass it with --dist (see README)`); +} + +// An unpacked extension's id: sha256 of its absolute path, hex digits mapped to a-p. +function unpackedId(dir) { + return [...createHash("sha256").update(fs.realpathSync(dir)).digest("hex").slice(0, 32)] + .map((c) => String.fromCharCode(97 + parseInt(c, 16))).join(""); +} + +function prepareExtension(workDir) { + const extDir = path.join(workDir, "ext"); + fs.cpSync(DIST_DIR, extDir, { recursive: true }); + const manifestPath = path.join(extDir, "manifest.json"); + const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8")); + delete manifest.background; + delete manifest.content_scripts; + fs.writeFileSync(manifestPath, JSON.stringify(manifest)); + return extDir; +} + +// How Chrome is started in TAG: see the header. +function launchOptions() { + if (process.platform === "darwin") { + return { + executablePath: path.join(TOOLS_DIR, "chrome-applelanguages.sh"), + env: { ...process.env, STORE_CHROME_BINARY: chromium.executablePath(), STORE_APPLE_LANGUAGE: TAG }, + args: [], + }; + } + return { channel: "chromium", env: { ...process.env, LANGUAGE: TAG.replace("-", "_") }, args: [`--lang=${TAG}`] }; +} + +const workDir = fs.mkdtempSync(path.join(os.tmpdir(), "msr-capture-")); +const extDir = prepareExtension(workDir); +const { args: localeArgs, ...options } = launchOptions(); +// No Playwright locale: the page's Intl and navigator.language come from Chrome's UI language. +const context = await chromium.launchPersistentContext(path.join(workDir, "profile"), { + ...options, + headless: true, + colorScheme: "light", + deviceScaleFactor: SCALE, + viewport: { width: POPUP_WIDTH, height: POPUP_MAX_HEIGHT }, + args: [`--disable-extensions-except=${extDir}`, `--load-extension=${extDir}`, "--hide-scrollbars", ...localeArgs], +}); +const errors = []; +const rects = {}; +try { + fs.mkdirSync(OUT_DIR, { recursive: true }); + const page = await context.newPage(); + for (const other of context.pages()) if (other !== page) await other.close(); + page.on("pageerror", (e) => errors.push(String(e))); + const popupUrl = `chrome-extension://${unpackedId(extDir)}/popup.html`; + await page.goto(popupUrl); + const uiLanguage = await page.evaluate(() => chrome.i18n.getUILanguage()); + if (uiLanguage.toLowerCase() !== TAG.toLowerCase()) throw new Error(`Chrome runs in ${uiLanguage}, not ${TAG}: its UI language didn't take`); + await page.waitForTimeout(1500); // the first load writes its defaults to storage + for (const [name, view] of Object.entries(VIEWS)) { + await page.evaluate(async (storage) => { + for (const area of ["sync", "local"]) { + await chrome.storage[area].clear(); + await chrome.storage[area].set(storage[area]); + } + }, viewStorage(view)); + await page.setViewportSize({ width: POPUP_WIDTH, height: POPUP_MAX_HEIGHT }); + await page.goto(popupUrl); + await page.waitForLoadState("networkidle"); + await page.waitForFunction(() => [...document.images].every((img) => img.complete)); + await page.waitForTimeout(500); + const images = await page.evaluate(() => [...document.images].filter((i) => i.getBoundingClientRect().width).map((i) => i.getAttribute("src"))); + const unknown = images.filter((src) => !ALLOWED_IMAGES.includes(src)); + if (unknown.length) throw new Error(`${name} shows ${unknown.join(", ")}: check it has no Microsoft or Bing mark, then add it to ALLOWED_IMAGES`); + // Chrome sizes a popup to its content, up to 600 px. + const height = await page.evaluate(() => Math.ceil(document.body.getBoundingClientRect().height)); + await page.setViewportSize({ width: POPUP_WIDTH, height: Math.min(height, POPUP_MAX_HEIGHT) }); + // Wait for a frame at the new size: a capture right after a resize can come + // back as a tiled copy of the old surface. + await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(r, 200))))); + rects[`${name}.png`] = await page.evaluate((targets) => Object.fromEntries(Object.entries(targets).map(([key, selector]) => { + const element = document.querySelector(selector); + if (!element) return [key, null]; + const { x, y, width, height } = element.getBoundingClientRect(); + return [key, { x, y, w: width, h: height }]; + })), view.targets); + await page.screenshot({ path: path.join(OUT_DIR, `${name}.png`) }); + } + fs.writeFileSync(path.join(OUT_DIR, "rects.js"), `window.RECTS = ${JSON.stringify(rects, null, 1)};\n`); + const missing = Object.entries(rects).flatMap(([file, r]) => Object.entries(r).filter(([, v]) => !v).map(([k]) => `${file}:${k}`)); + console.log(JSON.stringify({ locale: LOCALE, uiLanguage, files: fs.readdirSync(OUT_DIR), missing, errors })); + if (missing.length) process.exitCode = 1; +} finally { + await context.close(); + fs.rmSync(workDir, { recursive: true, force: true }); +} diff --git a/store-assets/tools/chrome-applelanguages.sh b/store-assets/tools/chrome-applelanguages.sh new file mode 100755 index 0000000..2aa1e0b --- /dev/null +++ b/store-assets/tools/chrome-applelanguages.sh @@ -0,0 +1,15 @@ +#!/bin/bash +# Starts Chrome with the macOS argument -AppleLanguages "()". On macOS that is +# how Chrome gets a UI language for one run (it ignores --lang there): its menus, +# chrome.i18n.getUILanguage() and the extension's catalogue then follow the tag. +# capture.mjs --locale runs this as Playwright's browser executable, because +# Playwright refuses arguments that aren't --switches. +# STORE_CHROME_BINARY the Chrome to start (capture.mjs passes Playwright's Chromium) +# STORE_APPLE_LANGUAGE the language tag, e.g. pt-BR +# Chrome also reads "()" as a page to open, and headless Chrome allows only one +# start page, so Playwright's trailing about:blank is dropped. +args=("$@") +if [ "${#args[@]}" -gt 0 ] && [ "${args[${#args[@]}-1]}" = "about:blank" ]; then + unset 'args[${#args[@]}-1]' +fi +exec "$STORE_CHROME_BINARY" "${args[@]}" -AppleLanguages "(${STORE_APPLE_LANGUAGE:?})" diff --git a/store-assets/tools/finalize.py b/store-assets/tools/finalize.py new file mode 100644 index 0000000..062c902 --- /dev/null +++ b/store-assets/tools/finalize.py @@ -0,0 +1,23 @@ +"""Saves each rendered PNG as 24-bit RGB with no alpha, the Chrome Web Store's format. + +Usage: python3 finalize.py +""" +import sys +from pathlib import Path + +from PIL import Image + +EXPECTED_SIZES = {(1280, 800)} + + +def main(source: Path, target: Path) -> None: + for png in sorted(source.glob("*.png")): + with Image.open(png) as image: + if image.size not in EXPECTED_SIZES: + raise SystemExit(f"{png.name}: {image.size} is not a store size") + image.convert("RGB").save(target / png.name, optimize=True) + print(f"saved {target / png.name}") + + +if __name__ == "__main__": + main(Path(sys.argv[1]), Path(sys.argv[2])) diff --git a/store-assets/tools/render.mjs b/store-assets/tools/render.mjs new file mode 100644 index 0000000..f15b9c0 --- /dev/null +++ b/store-assets/tools/render.mjs @@ -0,0 +1,94 @@ +// Renders the store screenshots (source/screenshot-*.html) for a locale at 1280x800, +// from the captures in raw-ui/chrome// (tools/capture.mjs), as 24-bit RGB PNGs +// with no alpha (finalize.py) in chrome//. +// node tools/render.mjs [--locale |all] (from store-assets/; or STORE_LOCALE) +// Default en. Captions for other locales come from source/i18n/.json, the tab +// title from locales.json; locales under "copies" there (es_419) are copied from +// theirs (es) after it renders. A render fails if a callout label leaves the image or +// overlaps the popup or another label, or if the frame or captions name Microsoft or +// Bing (see README, "Trademark rules"). +import { execFileSync } from "node:child_process"; +import { createRequire } from "node:module"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const { chromium } = createRequire(import.meta.url)("playwright"); +const ROOT = path.join(import.meta.dirname, ".."); +const SOURCE_DIR = path.join(ROOT, "source"); +const I18N_DIR = path.join(SOURCE_DIR, "i18n"); +const CONFIG = JSON.parse(fs.readFileSync(path.join(I18N_DIR, "locales.json"), "utf8")); +const PAGES = fs.readdirSync(SOURCE_DIR).filter((file) => /^screenshot-.*\.html$/.test(file)).sort(); +const FORBIDDEN = /microsoft|bing|msn\.com|live\.com/i; + +const i = process.argv.indexOf("--locale"); +if (i >= 0 && !process.argv[i + 1]) throw new Error("--locale needs a name or all"); +const requested = (i >= 0 ? process.argv[i + 1] : process.env.STORE_LOCALE) || "en"; +const names = requested === "all" ? Object.keys(CONFIG.locales) : [requested]; +for (const name of names) { + if (!CONFIG.locales[name]) throw new Error(`unknown locale ${name}; source/i18n/locales.json has ${Object.keys(CONFIG.locales).join(", ")}`); +} + +// In the page: what breaks the rules for callouts and the trademark rules. +function problems(forbidden) { + const box = (el) => el.getBoundingClientRect(); + const shot = box(document.querySelector(".shot")); + const popup = box(document.querySelector(".popup")); + const overlap = (a, b) => a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top; + const labels = [...document.querySelectorAll(".callout")].map((el) => ({ text: el.textContent, r: box(el) })); + const found = []; + labels.forEach((l, n) => { + if (l.r.left < shot.left || l.r.right > shot.right || l.r.top < shot.top || l.r.bottom > shot.bottom) found.push(`"${l.text}" leaves the image`); + if (overlap(l.r, popup)) found.push(`"${l.text}" overlaps the popup`); + for (const m of labels.slice(n + 1)) if (overlap(l.r, m.r)) found.push(`"${l.text}" overlaps "${m.text}"`); + }); + const text = `${document.title}\n${document.querySelector(".shot").innerText}`; + if (new RegExp(forbidden, "i").test(text)) found.push("the frame or captions name Microsoft or Bing"); + return found; +} + +async function renderPage(browser, file, name, tmpDir) { + const locale = CONFIG.locales[name]; + const key = file.replace(/\.html$/, ""); + let captions = null; + if (name !== "en") { + captions = JSON.parse(fs.readFileSync(path.join(I18N_DIR, `${name}.json`), "utf8"))[key]; + if (!captions) throw new Error(`source/i18n/${name}.json has no captions for ${key}`); + } + const page = await browser.newPage({ viewport: { width: 1400, height: 800 }, deviceScaleFactor: 1 }); + await page.addInitScript((value) => { window.STORE_I18N = value; }, { lang: locale.tag, tab: locale.newTab, captions }); + await page.goto(`file://${path.join(SOURCE_DIR, file)}?locale=${name}`); + await page.waitForFunction(() => document.body.dataset.ready, null, { timeout: 30_000 }); + const ready = await page.evaluate(() => document.body.dataset.ready); + if (ready !== "1") throw new Error(`${file} (${name}): ${ready}`); + const found = await page.evaluate(problems, FORBIDDEN.source); + if (found.length) throw new Error(`${file} (${name}): ${found.join("; ")}`); + const shrunk = Object.entries(JSON.parse(await page.evaluate(() => document.body.dataset.shrunk ?? "{}"))) + .filter(([, v]) => v).map(([k, v]) => `${k} ${v}`).join(", "); + const root = page.locator(".shot"); + const out = path.join(tmpDir, `${key}.png`); + await root.screenshot({ path: out }); + await page.close(); + console.log(`${name} ${key}${shrunk ? `: shrunk ${shrunk}` : ""}`); +} + +const browser = await chromium.launch(); +try { + for (const name of names) { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), `msr-render-${name}-`)); + for (const file of PAGES) await renderPage(browser, file, name, tmpDir); + const outDir = path.join(ROOT, "chrome", name); + fs.rmSync(outDir, { recursive: true, force: true }); + fs.mkdirSync(outDir, { recursive: true }); + execFileSync("python3", ["-I", path.join(import.meta.dirname, "finalize.py"), tmpDir, outDir], { stdio: "inherit" }); + fs.rmSync(tmpDir, { recursive: true, force: true }); + for (const [copy, from] of Object.entries(CONFIG.copies ?? {})) { + if (from !== name) continue; + fs.rmSync(path.join(ROOT, "chrome", copy), { recursive: true, force: true }); + fs.cpSync(outDir, path.join(ROOT, "chrome", copy), { recursive: true }); + console.log(`copied chrome/${name}/ to chrome/${copy}/`); + } + } +} finally { + await browser.close(); +} diff --git a/store-assets/tools/views.mjs b/store-assets/tools/views.mjs new file mode 100644 index 0000000..6f1cfc3 --- /dev/null +++ b/store-assets/tools/views.mjs @@ -0,0 +1,28 @@ +// The popup states the store images show: storage for each (on top of BASE) and the +// elements the callouts point at. The review and sponsor prompts are answered, so no +// card takes the promo tiles' place. +const BASE_SYNC = { + active: true, autoDaily: true, claimPoints: false, accountLevel: "member", timeout: 60, searches: 5, + closeTime: 5, openFirstResult: false, isSearching: false, currentSearch: 0, +}; +const BASE_LOCAL = { completedRuns: 12, reviewPrompt: "rated", reviewPromptAnsweredAt: 1, sponsorPrompt: "dismissed" }; + +export const VIEWS = { + "popup-main": { + sync: {}, + targets: { button: "#button", tasks: 'section[aria-labelledby="tasks-title"] .row:nth-of-type(2)' }, + }, + "popup-progress": { + sync: { isSearching: true, currentSearch: 3, searches: 5 }, + targets: { progress: ".progress-card", stop: "#button" }, + }, + "popup-settings": { + sync: { accountLevel: "silver", searches: 10, timeout: 90, closeTime: 8 }, + targets: { searches: "#searches", timeout: "#timeout" }, + }, +}; + +// storage.sync and storage.local for a view. +export function viewStorage(view) { + return { sync: { ...BASE_SYNC, ...view.sync }, local: { ...BASE_LOCAL, ...(view.local ?? {}) } }; +}