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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules/
*.log
.DS_Store
coverage/
.nyc_output/
.vscode/
package-lock.json
3 changes: 3 additions & 0 deletions _locales/ar/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@
"orange": {
"message": "برتقالي"
},
"originalTitleToggle": {
"message": "التبديل بين العنوان الأصلي/المترجم"
},
"os": {
"message": "نظام التشغيل"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,9 @@
"orange": {
"message": "Orange"
},
"originalTitleToggle": {
"message": "Originalen/übersetzten Titel umschalten"
},
"os": {
"message": "Betriebsystem"
},
Expand Down
8 changes: 3 additions & 5 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@
"characterEdgeStyle": {
"message": "Character Edge Style"
},
"cinemaMode": {
"message": "Cinema Mode"
},
"clip": {
"message": "Clip"
},
Expand Down Expand Up @@ -692,6 +689,9 @@
"hideDetails": {
"message": "Hide details"
},
"originalTitleToggle": {
"message": "Toggle original/translated title"
},
"hideEndscreen": {
"message": "Hide endscreen"
},
Expand Down Expand Up @@ -1526,8 +1526,6 @@
"excludeShortsInPlayAll": {
"message": "Exclude Shorts when using \"Play all\""
},
"fullScreenQuality": {
"message": "Fullscreen quality"
"secondaryColor": {
"message": "Secondary color"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,9 @@
"orange": {
"message": "Naranja"
},
"originalTitleToggle": {
"message": "Alternar título original/traducido"
},
"os": {
"message": "OS"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@
"openPopupPlayer": {
"message": "Ouvrir Video/playlist dans un nouvelle onglet"
},
"originalTitleToggle": {
"message": "Basculer entre titre original/traduit"
},
"other": {
"message": "Autres"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/hi/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@
"orange": {
"message": "नारंगी रंग"
},
"originalTitleToggle": {
"message": "मूल/अनुवादित शीर्षक टॉगल करें"
},
"os": {
"message": "ओ एस"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@
"orange": {
"message": "Arancione"
},
"originalTitleToggle": {
"message": "Alterna titolo originale/tradotto"
},
"os": {
"message": "Sistema Operativo"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@
"orange": {
"message": "オレンジ"
},
"originalTitleToggle": {
"message": "元のタイトル/翻訳されたタイトルを切り替え"
},
"other": {
"message": "その他"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,9 @@
"orange": {
"message": "주황"
},
"originalTitleToggle": {
"message": "원본/번역된 제목 전환"
},
"os": {
"message": "운영체제"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,9 @@
"orange": {
"message": "Oranje"
},
"originalTitleToggle": {
"message": "Schakel tussen originele/vertaalde titel"
},
"os": {
"message": "Besturingssysteem"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/pl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@
"orange": {
"message": "Pomarańczowy"
},
"originalTitleToggle": {
"message": "Przełącz tytuł oryginalny/przetłumaczony"
},
"other": {
"message": "Inne"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/pt/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@
"orange": {
"message": "Laranja"
},
"originalTitleToggle": {
"message": "Alternar título original/traduzido"
},
"os": {
"message": "Sistema Operacional"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@
"orange": {
"message": "Оранжевый"
},
"originalTitleToggle": {
"message": "Переключить оригинальное/переведённое название"
},
"os": {
"message": "ОС"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/sk/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@
"orange": {
"message": "Oranžová"
},
"originalTitleToggle": {
"message": "Prepnúť pôvodný/preložený názov"
},
"other": {
"message": "Ostatné"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/tr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@
"orange": {
"message": "Turuncu"
},
"originalTitleToggle": {
"message": "Orijinal/çevrilmiş başlığı değiştir"
},
"other": {
"message": "Diğer"
},
Expand Down
3 changes: 3 additions & 0 deletions _locales/zh/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@
"ok": {
"message": "確定"
},
"originalTitleToggle": {
"message": "切换原始/翻译标题"
},
"other": {
"message": "其他"
},
Expand Down
48 changes: 48 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,54 @@ chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
} else { console.error('Permission is not granted.'); }
})
break
case 'get-original-title':
case 'fetch-video-page':
// Fetch the original title without CORS restrictions
if (message.videoId) {
fetch(`https://www.youtube.com/watch?v=${message.videoId}`)
.then(response => response.text())
.then(html => {
// Helper function to decode HTML entities (without DOM)
function decodeHtmlEntities(text) {
return text
.replace(/&/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#39;/g, "'")
.replace(/&#(\d+);/g, (match, dec) => String.fromCharCode(dec))
.replace(/&#x([0-9a-f]+);/gi, (match, hex) => String.fromCharCode(parseInt(hex, 16)));
}

// Extract title from HTML
const titleMatch = html.match(/<meta\s+name="title"\s+content="([^"]+)"/i);
if (titleMatch && titleMatch[1]) {
const decodedTitle = decodeHtmlEntities(titleMatch[1]);
console.log('Background: Found title from meta tag:', decodedTitle);
sendResponse({ title: decodedTitle });
} else {
// Try alternate method
const altMatch = html.match(/"title":"([^"]+)"/);
if (altMatch && altMatch[1]) {
// This one might have unicode escapes, decode them too
let title = altMatch[1];
title = title.replace(/\\u([0-9a-fA-F]{4})/g, (match, code) => String.fromCharCode(parseInt(code, 16)));
const decodedTitle = decodeHtmlEntities(title);
console.log('Background: Found title from JSON:', decodedTitle);
sendResponse({ title: decodedTitle });
} else {
console.log('Background: No title found in HTML');
sendResponse({ title: null });
}
}
})
.catch(error => {
console.error('Background: Error fetching original title:', error);
sendResponse({ title: null });
});
return true; // Keep the message channel open for async response
}
break
}
});
/*-----# UNINSTALL URL-----------------------------------*/
Expand Down
2 changes: 2 additions & 0 deletions build/manifest3Firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"js&css/extension/www.youtube.com/appearance/header/header.css",
"js&css/extension/www.youtube.com/appearance/player/player.css",
"js&css/extension/www.youtube.com/appearance/details/details.css",
"js&css/extension/www.youtube.com/appearance/details/original-title.css",
"js&css/extension/www.youtube.com/appearance/sidebar/sidebar.css",
"js&css/extension/www.youtube.com/appearance/comments/comments.css"
],
Expand Down Expand Up @@ -82,6 +83,7 @@
"js&css/web-accessible/www.youtube.com/shortcuts.js",
"js&css/web-accessible/www.youtube.com/blocklist.js",
"js&css/web-accessible/www.youtube.com/settings.js",
"js&css/web-accessible/www.youtube.com/original-title.js",
"js&css/web-accessible/init.js",
"menu/icons/48.png"
],
Expand Down
9 changes: 9 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
module.exports = {
testEnvironment: 'jsdom',
testPathIgnorePatterns: [
"/node_modules/"
],
testMatch: [
"**/tests/**/*.js"
],
collectCoverage: true,
coverageDirectory: "coverage",
coverageReporters: ["text", "lcov", "html"],
collectCoverageFrom: [
"js&css/**/*.js",
"!js&css/**/node_modules/**",
"!js&css/web-accessible/www.youtube.com/original-title.js" // We'll test this file
]
};
25 changes: 25 additions & 0 deletions js&css/extension/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ extension.inject([
'/js&css/web-accessible/www.youtube.com/blocklist.js',
'/js&css/web-accessible/www.youtube.com/settings.js',
'/js&css/web-accessible/www.youtube.com/last-watched-overlay.js', // Neue Zeile hinzufügen
'/js&css/web-accessible/www.youtube.com/original-title.js',
'/js&css/web-accessible/init.js'
], function () {
extension.ready = true;
Expand Down Expand Up @@ -256,3 +257,27 @@ document.addEventListener('it-play', function () {
chrome.runtime.sendMessage({ action: 'play' })
} catch (error) { console.log(error); setTimeout(function () { try { chrome.runtime.sendMessage({ action: 'play' }, function (response) { console.log(response) }); } catch { } }, 321) }
});

// Listen for original title fetch requests from web-accessible scripts
window.addEventListener('message', function(event) {
if (event.data && event.data.type === 'IT_FETCH_ORIGINAL_TITLE' && event.data.videoId) {
const videoId = event.data.videoId;
const messageId = event.data.messageId;

console.log('Content script received title fetch request for video:', videoId, 'messageId:', messageId);

// Forward to background script
chrome.runtime.sendMessage({
action: 'fetch-video-page',
videoId: videoId
}, function(response) {
console.log('Content script received response from background:', response);
// Send response back to web-accessible script
window.postMessage({
type: 'IT_ORIGINAL_TITLE_RESPONSE',
messageId: messageId,
title: response ? response.title : null
}, '*');
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*------------------------------------------------------------------------------
>>> ORIGINAL TITLE TOGGLE
------------------------------------------------------------------------------*/

/* Make clickable title have a subtle hover effect */
h1.style-scope.ytd-watch-metadata yt-formatted-string[data-it-original-title] {
transition: opacity 0.2s ease, color 0.2s ease;
}

h1.style-scope.ytd-watch-metadata yt-formatted-string[data-it-original-title]:hover {
opacity: 0.8;
}

/* Style the toggle indicator */
.it-title-toggle-indicator {
display: inline-block;
transition: opacity 0.2s ease, transform 0.2s ease;
user-select: none;
vertical-align: middle;
}

.it-title-toggle-indicator:hover {
transform: scale(1.1);
}

/* Add a subtle underline when hovering over clickable titles */
h1.style-scope.ytd-watch-metadata yt-formatted-string[style*="cursor: pointer"]:hover {
text-decoration: underline;
text-decoration-style: dotted;
text-underline-offset: 4px;
}

/* Smooth transition when title text changes */
h1.style-scope.ytd-watch-metadata yt-formatted-string[data-it-original-title] {
animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
0% {
opacity: 0.7;
}
100% {
opacity: 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ html[it-player-hide-annotations='true'] .annotation-shape,
# HIDE ENDSCREEN
--------------------------------------------------------------*/
html[it-player-hide-endscreen='true'] .html5-endscreen,
html[it-player-hide-endscreen='true'] .ytp-fullscreen-grid-stills-container,
/*--------------------------------------------------------------
# HIDE CARDS
--------------------------------------------------------------*/
Expand Down Expand Up @@ -760,4 +759,4 @@ html[it-revert-theater-button-size='true'] .html5-video-player.ytp-big-mode .ytp
html[it-revert-theater-button-size='true'] .html5-video-player.ytp-big-mode .ytp-time-contents {
display: flex;
align-items: center;
}
}
5 changes: 5 additions & 0 deletions js&css/web-accessible/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ ImprovedTube.videoPageUpdate = function () {
ImprovedTube.playerCinemaModeButton();
ImprovedTube.playerHamburgerButton();
ImprovedTube.playerControls();

// Initialize original title toggle for each new video
if (typeof ImprovedTube.initOriginalTitleToggle === 'function') {
ImprovedTube.initOriginalTitleToggle();
}
}
};

Expand Down
Loading