• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5const button_selector =
6    'div.body.style-scope.ytd-consent-bump-v2-lightbox > div.eom-buttons.style-scope.ytd-consent-bump-v2-lightbox > div:nth-child(1) > ytd-button-renderer:nth-child(1) > yt-button-shape > button'
7const banner_selector =
8    'ytd-consent-bump-v2-lightbox > tp-yt-paper-dialog[id=dialog]'
9
10const button_observer = new MutationObserver(mutations => {
11  const button = document.querySelector(button_selector)
12  if (!button) {
13    return
14  }
15  const banner_node = document.querySelector(banner_selector)
16  if (!banner_node) {
17    return
18  }
19  if (localStorage.getItem('already_run') === 'already_run') {
20    return
21  }
22  localStorage.setItem('already_run', 'already_run')
23  const banner_observer = new MutationObserver(function(e) {
24    for (m of e) {
25      if (m.type == 'attributes' && banner_node.style.display == 'none') {
26        performance.mark('cookie_banner_gone')
27        break
28      }
29    }
30  });
31  banner_observer.observe(
32      banner_node, {attributes: true, attributeFilter: ['style']});
33  performance.mark('cookie_banner_shown')
34  button.click()
35})
36
37button_observer.observe(document, {childList: true, subtree: true});
38