Last active
September 19, 2018 14:03
-
-
Save Jan-Zeiseweis/3d65340753bce538a2ae732e3d2e1aff to your computer and use it in GitHub Desktop.
yt marked watched
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Marked watched videos | |
// @namespace deKexx | |
// @description Mark watched videos on Youtube | |
// @include http://www.youtube.com/watch* | |
// @include https://www.youtube.com/watch* | |
// @connect popo.local | |
// @author Jan Zeiseweis | |
// @version 0.1 | |
// @grant GM_xmlhttpRequest | |
// @require https://code.jquery.com/jquery-2.1.4.min.js | |
// @require https://gist.githubusercontent.com/raw/2625891/waitForKeyElements.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
var seen_videos = []; | |
function getPlayingVideoId() { | |
return ytplayer.config.args.video_id; | |
} | |
function viewing(video_id) { | |
console.log(video_id); | |
// Locally save history to avoid unnecessary requests. | |
if (seen_videos.indexOf(video_id) === -1) { | |
seen_videos.push(video_id); | |
} | |
var requestDetails = { | |
method: "GET", | |
url: "http://popo.local:5000/viewing/" + video_id, | |
onload: function(response) { | |
console.log(response.responseText); | |
} | |
} | |
GM_xmlhttpRequest(requestDetails); | |
}; | |
viewing(getPlayingVideoId()); | |
function getThumbnailVideoIds() { | |
var thumbnails = document.getElementsByTagName('ytd-thumbnail'); | |
if (thumbnails.length > 19) { | |
console.log(thumbnails.length); | |
for (var i = 0; i < thumbnails.length; i++) { | |
var thumbnail = thumbnails[i]; | |
var href = thumbnail.getElementsByTagName('a')[0].href; | |
var video_id = href.split('=')[1]; | |
console.log(video_id); | |
} | |
} | |
} | |
var mutationObserver = new MutationObserver(function(mutations) { | |
mutations.forEach(function(mutation) { | |
if (mutation.target.id === 'items') { | |
console.log(mutation); | |
} | |
}); | |
}); | |
waitForKeyElements('#related', function() { | |
mutationObserver.observe(document.getElementById('related'), { | |
attributes: false, | |
characterData: false, | |
childList: true, | |
subtree: true, | |
attributeOldValue: false, | |
characterDataOldValue: false | |
}); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment