Skip to content

Commit

Permalink
0.2.7b
Browse files Browse the repository at this point in the history
Improved: Changing between playlist and single video now updates the
previous and next controls correctly when video autoplay is disabled
Closes #167
  • Loading branch information
ParticleCore committed Sep 16, 2017
1 parent 38d3add commit fdccf47
Showing 1 changed file with 66 additions and 21 deletions.
87 changes: 66 additions & 21 deletions src/userscript/Iridium.user.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// ==UserScript==
// @version 0.2.6b
// @version 0.2.7b
// @name Iridium
// @namespace https://github.com/ParticleCore
// @description YouTube with more freedom
// @compatible firefox
// @compatible chrome
// @resource iridium_css https://particlecore.github.io/Iridium/css/Iridium.css?v=0.2.6b
// @resource iridium_css https://particlecore.github.io/Iridium/css/Iridium.css?v=0.2.7b
// @icon https://raw.githubusercontent.com/ParticleCore/Iridium/gh-pages/images/i-icon.png
// @match *://www.youtube.com/*
// @exclude *://www.youtube.com/tv*
Expand Down Expand Up @@ -1859,6 +1859,8 @@

if (current_config && current_config.args) {

context.updatePlayerLayout = !!current_config.args.list !== !!args.list;

if ((current_config.args.eventid === args.eventid || current_config.args.loaderUrl === args.loaderUrl)) {

if (!document.querySelector(".ended-mode") && (current_video_id = window.location.href.match(iridium_api.videoIdPattern))) {
Expand Down Expand Up @@ -2053,6 +2055,19 @@

};

},
interceptHooks: function () {

if (iridium_api.checkIfExists("yt.player.Application.create")) {

window.yt.player.Application.create = this.modPlayerLoad(window.yt.player.Application.create);

document.documentElement.removeEventListener("load", this.fileLoadListener, true);

this.fileLoadListener = null;

}

},
handleCustoms: function (event) {

Expand Down Expand Up @@ -2480,10 +2495,13 @@
}

},
loadStart: function () {
loadStart: function (event) {

var is_watch;
var is_playlist;
var meta_section;
var quick_controls;
var yt_player_manager;

if (this.quickControlsListener) {

Expand Down Expand Up @@ -2541,6 +2559,7 @@
this.quickControlsState();

this.quickControlsListener = this.quickControls.bind(this);

document.addEventListener("click", this.quickControlsListener, false);

} else if (quick_controls && !user_settings.player_quick_controls) {
Expand All @@ -2549,6 +2568,35 @@

}

if (event) {

is_watch = window.location.pathname === "/watch";
is_playlist = !!window.location.search.match(/list=[A-Z]{2}/);

switch (event.type) {

case "popstate":
case "yt-navigate-start":

if (!user_settings.player_auto_play && (is_watch !== this.was_watch || is_playlist !== this.was_playlist)) {

if ((yt_player_manager = document.querySelector("yt-player-manager")) && yt_player_manager["playerContainer_"]) {

yt_player_manager["playerContainer_"] = undefined;

}

}

break;

}

this.was_watch = is_watch;
this.was_playlist = is_playlist;

}

},
onSettingsUpdated: function () {

Expand Down Expand Up @@ -2586,21 +2634,35 @@
window.removeEventListener("yt-page-data-updated", this.loadStartListener, true);
window.removeEventListener("yt-navigate-start", this.loadStartListener, false);
window.removeEventListener("yt-navigate-finish", this.loadStartListener, false);
this.loadStartListener = null;
window.removeEventListener("popstate", this.loadStartListener, true);

}

this.loadStartListener = this.loadStart.bind(this);

window.addEventListener("yt-page-data-updated", this.loadStartListener, true);
window.addEventListener("yt-navigate-start", this.loadStartListener, false);
window.addEventListener("yt-navigate-finish", this.loadStartListener, false);
window.addEventListener("popstate", this.loadStartListener, true);

if (this.fileLoadListener) {

document.documentElement.removeEventListener("load", this.fileLoadListener, true);

}

this.fileLoadListener = this.interceptHooks.bind(this);

document.documentElement.addEventListener("load", this.fileLoadListener, true);

window.matchMedia = this.modMatchMedia(window.matchMedia);
window.onYouTubePlayerReady = this.shareApi(window.onYouTubePlayerReady);
JSON.parse = this.modJSONParse(JSON.parse);
XMLHttpRequest.prototype.open = this.modOpen(XMLHttpRequest.prototype.open);
DOMParser.prototype.parseFromString = this.modParseFromString(DOMParser.prototype.parseFromString);

this.interceptHooks();

context = this;

Object.defineProperties(Object.prototype, {
Expand Down Expand Up @@ -2662,23 +2724,6 @@

}
},
create: {
set: function (data) {

if (data.toString && data.toString().match(/:"player"+/)) {

this._create = context.modPlayerLoad(data);

} else {

this._create = data;

}
},
get: function () {
return this._create;
}
},
playVideo: {
set: function (data) {
this._playVideo = data;
Expand Down

0 comments on commit fdccf47

Please sign in to comment.