Skip to content

Commit

Permalink
Add more aliases (#7)
Browse files Browse the repository at this point in the history
* Add more aliases

* Fix e2e tests
  • Loading branch information
fferrin authored Jun 5, 2024
1 parent 8d686b6 commit 540c48b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You can install the FreeMedium Chrome extension by following these steps:

3. Enable Developer mode by toggling the switch in the top right corner.

4. Click on the "Load unpacked" button and select the directory where you downloaded the extension files.
4. Click on the "Load unpacked" button and **select the `extension` folder**.

5. The FreeMedium extension should now be installed and visible in the list of installed extensions.

Expand All @@ -39,6 +39,8 @@ To use the FreeMedium extension:

Contributions are welcome! If you have any ideas for improving the FreeMedium extension or encounter any issues, feel free to [open an issue](https://github.com/fferrin/free-medium/issues) or submit a pull request.

It appears that Google only approves extensions that request minimal permissions. Since this extension is designed for reading Medium posts, I initially restricted its usage to *.medium.com pages. However, Google rejected the extension from the Chrome Web Store because they don't allow extension to bypass paywalls. Because of that, I released the code so you can see what the extension is doing and, because of that, I'm not restricted to add as many aliases as I want. **If you would like to add other Medium aliases**, please create an [issue](https://github.com/fferrin/free-medium/issues) with the alias(es) you want me to include.

## License

This project is licensed under the [MIT License](https://github.com/git/git-scm.com/blob/main/MIT-LICENSE.txt).
Expand Down
40 changes: 19 additions & 21 deletions extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,26 @@ function freeUrl(url) {
}

document.addEventListener("readystatechange", (event) => {
if (window.location.host.endsWith("medium.com")) {
const button = document.createElement("button");
button.id = "free-medium__button";
button.textContent = "Read for free";
button.style.position = "fixed";
button.style.bottom = "20px";
button.style.right = "20px";
button.style.padding = "20px 28px";
button.style.backgroundColor = "#007bff";
button.style.color = "#fff";
button.style.border = "none";
button.style.borderRadius = "48px";
button.style.fontSize = "18px";
button.style.cursor = "pointer";
button.style.zIndex = "9999";
button.style.boxShadow = "0 2px 5px rgba(0, 0, 0, 0.2)";
const button = document.createElement("button");
button.id = "free-medium__button";
button.textContent = "Read for free";
button.style.position = "fixed";
button.style.bottom = "20px";
button.style.right = "20px";
button.style.padding = "20px 28px";
button.style.backgroundColor = "#007bff";
button.style.color = "#fff";
button.style.border = "none";
button.style.borderRadius = "48px";
button.style.fontSize = "18px";
button.style.cursor = "pointer";
button.style.zIndex = "9999";
button.style.boxShadow = "0 2px 5px rgba(0, 0, 0, 0.2)";

button.addEventListener("click", function () {
window.location.href = freeUrl(document.URL);
});
button.addEventListener("click", function () {
window.location.href = freeUrl(document.URL);
});

document.body.appendChild(button);
}
document.body.appendChild(button);
});

3 changes: 2 additions & 1 deletion extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"content_scripts": [
{
"matches": [
"https://*.medium.com/*"
"https://*.medium.com/*",
"https://levelup.gitconnected.com/*"
],
"js": [
"content.js"
Expand Down
31 changes: 20 additions & 11 deletions tests/e2e/e2e.spec.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
// @ts-check
import { test, expect } from './fixtures';

test('Button exists in Medium page', async ({ page }) => {
const mediumUrl ='https://medium.com/hackernoon/hello-world-79436a73e443'
const expectedUrl ='https://freedium.cfd/hackernoon/hello-world-79436a73e443'

await page.goto(mediumUrl);
expect(page.locator('button#free-medium__button')).toBeDefined();
await expect(page.locator('button#free-medium__button')).toHaveText('Read for free');

await page.locator('button#free-medium__button').click()
const href = await page.evaluate(() => document.location.href);
expect(href).toEqual(expectedUrl)
});
const urls = [
'https://somesubdomain.medium.com',
'https://medium.com',
'https://levelup.gitconnected.com',
]

for (const url of urls) {
test(`Button exists in "${url}" page`, async ({ page }) => {
const mediumUrl = `${url}/some-post`
const expectedUrl = 'https://freedium.cfd/some-post'

await page.goto(mediumUrl);
expect(page.locator('button#free-medium__button')).toBeDefined();
await expect(page.locator('button#free-medium__button')).toHaveText('Read for free');

await page.locator('button#free-medium__button').click()
const href = await page.evaluate(() => document.location.href);
expect(href).toEqual(expectedUrl)
});
}

test('Button do not exist in non Medium page', async ({ page }) => {
await page.goto('https://www.microsiervos.com');
Expand Down

0 comments on commit 540c48b

Please sign in to comment.