{"id":21076074,"url":"https://github.com/shaack/webtools-js","last_synced_at":"2025-03-14T03:43:05.990Z","repository":{"id":57397549,"uuid":"369509523","full_name":"shaack/webtools-js","owner":"shaack","description":null,"archived":false,"fork":false,"pushed_at":"2022-09-03T12:36:24.000Z","size":27,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-08T10:51:58.253Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shaack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-21T11:13:41.000Z","updated_at":"2022-03-10T19:31:02.000Z","dependencies_parsed_at":"2022-08-31T15:51:16.940Z","dependency_job_id":null,"html_url":"https://github.com/shaack/webtools-js","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fwebtools-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fwebtools-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fwebtools-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shaack%2Fwebtools-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shaack","download_url":"https://codeload.github.com/shaack/webtools-js/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243521215,"owners_count":20304183,"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":[],"created_at":"2024-11-19T19:26:21.639Z","updated_at":"2025-03-14T03:43:05.962Z","avatar_url":"https://github.com/shaack.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webtools-js\n\nJust some `JavaScript` tools for websites to not bloat the code with\nlarger frameworks.\n\n### Functionality\n\n- Read and write **Cookies**\n- **Observe** variables to call a callback on change\n- Make **http requests**\n- **Delegate** events\n- Use a `documentReady` event handler\n- Automatically **open external links in a new tab**\n\n### Benefits\n\n- Vanilla, uncompiled JavaScript in ES 5.1 Syntax\n- No dependencies\n\n## Cookies\n\n### wt.Cookies.set(name, value, days)\nSet a Cookie. If \"days\" is not set, a session cookie is written\n\n```js\n// write a session cookie\nwt.Cookies.set(\"testcookie\", \"123\")\n```\n\n### wt.Cookies.get(name)\nRead a Cookie\n\n### wt.Cookies.remove(name)\nRemove a Cookie\n\n## Observed\n\nObserve variables\n\n```js\nvar observedVar = new wt.Observed(\n    function(newValue, oldValue) { \n        // callback on change \n    })\n```\n\nSet values with\n```js\nobservedVar(value)\n```\n\nGet values with\n```js\nvar value = observedVar()\n```\n\n## HttpRequest\n\n### wt.HttpRequest.get(url, onSuccess, onError) \n\n```js\nwt.HttpRequest.get(\"test-request.txt\", function (response) {\n    // success\n    console.log(response)\n}, function (errorMessage) {\n    // failure\n    console.error(errorMessage)\n})\n```\n\n## Utils\n\n### wt.Utils.openExternalLinksBlank()\n\nOpens all external links in a new tab, except when they have `target=\"_self\"`. \n\n## Examples\n```js\n// Cookies\n\n// write a cookie\nwt.Cookies.set(\"testcookie\", \"123\")\n// read a cookie\nconsole.log(\"Cookie\", wt.Cookies.get(\"testcookie\"))\n\n// Observed variable\n\n// observe the value of the variable `observedVar`\nvar observedVar = new wt.Observed(function (newValue, oldValue) {\n    console.log(\"newValue\", newValue)\n    console.log(\"oldValue\", oldValue)\n})\n// write the value of the variable `observedVar`\nobservedVar(\"New Value\")\n// read the value of the variable `observedVar`\nconsole.log(\"observedVar()\", observedVar())\n\n// HttpRequest\n\nwt.HttpRequest.get(\"test-request.txt\", function (response) {\n    // success\n    console.log(response)\n}, function (errorMessage) {\n    // failure\n    console.error(errorMessage)\n})\n\n// Utils\n\n// open all external links in a new tab, except when they have `target=\"_self\"`\nwt.Utils.openExternalLinksBlank()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaack%2Fwebtools-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshaack%2Fwebtools-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshaack%2Fwebtools-js/lists"}