|
1 | | -const twelveFootDomain = "https://12ft.io/proxy?q="; |
| 1 | +const freediumUrl = "https://freedium.cfd/"; |
2 | 2 | const mediumDomain = "https://medium.com"; |
3 | 3 |
|
4 | | -const add12ftToMediumArticleURL = (url) => { |
5 | | - if (!url.includes(twelveFootDomain)) { |
6 | | - const urlWith12ft = twelveFootDomain + encodeURIComponent(mediumDomain + url); |
7 | | - return urlWith12ft; |
8 | | - } |
9 | | - return url; |
10 | | -}; |
| 4 | +function handleNewArticles(mutationsList) { |
| 5 | + mutationsList.forEach((mutation) => { |
| 6 | + if (mutation.type === "childList") { |
| 7 | + mutation.addedNodes.forEach((node) => { |
| 8 | + if (node.tagName === "ARTICLE") { |
| 9 | + const links = node.querySelectorAll('div[class^="iq"] a'); |
11 | 10 |
|
12 | | -const modifyEachArticleLink = () => { |
13 | | - const links = document.querySelectorAll('a[aria-label="Post Preview Title"]'); |
14 | | - links.forEach((link) => { |
15 | | - const originalURL = link.getAttribute("href"); |
16 | | - const modifiedURL = add12ftToMediumArticleURL(originalURL); |
17 | | - link.setAttribute("href", modifiedURL); |
| 11 | + links.forEach((link) => { |
| 12 | + const originalURL = link.getAttribute("href"); |
| 13 | + const modifiedURL = freediumUrl + originalURL; |
18 | 14 |
|
19 | | - // Prevent the navigation to Medium's detail page, and instead |
20 | | - // navigate to the 12ft.io proxy page |
21 | | - link.addEventListener("click", (event) => { |
22 | | - event.preventDefault(); |
23 | | - window.location.href = modifiedURL; |
24 | | - }); |
25 | | - }); |
26 | | -}; |
| 15 | + link.setAttribute("href", modifiedURL); |
27 | 16 |
|
28 | | -const observeDOMChanges = (mutationsList, observer) => { |
29 | | - for (const mutation of mutationsList) { |
30 | | - if (mutation.type === "childList") { |
31 | | - modifyEachArticleLink(); |
| 17 | + link.addEventListener("click", (event) => { |
| 18 | + event.preventDefault(); |
| 19 | + window.open(modifiedURL, "_blank"); |
| 20 | + }); |
| 21 | + }); |
| 22 | + } |
| 23 | + }); |
32 | 24 | } |
33 | | - } |
34 | | -}; |
35 | | - |
36 | | -const observer = new MutationObserver(observeDOMChanges); |
| 25 | + }); |
| 26 | +} |
37 | 27 |
|
38 | | -// Start observing the target element for changes |
39 | | -const target = document.querySelector("div.dx.s"); |
40 | | -observer.observe(target, { childList: true, subtree: true }); |
| 28 | +const targetNode = document.body; |
| 29 | +const config = { childList: true, subtree: true }; |
| 30 | +const observer = new MutationObserver(handleNewArticles); |
| 31 | +observer.observe(targetNode, config); |
0 commit comments