{"id":18448386,"url":"https://github.com/darkseal/repflare","last_synced_at":"2025-04-08T01:32:13.747Z","repository":{"id":37543951,"uuid":"309115766","full_name":"Darkseal/REPflare","owner":"Darkseal","description":"A lightweight Cloudflare Worker to replace text and inject styles and scripts in any web page","archived":false,"fork":false,"pushed_at":"2020-11-02T01:27:36.000Z","size":13,"stargazers_count":25,"open_issues_count":1,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-23T03:51:14.387Z","etag":null,"topics":["cloudflare","cloudflare-api","cloudflare-worker","cloudflare-workers","injection","javascript","replacement","script","serverless"],"latest_commit_sha":null,"homepage":"https://www.ryadel.com/en/portfolio/repflare/","language":"JavaScript","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/Darkseal.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-11-01T14:38:32.000Z","updated_at":"2025-03-09T07:01:40.000Z","dependencies_parsed_at":"2022-09-10T19:41:10.861Z","dependency_job_id":null,"html_url":"https://github.com/Darkseal/REPflare","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/Darkseal%2FREPflare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Darkseal%2FREPflare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Darkseal%2FREPflare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Darkseal%2FREPflare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Darkseal","download_url":"https://codeload.github.com/Darkseal/REPflare/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247760487,"owners_count":20991500,"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":["cloudflare","cloudflare-api","cloudflare-worker","cloudflare-workers","injection","javascript","replacement","script","serverless"],"created_at":"2024-11-06T07:15:46.455Z","updated_at":"2025-04-08T01:32:13.524Z","avatar_url":"https://github.com/Darkseal.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# REPflare\nA lightweight Cloudflare Worker to replace text and inject styles and scripts in any web page.\n\n## Introduction\nREPflare is born as a \"spinoff\" of CORSflare, a lightweight reverse proxy written in JavaScript that can be used to bypass most common \nCORS (Cross-Origin Resource Sharing)restrictions: for additional info about it, read [here](https://github.com/Darkseal/CORSflare).\n\nIn a nutshell, REPflare is a Cloudflare Worker that allows to perform text replacements and script injections in any webpage,\nas long as the originating website is server through the Cloudflare CDN.\n\n### Wait a minute... what's a Cloudflare Worker?\nCloudflare Workers are serverless execution environments that allow developers to create entirely new applications or augment existing ones \nwithout configuring or maintaining infrastructure. A Cloudflare Worker can be set up to work in two ways:\n\n- **Stand-alone**, meaning that it will serve first-hand content or content fetched from third-party sources (inside or outside Cloudflare).\n[CORSflare](https://github.com/Darkseal/CORSflare) is a good example of stand-alone worker, since it can proxy every website.\n- **Route-based**, meaning that it will *intercept* a route (or a route mask) of one of our Cloudflare-served domains and perform some post-processing tasks\nbetween the web server's HTTP response and the client. REPflare is a good example of route-based worker, since is meant to perform text replacement and script injection\nonly for the domains that the person who uses it has registered on Cloudflare (and that are served through the Cloudflare CDN).\n\n## How to install\nTo setup REPflare as a Cloudflare Worker, follow these steps:\n* **Download the latest REPflare version** from the REPflare GitHub page: you'll only need the `REPflare.js` JavaScript file.\n* **Login to Cloudflare**. If you don't have an account, create one: it's free \nand the basic plan will arguably be enough for most common scenarios, as it will grant 100.000 requests per day.\n* **Navigate to the *Workers* section** using the top-level menu.\n* **Create a new worker**. If it's the first time you do that, you'll also be asked to choose a subdomain, such as `domainName.workers.dev`.\nThe subdomain name will be appended to the worker's name to form the worker's FQDN, such as `workerName.domainName.workers.dev`.\n* **Paste the REPflare.js source code within the worker code**.\n* **Setup the REPflare configuration settings** by following the instructions in the code comment sections (or see below).\n* **Add one or more ROUTES to Cloudflare** and assign them to the REPflare worker: for example, if you want to perform text replacements and script injections on all\nthe web pages of the `www.yourdomain.com` domain, you'll have to add (and assign) the `www.yourdomain.com/*` route.\n\nFor additional details about Cloudflare Workers, Workers routes and how to properly set them, take a look at the following official guides:\n* https://developers.cloudflare.com/workers/\n* https://developers.cloudflare.com/workers/platform/routes\n* https://workers.cloudflare.com/\n \n## Configuration Settings\nREPflare's configuration settings can be set via some JavaScript constants \u0026 variables placed at the beginning of the source code.\nThe best way to do that is to read the code comments. However, here's a quick breakdown of the most relevant options:\n\n* **textReplacement_useRegex**: set this  to TRUE to allow RegExp usage within the text replacement rules, FALSE otherwise.\n* **textReplacement_caseInsensitive**: set this to TRUE to perform the replacement in a case-insensitive way, FALSE otherwise.\n* **textReplacementRules**: a JSON object containing the text replacement rules (see below for details).\n* **scriptInjectionRules**: a JSON object containing the script injection rules (see below for details).\n\n\n### Text Replacement Rules\nThe `textReplacementRules` object can be used to configure the text replacement rules\nthat will be applied to the web server's HTTP response before serving the webpage back to the user.\n\nYou can use this feature for a number of tasks, such as:\n- \"fix\" non-standard internal URLs and/or local paths within the upstream's returned contents (html pages, css, js, internal links, custom fonts, and so on)\n-  alter the response content in various ways (change a logo, modify the page title, replace a word or a link, and so on).\n\nEach rule must be defined in the following way:\n\n    '\u003csource_string\u003e' : '\u003creplacement_string\u003e'\n\n**HINT**: text replacement rules are processed from top to bottom: put the most specific rules before the generic ones.\n\n\n### Script Injection Rules\nThe `scriptInjectionRules` object can be used to inject `\u003cscript\u003e`, `\u003cstyle\u003e` and/or any other HTML element (or raw content) \nto the web server's HTTP response before serving the webpage back to the user.\n\nYou can use this feature for a number of tasks, such as:\n- add additional scripts and/or styles to the webpage (including those pointing to external/third party websites).\n- add additional content to the webpage (such as a banner, a emergency alert, a cookie policy modal dialog, and so on)\n\nEach rule must be defined in the following way:\n\n    '\u003ccontent_to_inject\u003e' : \u003cposition\u003e\n\nThe rightmost `position` parameter must be a number from 0 to 3 that will determine where the content will be injected.\nThe `position` parameter can have the following values:\n* 0: at the beginning of \u003chead\u003e element ( first child of \u003chead\u003e )\n* 1: at the end of \u003cheader\u003e element  ( right before \u003c/head\u003e )\n* 2: at the beginning of \u003cbody\u003e element ( first child of \u003cbody\u003e )\n* 3: at the end of \u003cbody\u003e element ( right before \u003c/body\u003e )\n\n**HINT**: script injection rules are processed from top to bottom.\n\n\n## Useful References\n* [REPflare official project page](https://www.ryadel.com/en/portfolio/repflare/)\n* [REPflare setup guide](https://www.ryadel.com/en/repflare-free-cloudflare-worker-text-replacement-script-inject/)\n* [REPflare's GitHub page](https://github.com/Darkseal/REPflare)\n\n\n## Credits\nREPflare is strongly based upon the [CORSflare](https://github.com/Darkseal/CORSflare) project (MIT license).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkseal%2Frepflare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkseal%2Frepflare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkseal%2Frepflare/lists"}