sniff1 Posted July 6, 2017 Report Share Posted July 6, 2017 I have written a script to hide the video window on youtube, and it works when the page is opened directly, or from the address bar. But if I click any link on youtube, the script doesn't even start. even the first line of the scripts never runs, which is simply this: console.log('Starting script'); Link to comment Share on other sites More sharing options...
7twenty Posted July 6, 2017 Report Share Posted July 6, 2017 Can you provide a link to the script so others can test? Link to comment Share on other sites More sharing options...
sniff1 Posted July 6, 2017 Author Report Share Posted July 6, 2017 Like I said, it happens on any script even if you just use it like this: // ==UserScript== // @name Youtube // @namespace Violentmonkey Scripts // @include http://*.youtube.* // @include https://*.youtube.* // @grant none // @run-at document-end // ==/UserScript== console.log('start'); You won't see that in the console after clicking a link. It seems that when you click a link on YouTube the page doesn't actually reload. Link to comment Share on other sites More sharing options...
7twenty Posted July 6, 2017 Report Share Posted July 6, 2017 Hmmm it does seem a bit random. Although even on Chrome it did seem to depend on what link you clicked at some times. Link to comment Share on other sites More sharing options...
sniff1 Posted July 7, 2017 Author Report Share Posted July 7, 2017 I think it's because Youtube does some Lazy Load for some of the pages... Any ideas on how to figure it out? I attached a function to the <video> tag, but it doesnt work coming from the main page (which doesn't have a <video> tag) Link to comment Share on other sites More sharing options...
bayas Posted July 7, 2017 Report Share Posted July 7, 2017 On 07.07.2017 at 2:01 PM, sniff1 said: I think it's because Youtube does some Lazy Load for some of the pages... Any ideas on how to figure it out? I attached a function to the <video> tag, but it doesnt work coming from the main page (which doesn't have a <video> tag) Your issue is not related to the ViolentMonkey. You must observe some elements in javascript to change some functionalities. Here is an example for your need. // ==UserScript== // @name Youtube // @namespace Violentmonkey Scripts // @include http://*.youtube.* // @include https://*.youtube.* // @grant none // @run-at document-end // ==/UserScript== console.log('My Script Injected!'); function myVideoFunction() { console.log('New Youtube video loading..'); var video = document.querySelector('#player video'); video.playbackRate = 10.0; } var observer = new WebKitMutationObserver(function (mutations) { mutations.forEach(function (mutation) { for (i = 0; i < mutation.addedNodes.length; i++) { if (mutation.addedNodes[i].id === 'watch7-main-container') { myVideoFunction(); } } }); }); var ytPage = document.getElementById('page'); observer.observe(ytPage, { childList: true, subtree: true }); Link to comment Share on other sites More sharing options...
sniff1 Posted July 8, 2017 Author Report Share Posted July 8, 2017 I realized that after seeing the lazy load part of youtube, was going to write a mutation observer. You made my life easier. Awesome, thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.