Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions extension/content.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
function freeUrl(url) {
const urlObj = new URL(url)
const urlObj = new URL(url);

urlObj.host = "freedium-mirror.cfd";

return urlObj.href;
}

document.addEventListener("readystatechange", (event) => {
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)";
if (typeof document !== "undefined") {
document.addEventListener("readystatechange", (event) => {
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);
});
}

if (typeof module !== "undefined" && module.exports) {
module.exports = { freeUrl };
}
21 changes: 7 additions & 14 deletions tests/unit/freeUrl.test.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
function freeUrl(url) {
const urlObj = new URL(url)

urlObj.host = "freedium-mirror.cfd";

return urlObj.href;
}

const { freeUrl } = require("../../extension/content.js");

describe("freeUrl", () => {
it("converts the URLs correctly", () => {
expect(freeUrl("https://medium.com/my-post")).toBe(
"https://freedium-mirror.cfd/my-post"
"https://freedium-mirror.cfd/my-post",
);
expect(freeUrl("https://www.medium.com/my-post")).toBe(
"https://freedium-mirror.cfd/my-post"
"https://freedium-mirror.cfd/my-post",
);
expect(freeUrl("https://some-subdomain.medium.com/my-post")).toBe(
"https://freedium-mirror.cfd/my-post"
);
expect(freeUrl("https://medium.com/hackernoon/hello-world-79436a73e443")).toBe(
"https://freedium-mirror.cfd/hackernoon/hello-world-79436a73e443"
"https://freedium-mirror.cfd/my-post",
);
expect(
freeUrl("https://medium.com/hackernoon/hello-world-79436a73e443"),
).toBe("https://freedium-mirror.cfd/hackernoon/hello-world-79436a73e443");
});
});