From 65edb92a57994b4654160460ac3823cdd2a9d5b4 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 28 Jul 2018 08:27:24 +0200 Subject: Click the "settings" gear icon to populate settings menu It turns out the settings pop-up menu isn't populated at page load. Now that I think about it, this makes sense because different videos are going to have different options available. I think. We can force the settings menu to load by clicking the gear icon twice, opening then closing the settings pop-up menu. Following this, the annotation menu item element will exist and we can click it to disable annotations. We don't even need the interval any more. --- youtube-turn-off-annotations.user.js | 38 +++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/youtube-turn-off-annotations.user.js b/youtube-turn-off-annotations.user.js index 6691df6..16c4104 100644 --- a/youtube-turn-off-annotations.user.js +++ b/youtube-turn-off-annotations.user.js @@ -6,21 +6,27 @@ // ==/UserScript== -var find_annotations_interval = window.setInterval(function() { - var annotations_is_present = document.evaluate( - "//div[contains(@class, 'ytp-settings-menu')] \ - //div[ \ - contains(@class, 'ytp-menuitem-label') and \ - contains(., 'Annotations') \ - ]", - document, - null, - XPathResult.FIRST_ORDERED_NODE_TYPE, - null - ); +var settings_button = document.querySelector('.ytp-settings-button'); - console.log(annotations_is_present); - if (annotations_is_present) { +// Load annotations menu item by activating & deactivating the settings menu +settings_button.click(); +settings_button.click(); + +// var find_annotations_interval = window.setInterval(function() { + // var annotations_is_present = document.evaluate( + // "//div[contains(@class, 'ytp-settings-menu')] \ + // //div[ \ + // contains(@class, 'ytp-menuitem-label') and \ + // contains(., 'Annotations') \ + // ]", + // document, + // null, + // XPathResult.FIRST_ORDERED_NODE_TYPE, + // null + // ); + // + // console.log(annotations_is_present); + // if (annotations_is_present) { var annotations_menu_item = document.evaluate( "//div[contains(@class, 'ytp-settings-menu')] \ //div[ \ @@ -42,5 +48,5 @@ var find_annotations_interval = window.setInterval(function() { } // window.clearInterval(find_annotations_interval); - } -}, 1000); +// } +// }, 1000); -- cgit v1.2.3