Skip to content

Commit 44cdc12

Browse files
authored
Merge pull request #2889 from wbalbo/clickable-links-in-description
Clickable links in description of both Subscriptions and Search Results page.
2 parents 053c9eb + 1d21c49 commit 44cdc12

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

_locales/en/messages.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,5 +1439,8 @@
14391439
},
14401440
"pauseWhileIAmTypingOnYouTube": {
14411441
"message": "Pause when I'm typing on YouTube"
1442+
},
1443+
"clickableLinksInDescription": {
1444+
"message": "Right click to copy links in video descriptions"
14421445
}
14431446
}

js&css/extension/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function bodyReady () {
2828
if (extension.ready && extension.domReady) {
2929
extension.features.addScrollToTop();
3030
extension.features.font();
31+
extension.features.clickableLinksInVideoDescriptions();
3132
}
3233
}
3334

@@ -44,7 +45,7 @@ extension.events.on('init', function () {
4445
extension.features.relatedVideos();
4546
extension.features.comments();
4647
extension.features.openNewTab();
47-
extension.features.removeListParamOnNewTab();
48+
extension.features.removeListParamOnNewTab();
4849
bodyReady();
4950
});
5051

js&css/extension/www.youtube.com/general/general.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,3 +616,37 @@ extension.features.removeListParamOnNewTab = function () {
616616
};
617617

618618
extension.features.removeListParamOnNewTab();
619+
620+
/*--------------------------------------------------------------
621+
# CLICKABLE LINKS IN VIDEO DESCRIPTIONS
622+
--------------------------------------------------------------*/
623+
extension.features.clickableLinksInVideoDescriptions = function () {
624+
if (extension.storage.get("clickable_links_in_description") !== true) {
625+
return;
626+
}
627+
628+
document.addEventListener("contextmenu", (e) => {
629+
// Check if the clicked element is a yt-formatted-string with the class we're targeting
630+
const clickedElement = e.target.closest(".style-scope.ytd-video-renderer");
631+
632+
if (clickedElement) {
633+
// Grab the plain text inside the yt-formatted-string (looking for links or URLs)
634+
const textContent = clickedElement.innerText;
635+
636+
// Extract URL using a simple regex (you can customize it to be more accurate)
637+
const urlRegex = /\bhttps?:\/\/[^\s]+/g;
638+
const match = textContent.match(urlRegex);
639+
640+
if (match) {
641+
// Copy the found URL to the clipboard
642+
navigator.clipboard.writeText(match[0]).catch((err) => {
643+
console.error("Failed to copy: ", err);
644+
});
645+
646+
// Prevent the default right-click menu from showing
647+
e.preventDefault();
648+
}
649+
// If no URL found, the normal right-click behavior will happen
650+
}
651+
});
652+
}

menu/skeleton-parts/general.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,10 @@ extension.skeleton.main.layers.section.general = {
408408
remove_list_param_from_links: {
409409
component: 'switch',
410410
text: 'removePlaylistParam'
411+
},
412+
clickable_links_in_description: {
413+
component: 'switch',
414+
text: 'clickableLinksInDescription'
411415
}
412416
}
413417
}

0 commit comments

Comments
 (0)