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
4 changes: 2 additions & 2 deletions FreeYT Extension/Resources/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ async function updateBadge() {
if (chrome.declarativeNetRequest?.onRuleMatchedDebug) {
chrome.declarativeNetRequest.onRuleMatchedDebug.addListener(async (info) => {
try {
// Count only our redirect rules (1,2,3)
if ([1, 2, 3].includes(info?.rule?.ruleId)) {
// Count only our redirect rules (1-5)
if ([1, 2, 3, 4, 5].includes(info?.rule?.ruleId)) {
await incrementRedirectCounter();
// Notify popup (if open)
const ping = chrome.runtime.sendMessage({ type: "statsUpdated" });
Expand Down
3 changes: 1 addition & 2 deletions FreeYT Extension/Resources/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
],
"host_permissions": [
"*://*.youtube.com/*",
"*://youtu.be/*",
"*://yout-ube.com/*"
"*://youtu.be/*"
],
"icons": {
"48": "images/icon-48.png",
Expand Down
46 changes: 40 additions & 6 deletions FreeYT Extension/Resources/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "regexSubstitution": "https://yout-ube.com/\\2" }
"redirect": {
"regexSubstitution": "https://www.youtube-nocookie.com/embed/\\1"
}
},
"condition": {
"regexFilter": "^https?://([a-z0-9-]+\\.)?youtube\\.com/(.*)$",
"regexFilter": "^https?://(?:[a-z0-9-]+\\.)?youtube\\.com/watch\\?[^#]*v=([\\w-]{11})(?:[&#].*)?$",
"resourceTypes": ["main_frame", "sub_frame"]
}
},
Expand All @@ -16,10 +18,12 @@
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "regexSubstitution": "https://yout-ube.com/watch?v=\\1&\\2" }
"redirect": {
"regexSubstitution": "https://www.youtube-nocookie.com/embed/\\1"
}
},
"condition": {
"regexFilter": "^https?://youtu\\.be/([\\w-]{11})\\?(.*)$",
"regexFilter": "^https?://(?:[a-z0-9-]+\\.)?youtube\\.com/shorts/([\\w-]{11})(?:\\?[^#]*)?$",
"resourceTypes": ["main_frame", "sub_frame"]
}
},
Expand All @@ -28,10 +32,40 @@
"priority": 1,
"action": {
"type": "redirect",
"redirect": { "regexSubstitution": "https://yout-ube.com/watch?v=\\1" }
"redirect": {
"regexSubstitution": "https://www.youtube-nocookie.com/embed/\\1"
}
},
"condition": {
"regexFilter": "^https?://youtu\\.be/([\\w-]{11})$",
"regexFilter": "^https?://youtu\\.be/([\\w-]{11})(?:\\?[^#]*)?$",
"resourceTypes": ["main_frame", "sub_frame"]
Comment on lines 32 to +41

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve query parameters when rewriting YouTube URLs

The new redirect rules rewrite any matched YouTube URL to https://www.youtube-nocookie.com/embed/<videoId> but they drop the original query string entirely. Share links such as watch?v=<id>&t=90, watch?v=<id>&list=…, or https://youtu.be/<id>?t=30 now redirect to an embed that always starts from the beginning and loses playlist or other context. Prior to this commit, regexSubstitution forwarded the entire path and query (\2), so start times and other parameters were preserved. This regression affects any link that depends on query parameters for desired playback behaviour.

Useful? React with 👍 / 👎.

}
},
{
"id": 4,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "https://www.youtube-nocookie.com/embed/\\1"
}
},
"condition": {
"regexFilter": "^https?://(?:[a-z0-9-]+\\.)?youtube\\.com/embed/([\\w-]{11})(?:\\?[^#]*)?$",
"resourceTypes": ["main_frame", "sub_frame"]
}
},
{
"id": 5,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "https://www.youtube-nocookie.com/embed/\\1"
}
},
"condition": {
"regexFilter": "^https?://(?:[a-z0-9-]+\\.)?youtube\\.com/live/([\\w-]{11})(?:\\?[^#]*)?$",
"resourceTypes": ["main_frame", "sub_frame"]
}
}
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,15 @@ FreeYT/
Defines extension permissions, background worker, toolbar action, and declarativeNetRequest rules.

### rules.json
Contains regex patterns for matching and redirecting YouTube URLs. All redirect rules use priority 1 and apply to youtube.com domains.
Implements the declarativeNetRequest redirects that make the extension useful. The five rules cover the most common YouTube entry points and convert them to their privacy-respecting embeds on `youtube-nocookie.com`:

1. `youtube.com/watch` (including `m.youtube.com`) → `https://www.youtube-nocookie.com/embed/<videoId>`
2. `youtube.com/shorts/<videoId>` → `https://www.youtube-nocookie.com/embed/<videoId>`
3. `youtu.be/<videoId>` → `https://www.youtube-nocookie.com/embed/<videoId>`
4. `youtube.com/embed/<videoId>` → `https://www.youtube-nocookie.com/embed/<videoId>` (ensures existing embeds shed tracking cookies)
5. `youtube.com/live/<videoId>` → `https://www.youtube-nocookie.com/embed/<videoId>`

All rules target both `main_frame` and `sub_frame` resource types so that navigation, links, and inline iframes receive the same privacy upgrade.

### background.js
Service worker that:
Expand Down