{"id":25759170,"url":"https://github.com/syusui-s/gmpromisify","last_synced_at":"2025-05-13T02:14:23.479Z","repository":{"id":144911288,"uuid":"522170947","full_name":"syusui-s/gmpromisify","owner":"syusui-s","description":"Promise wrapper for Greasemonkey asyncronous functions","archived":false,"fork":false,"pushed_at":"2025-02-26T16:52:05.000Z","size":537,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-13T02:14:17.317Z","etag":null,"topics":["greasemonkey","promise","promisified","userscript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/syusui-s.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-07T09:38:07.000Z","updated_at":"2025-03-25T20:11:39.000Z","dependencies_parsed_at":null,"dependency_job_id":"33e75ed3-b4d4-45d4-8011-e24ed594ae42","html_url":"https://github.com/syusui-s/gmpromisify","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syusui-s%2Fgmpromisify","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syusui-s%2Fgmpromisify/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syusui-s%2Fgmpromisify/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/syusui-s%2Fgmpromisify/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/syusui-s","download_url":"https://codeload.github.com/syusui-s/gmpromisify/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856666,"owners_count":21974582,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["greasemonkey","promise","promisified","userscript"],"created_at":"2025-02-26T17:20:44.547Z","updated_at":"2025-05-13T02:14:23.458Z","avatar_url":"https://github.com/syusui-s.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gmpromisify : Promisified GM functions\n\ngmPromisify is a library which provides [promisified](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) versions of Greasemonkey functions.\n\nThese functions are supported:\n\n- `gmFetch` for `GM.xmlHttpRequst`\n- `gmDownload` for `GM_download`\n\n## Examples\n\n### Use in `@require`\n\n```javascript\n// ==UserScript==\n// @name     gmPromisify Example\n// @include  http*\n// @grant    GM.xmlHttpRequest\n// @require  https://cdn.jsdelivr.net/npm/@syusui-s/gmpromisify/dist/index.iife.js\n// ==/UserScript==\n\n(async () =\u003e {\n  const { gmFetch } = gmPromisify;\n\n  const res = await gmFetch('https://example.com', {\n    method: 'GET',\n    headers: {\n      'X-Custom-Header': 'Custom Value',\n    },\n  });\n  const body = await res.text();\n  console.log(body);\n})();\n```\n\n### Use as npm package\n\nIt's needed to use some bundler to import this library into your UserScript.\n\n```sh\n$ npm install @syusui-s/gmpromisify\n```\n\n```javascript\nimport { gmFetch } from '@syusui-s/gmpromisify';\n\n(async () =\u003e {\n  const res = await gmFetch('https://example.com', {\n    method: 'GET',\n    headers: {\n      'X-Custom-Header': 'Custom Value',\n    },\n  });\n  const body = await res.text();\n  console.log(body);\n})();\n```\n\n## API\n\n### gmFetch\n\n`gmFetch(resource: RequestInfo, init: RequestInit): Promise\u003cResponse\u003e`\n\n`gmFetch` is a wrapper of `GM.xmlHttpRequest` and has almost the same interface as [fetch()](https://developer.mozilla.org/en-US/docs/Web/API/fetch).\n\n#### Arguments compatibility\n\n- [`init`](https://developer.mozilla.org/en-US/docs/Web/API/RequestInit)\n  - `method`\n    - Supported\n  - `body`\n    - Supported\n  - `headers`\n    - Supported\n  - `credentials`\n    - Supported\n    - The default value is `\"same-origin\"`.\n    - Greasemonkey limitation: `gmFetch` will include `Cookie` when the request is same-origin and `credentials` is `\"omit\"` because of [this](https://github.com/greasemonkey/greasemonkey/blob/master/src/bg/on-user-script-xhr.js#L130). Including cookies for CORS is introduced by [this PR](https://github.com/greasemonkey/greasemonkey/pull/2835).\n  - `integrity`\n    - Supported [(SHA-256, SHA-384 and SHA-512)](https://w3c.github.io/webappsec-csp/#grammardef-hash-algorithm)\n  - `signal`\n    - Supported **ONLY IN [Tampermonkey](https://www.tampermonkey.net/documentation.php?locale=en#api:GM_download) and [Violentmonkey](https://violentmonkey.github.io/api/gm/#gm_xmlhttprequest)**.\n  - `mode`\n    - **IGNORED**\n  - `cache`\n    - **IGNORED**\n  - `redirect`\n    - **MUST BE `\"follow\"` or `undefined`**.\n    - `TypeError` will be thrown if the other value is specified.\n    - TBD: Tampermonkey [supports it](https://www.tampermonkey.net/documentation.php?locale=en#api:GM_xmlhttpRequest).\n  - `keepalive`\n    - **IGNORED**\n  - `referrer`\n    - **IGNORED**\n  - `referrerPolicy`\n    - **IGNORED**\n  - `priority`\n    - **IGNORED**\n\n#### Return value compatibility\n\nA Promise of [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response).\nThe promise will be rejected if the error occurred.\n\n- `Response.body`\n  - Supported\n- `Response.headers`\n  - Supported\n- `Response.ok`\n  - Supported\n- `Response.statusText`\n  - Supported\n- `Response.url`\n  - Always `\"\"`\n- `Response.redirected`\n  - Always `false` even if redirected.\n- `Response.type`\n  - Always `\"default\"`\n\n### gmDownload\n\n`gmDownload(url: string, filename: string): Promise\u003cvoid\u003e`\n`gmDownload(detail: DownloadRequestWithSignal): Promise\u003cvoid\u003e`\n\n`gmDownload` is a thin wrapper of `GM_download`.\n\n**NOTE**: This is supported only by [Tampermonkey](https://www.tampermonkey.net/documentation.php?locale=en#api:GM_download) and [Violentmonkey](https://violentmonkey.github.io/api/gm/#gm_download), and not supported by Greasemonkey. `TypeError` will be thrown if the function is called in Greasemonkey environment.\n\n#### Arguments compatibility\n\nThe API is the same as [GM_download](https://www.tampermonkey.net/documentation.php?locale=en#api:GM_download).\n\n- `detail`\n  - The event handlers `onload`, `onerror` and `ontimeout` cannot be passed.\n\nAdditional parameters:\n\n- `signal`\n  - `AbortController` is supported.\n\n#### Return value compatibility\n\nA Promise of `void`. The promise will be rejected if the `onerror` callback or `ontimeout` callback is called.\n\n## LICENSE\n\nCopyright 2022-2025 Shusui Moyatani\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\nhttp://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyusui-s%2Fgmpromisify","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsyusui-s%2Fgmpromisify","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsyusui-s%2Fgmpromisify/lists"}