Skip to content

Commit

Permalink
Youtube Click To Load - UI Implementation (#1433)
Browse files Browse the repository at this point in the history
* POC Youtube CTL

* Implement YouTube CTL Dialog with Previews toggle

* Implement YouTube CTL Preview Placeholder UI

* Update modal UI for both Facebook CTL and YouTube CTL.

* Fix typos in options.json

* Update styles for "Enable YouTube Previews" in options page

* Fix styles for centering modal and cursor for preview title

* Add Share Feedback element to CTL blocked dialog and YT Preview placeholder

* Enable YT CTL integration tests again

* Clean up click-to-load.js and add more comments to funcitons

* Lint code

* Comment out YT Preview option while feature is not released

* Show "Share Feedback" link only with YT CTL enabled

* Clean up and code improvements to message-handlers.js

* Clean up sendAllTabsMessage()

* Size YT placeholder according to original element size

* Clean up YT CTL code and add more comments

* Update YouTube CTL integration test configuration

* Rollback YT CTL feature flag

* Change hideTrackingElement to true for YT block dialog

* Only build YT placeholders according to active setting

* Fix getCloseIcon path

* Remove social_ctp_configuration.json

* Update ClickToLoadConfig to use external resource

Co-authored-by: francielefaccin <franfaccin@duck.com>
  • Loading branch information
franfaccin and franfaccin committed Oct 25, 2022
1 parent b1c09e3 commit 87b6c58
Show file tree
Hide file tree
Showing 14 changed files with 707 additions and 54 deletions.
25 changes: 20 additions & 5 deletions integration-test/data/configs/click-to-load-youtube.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,19 @@
],
"replaceSettings": {
"type": "youtube-video",
"buttonText": "Unblock Video",
"infoTitle": "DuckDuckGo blocked this video to prevent YouTube from tracking you",
"infoText": "We blocked YouTube from tracking you when the page loaded. If you unblock this Video, YouTube will know your activity.",
"simpleInfoText": "We blocked YouTube from tracking you when the page loaded. If you unblock this Video, YouTube will know your activity."
"buttonText": "Unblock video",
"infoTitle": "DuckDuckGo blocked this YouTube video to prevent Google from tracking you",
"infoText": "We blocked Google (which owns YouTube) from tracking you when the page loaded. If you unblock this video, Google will know your activity.",
"simpleInfoText": "We blocked Google (which owns YouTube) from tracking you when the page loaded. If you unblock this video, Google will know your activity.",
"previewToggleText": "Previews disabled for additional privacy",
"placeholder": {
"previewToggleEnabledText": "Previews enabled",
"previewInfoText": "Turn previews off for additional privacy from DuckDuckGo.",
"videoPlayIcon": {
"lightMode": "video_play_light.svg",
"darkMode": "video_play_dark.svg"
}
}
},
"clickAction": {
"type": "youtube-video"
Expand All @@ -58,7 +67,13 @@
}
}
},
"informationalModal": {},
"informationalModal": {
"icon": "blocked_youtube_video.svg",
"messageTitle": "Enable YouTube previews and reduce privacy?",
"messageBody": "Showing previews will allow Google (which owns YouTube) to see some of your device’s information, but is still more private than playing the video.",
"confirmButtonText": "Enable Previews",
"rejectButtonText": "No Thanks"
},
"surrogates": [
{
"rule": "(www.)?youtube(-nocookie)?.com/iframe_api",
Expand Down
1 change: 1 addition & 0 deletions shared/data/defaultSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
httpsEverywhereEnabled: true,
embeddedTweetsEnabled: false,
GPC: true,
youtubePreviewsEnabled: false,
atb: null,
set_atb: null,
'config-etag': null,
Expand Down
13 changes: 13 additions & 0 deletions shared/img/social/blocked_youtube_video.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions shared/img/social/close.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions shared/img/social/video_play_dark.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions shared/img/social/video_play_light.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions shared/js/background/message-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,34 @@ export async function initClickToLoad (unused, sender) {
return config
}

export async function getYouTubeVideoDetails (videoURL) {
const endpointURL = new URL('https://www.youtube.com/oembed?format=json')
const parsedVideoURL = new URL(videoURL)

const playlistID = parsedVideoURL.searchParams.get('list')
const videoId = parsedVideoURL.pathname.split('/').pop()

if (playlistID) {
parsedVideoURL.hostname = endpointURL.hostname
endpointURL.searchParams.set('url', parsedVideoURL.href)
} else {
endpointURL.searchParams.set('url', 'https://youtu.be/' + videoId)
}

try {
const youTubeVideoResponse = await fetch(
endpointURL.href, {
referrerPolicy: 'no-referrer',
credentials: 'omit'
}
).then(response => response.json())
const { title, thumbnail_url: previewImage } = youTubeVideoResponse
return { status: 'success', title, previewImage }
} catch (e) {
return { status: 'failed' }
}
}

export function getLoadingImage (theme) {
if (theme === 'dark') {
return utils.imgToData('img/social/loading_dark.svg')
Expand All @@ -146,6 +174,10 @@ export function getLogo () {
return utils.imgToData('img/social/dax.png')
}

export function getCloseIcon () {
return getImage('close.svg')
}

export function getCurrentTab () {
return utils.getCurrentTab()
}
Expand Down Expand Up @@ -186,6 +218,7 @@ export async function enableSocialTracker (data, sender) {
export async function updateSetting ({ name, value }) {
await settings.ready()
settings.updateSetting(name, value)
utils.sendAllTabsMessage({ messageType: `ddg-settings-${name}`, value })
}

export async function getSetting ({ name }) {
Expand Down
10 changes: 10 additions & 0 deletions shared/js/background/utils.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ export async function sendTabMessage (id, message, details) {
}
}

export async function sendAllTabsMessage (message, details) {
try {
for (const { id: tabId } of await browser.tabs.query({})) {
sendTabMessage(tabId, message, details)
}
} catch {
// Ignore errors
}
}

/**
* @param {string} urlString
* @returns {string | null} etld plus one of the URL
Expand Down

0 comments on commit 87b6c58

Please sign in to comment.