commit 65d00ae0b93e31a6bb7479ad3ddee951a7fb08e9 Author: csasq Date: Sat Jul 5 20:42:37 2025 +0300 v1.0 diff --git a/icons/128x128.png b/icons/128x128.png new file mode 100644 index 0000000..5d325df Binary files /dev/null and b/icons/128x128.png differ diff --git a/icons/16x16.png b/icons/16x16.png new file mode 100644 index 0000000..5f27ef2 Binary files /dev/null and b/icons/16x16.png differ diff --git a/icons/48x48.png b/icons/48x48.png new file mode 100644 index 0000000..8e85e14 Binary files /dev/null and b/icons/48x48.png differ diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..b7b93b8 --- /dev/null +++ b/manifest.json @@ -0,0 +1,27 @@ +{ + "manifest_version": 3, + "name": "Т-Банк Экспорт", + "version": "1.0", + "description": "", + "icons": { + "16": "/icons/16x16.png", + "48": "/icons/48x48.png", + "128": "/icons/128x128.png" + }, + "action": { + "default_title": "Скачать выписку" + }, + "background": { + "service_worker": "/service_worker.js" + }, + "host_permissions": [ + "*://tbank.ru/*", + "*://www.tbank.ru/*" + ], + "permissions": [ + "cookies", + "activeTab", + "downloads", + "scripting" + ] +} \ No newline at end of file diff --git a/service_worker.js b/service_worker.js new file mode 100644 index 0000000..cd44cd9 --- /dev/null +++ b/service_worker.js @@ -0,0 +1,42 @@ +const formats = { + csv: 'csv', +} + +const downloadStatement = (format, sessionId, start, end) => { + const downloadUrl = new URL('https://www.tbank.ru/api/common/v1/export_operations/') + + downloadUrl.searchParams.set('format', format) + downloadUrl.searchParams.set('sessionid', sessionId) + downloadUrl.searchParams.set('start', start) + downloadUrl.searchParams.set('end', end) + + chrome.downloads.download({ + url: downloadUrl.toString(), + }) +} + +chrome.action.onClicked.addListener(async (tab) => { + chrome.cookies.get( + { + url: tab.url, + name: "psid", + }, + async (cookie) => { + const psId = cookie.value + + const now = new Date() + const year = now.getUTCFullYear() + const month = now.getUTCMonth() + + const start = Date.UTC(year, month, 1) + const end = Date.UTC(year, month + 1, 0, 23, 59, 59, 0) + + downloadStatement( + formats.csv, + psId, + start.toString(), + end.toString(), + ) + } + ) +}) \ No newline at end of file