{"id":30680648,"url":"https://github.com/knowledgecode/blokr","last_synced_at":"2025-09-01T16:51:10.084Z","repository":{"id":310962813,"uuid":"1041951008","full_name":"knowledgecode/blokr","owner":"knowledgecode","description":"Lightweight library to block user interactions in browsers","archived":false,"fork":false,"pushed_at":"2025-08-21T09:09:59.000Z","size":51,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-21T10:15:56.252Z","etag":null,"topics":["blocking","browser","disable","event","interaction","lock","ui"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/knowledgecode.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,"zenodo":null}},"created_at":"2025-08-21T08:57:42.000Z","updated_at":"2025-08-21T09:10:03.000Z","dependencies_parsed_at":"2025-08-21T10:16:02.663Z","dependency_job_id":"9cb9daa7-d155-4e72-8540-ffbd13b9e90b","html_url":"https://github.com/knowledgecode/blokr","commit_stats":null,"previous_names":["knowledgecode/blokr"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/knowledgecode/blokr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fblokr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fblokr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fblokr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fblokr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knowledgecode","download_url":"https://codeload.github.com/knowledgecode/blokr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fblokr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273158944,"owners_count":25055859,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["blocking","browser","disable","event","interaction","lock","ui"],"created_at":"2025-09-01T16:51:08.999Z","updated_at":"2025-09-01T16:51:10.048Z","avatar_url":"https://github.com/knowledgecode.png","language":"TypeScript","readme":"# Blokr\n\n[![CI](https://github.com/knowledgecode/blokr/actions/workflows/ci.yml/badge.svg)](https://github.com/knowledgecode/blokr/actions/workflows/ci.yml)\n[![npm](https://img.shields.io/npm/v/blokr)](https://www.npmjs.com/package/blokr)\n\nLightweight library to block user interactions in browsers.\n\n## Features\n\n- **No overlay elements**: Blocks interactions without adding elements to the DOM\n- **Event blocking**: Prevents mouse, keyboard, and touch interactions\n- **Auto-timeout**: Configurable timeout to prevent permanent blocking (default: 10 seconds)\n- **Lightweight**: Minimal footprint with no dependencies\n- **TypeScript**: Full type support included\n- **Singleton**: Simple, predictable API\n\n## Use Cases\n\n- **POST processing**: Block interactions during data submission\n- **Form submission**: Prevent double-submission\n- **Animations**: Disable interaction during transitions\n- **Game pausing**: Temporarily disable game controls\n\n## Installation\n\n```bash\nnpm install blokr\n```\n\n## Usage\n\n### ES Modules\n\n```typescript\nimport blokr from 'blokr';\n\n// Block user interactions\nblokr.lock();\n\n// Check if blocked\nif (blokr.isLocked()) {\n  console.log('User interactions are blocked');\n}\n\n// Unblock after some work\nsetTimeout(() =\u003e {\n  blokr.unlock();\n}, 2000);\n```\n\n### CDN\n\n```html\n\u003cscript src=\"https://unpkg.com/blokr/dist/blokr.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n  // Block interactions\n  window.Blokr.lock();\n\n  // Auto-unlock after 3 seconds\n  setTimeout(() =\u003e {\n    window.Blokr.unlock();\n  }, 3000);\n\u003c/script\u003e\n```\n\n## API\n\n### `blokr.lock()`\n\nBlocks user interactions. Multiple calls are counted internally, requiring the same number of `unlock()` calls to fully unblock.\n\n```typescript\nblokr.lock();    // Call count: 1\nblokr.lock();    // Call count: 2\nblokr.unlock();  // Call count: 1 (still blocked)\nblokr.unlock();  // Call count: 0 (unblocked)\n```\n\n### `blokr.unlock(abort?: boolean)`\n\nUnblocks user interactions. By default, decrements the internal counter. When `abort` is `true`, immediately resets the counter to zero and releases all locks.\n\n**Parameters:**\n\n- `abort` (optional): When `true`, immediately unlocks all locks. Default: `false`\n\n```typescript\n// Normal unlock behavior (decrements counter)\nblokr.lock();    // Lock count: 1\nblokr.lock();    // Lock count: 2\n\nblokr.unlock();  // Lock count: 1 (still locked)\nblokr.unlock();  // Lock count: 0 (unlocked)\n\n// Emergency unlock with abort\nblokr.lock();        // Lock count: 1\nblokr.lock();        // Lock count: 2\nblokr.unlock(true);  // Lock count: 0 (immediately unlocked)\n```\n\n### `blokr.isLocked(): boolean`\n\nReturns `true` if user interactions are currently blocked.\n\n```typescript\nblokr.isLocked(); // false\nblokr.lock();\nblokr.isLocked(); // true\n```\n\n### `blokr.setTimeout(timeout: number): boolean`\n\nSets the auto-unlock timeout in milliseconds (default: 10000). Cannot be changed while locked. Returns `true` if successfully set, `false` if currently locked.\n\n```typescript\n// Set 5-second timeout (only works when unlocked)\nblokr.setTimeout(5000);\n\n// Disable auto-timeout\nblokr.setTimeout(0);\n\n// Cannot change timeout while locked\nblokr.lock();\nblokr.setTimeout(1000); // returns false\n```\n\n## Example: POST Processing\n\n```typescript\nimport blokr from 'blokr';\n\nasync function saveUserProfile(formData) {\n  // Block all interactions during save\n  blokr.lock();\n\n  try {\n    const response = await fetch('/api/profile', {\n      method: 'POST',\n      body: formData\n    });\n\n    if (response.ok) {\n      showSuccessMessage();\n    }\n  } finally {\n    blokr.unlock();\n  }\n}\n```\n\n## Example: Animation Blocking\n\n```typescript\nimport blokr from 'blokr';\n\nfunction slidePanel() {\n  // Block interactions during animation\n  blokr.lock();\n\n  // Start CSS animation\n  panel.classList.add('sliding');\n\n  // Re-enable interactions when animation completes\n  setTimeout(() =\u003e {\n    blokr.unlock();\n  }, 500);\n}\n```\n\n## Limitations\n\n- Only blocks genuine user interactions. Programmatically triggered events (e.g., `element.click()`) are not blocked.\n- May not work when used with event delegation libraries. Loading Blokr before other libraries may resolve this issue.\n\n## License\n\nMIT\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fblokr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknowledgecode%2Fblokr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fblokr/lists"}