From ac1fe4a89b63eebca21538779e4113d792e481e9 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 28 Jul 2018 08:25:01 +0200 Subject: Move annotation shutoff code into interval Still not working, just an idea while figuring out what's going on & how to get access to the menu item. --- youtube-turn-off-annotations.user.js | 58 +++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/youtube-turn-off-annotations.user.js b/youtube-turn-off-annotations.user.js index eaaf889..6691df6 100644 --- a/youtube-turn-off-annotations.user.js +++ b/youtube-turn-off-annotations.user.js @@ -6,37 +6,41 @@ // ==/UserScript== -var annotations_menu_item = document.evaluate( - "//div[contains(@class, 'ytp-settings-menu')] \ - //div[ \ - @aria-checked='true' and \ +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 -); + ]", + document, + null, + XPathResult.FIRST_ORDERED_NODE_TYPE, + null + ); -// if (annotations_menu_item) { -// annotations_menu_item.singleNodeValue.click(); -// } + console.log(annotations_is_present); + if (annotations_is_present) { + var annotations_menu_item = document.evaluate( + "//div[contains(@class, 'ytp-settings-menu')] \ + //div[ \ + @aria-checked='true' and \ + //div[ \ + contains(@class, 'ytp-menuitem-label') and \ + contains(., 'Annotations') \ + ] \ + ]", + document, + null, + XPathResult.FIRST_ORDERED_NODE_TYPE, + null + ); -window.setInterval(function() { -var annotations = 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 -); + if (annotations_menu_item.singleNodeValue) { + annotations_menu_item.singleNodeValue.click(); + console.log(annotations_menu_item.singleNodeValue); + } - console.log(annotations.singleNodeValue); + // window.clearInterval(find_annotations_interval); + } }, 1000); -- cgit v1.2.3