Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
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
6 changes: 3 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//opens youtube on install
chrome.runtime.onInstalled.addListener(function(details) {
if(details.reason == "install") {
// open YouTube on install
chrome.runtime.onInstalled.addListener(details => {
if(details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
chrome.tabs.create({url: "https://www.youtube.com/"});
}
});
79 changes: 42 additions & 37 deletions content.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
// creates set cookie function for easy replacement
function setCookie(name, value, days, domain, path) {
let expires = "";
let secureFlag = "";
if (days) {
let date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
expires = "; expires=" + date.toUTCString();
}
let cookieString = name + "=" + value + expires;
if (domain) {
cookieString += "; domain=" + domain;
}
if (path) {
cookieString += "; path=" + path;
} else {
cookieString += "; path=/";
}
if (window.location.protocol === "https:") {
secureFlag = "; secure";
}
document.cookie = cookieString + secureFlag;
}

// Set the PREF cookie reponsible for your theme
setCookie("PREF", "f6=8", 365, ".youtube.com", "/");

//the function is self explanatory but the new update doesnt force open it in a new tab anymore
function openYoutubeVideoInTab(e) {
// helper function to set the document's cookie
const setCookie = (name, value, days, domain = ".youtube.com", path = "/") => {
// if days exists, convert days to seconds for expiration
const expires = days ? `max-age=${days * 86400}` : "";
// include "secure" if https is used
const isSecure = window.location.protocol === "https:" ? "secure" : "";
document.cookie = `${name}=${encodeURIComponent(value)}; ${expires}; domain=${domain}; path=${path}; ${isSecure}`;
};

const openYoutubeVideoInTab = (e) => {
// ignore right-click or if Alt key is pressed
if (e.button > 1 || e.altKey) return;
if (e.target.classList.contains('ytp-scrubber-pull-indicator')) return;

var link = e.target.closest('[href^="/watch"]');
if (!link || (link.getAttribute('href') || '').match(/^(javascript|#|$)/) || link.href.replace(/#.*/, '') == location.href.replace(/#.*/, '')) return;

window.open(link.href, '_self');
//cancels the event that youtube uses for dynamic websites

// ignore if the target is the player's scrubber
if (e.target.classList.contains("ytp-scrubber-pull-indicator")) return;

// find the closest link element that starts with "/watch"
const link = e.target.closest('[href^="/watch"]');

// ignore if the link is not valid or a JavaScript/anchor link
if (
!link ||
(link.getAttribute("href") || "").match(/^(javascript|#|$)/) ||
link.href.replace(/#.*/, "") === location.href.replace(/#.*/, "")
)
return;

// extract search parameters from the current URL
const searchParams = new URLSearchParams(window.location.search);

// append search parameters to the link href
const href = new URL(link.href);
if (searchParams.size > 1) href.searchParams.append(...searchParams);

// open the link with preserved search parameters in the same tab
window.open(href.toString(), "_self");

// cancel events YouTube uses for dynamic websites
e.preventDefault();
}
};

// set the PREF value to disable new UI
setCookie("PREF", "f6=8", 365);

// add listener to open the video with new UI
window.addEventListener('mouseup', openYoutubeVideoInTab, true);
21 changes: 11 additions & 10 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"manifest_version": 2,
"name": "YouTube Cookie Setter",
"version": "1.0",
"description": "Sets a YouTube cookie.",
"manifest_version": 3,
"name": "Revert YouTube UI",
"version": "1.1",
"description": "Reverts new desktop YouTube UI implemented in April 2023.",
"content_scripts": [
{
"matches": ["https://www.youtube.com/*"],
"js": ["content.js"]
"js": ["content.js"],
"matches": ["https://*.youtube.com/*"]
}
],
"browser_action": {
"action": {
"default_popup": "popup.html"
},
"background": {
"scripts": ["background.js"],
"persistent": false
}
"service_worker": "background.js",
"permissions": ["scripting", "activeTab"]
},
"host_permissions": ["https://*.youtube.com/*"]
}