Fix some drive userscript issues

This commit is contained in:
Calvin Montgomery 2016-10-07 19:55:41 -07:00
parent 7c3f2d0a8b
commit d0d2002a5f
6 changed files with 79 additions and 43 deletions

View file

@ -7,7 +7,7 @@
// @grant GM_xmlhttpRequest
// @connect docs.google.com
// @run-at document-end
// @version 1.1.0
// @version 1.2.0
// ==/UserScript==
try {
@ -67,18 +67,14 @@ try {
});
if (data.status === 'fail') {
error = new Error('Google Docs request failed: ' +
'metadata indicated status=fail');
error.response = res.responseText;
error.reason = 'RESPONSE_STATUS_FAIL';
var error = 'Google Docs request failed: ' +
unescape(data.reason).replace(/\+/g, ' ');
return cb(error);
}
if (!data.fmt_stream_map) {
error = new Error('Google Docs request failed: ' +
'metadata lookup returned no valid links');
error.response = res.responseText;
error.reason = 'MISSING_LINKS';
var error = 'Google Docs request failed: ' +
'metadata lookup returned no valid links';
return cb(error);
}
@ -96,8 +92,8 @@ try {
},
onerror: function () {
var error = new Error('Google Docs request failed: ' +
'metadata lookup HTTP request failed');
var error = 'Google Docs request failed: ' +
'metadata lookup HTTP request failed';
error.reason = 'HTTP_ONERROR';
return cb(error);
}
@ -205,6 +201,7 @@ try {
unsafeWindow.console.log('Initialized userscript Google Drive player');
unsafeWindow.hasDriveUserscript = true;
unsafeWindow.driveUserscriptVersion = '1.2';
} catch (error) {
unsafeWindow.console.error(error);
}

View file

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.23.2",
"version": "3.23.3",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View file

@ -6,13 +6,14 @@ window.GoogleDrivePlayer = class GoogleDrivePlayer extends VideoJSPlayer
super(data)
load: (data) ->
window.maybePromptToUpgradeUserscript()
if typeof window.getGoogleDriveMetadata is 'function'
window.getGoogleDriveMetadata(data.id, (error, metadata) =>
if error
console.error(error)
alertBox = window.document.createElement('div')
alertBox.className = 'alert alert-danger'
alertBox.textContent = error.message
alertBox.textContent = error
document.getElementById('ytapiplayer').appendChild(alertBox)
else
data.meta.direct = metadata.videoMap

View file

@ -49,7 +49,7 @@ html(lang="en")
| Tampermonkey supports many browsers besides Chrome.
p.
Once you have installed the userscript manager addon for your browser,
you can <a href="/js/cytube-google-drive.user.js?v=1.1" target="_blank">
you can <a href="/js/cytube-google-drive.user.js" target="_blank">
install the userscript</a>. If this link 404s, it means the administrator
of this server hasn't generated it yet.
p.
@ -58,17 +58,3 @@ html(lang="en")
include footer
+footer()
script(type="text/javascript").
function showEmail(btn, email, key) {
email = unescape(email);
key = unescape(key);
var dest = new Array(email.length);
for (var i = 0; i < email.length; i++) {
dest[i] = String.fromCharCode(email.charCodeAt(i) ^ key.charCodeAt(i % key.length));
}
email = dest.join("");
$("<a/>").attr("href", "mailto:" + email)
.text(email)
.insertBefore(btn);
$(btn).remove();
}

View file

@ -679,6 +679,7 @@
}
GoogleDrivePlayer.prototype.load = function(data) {
window.maybePromptToUpgradeUserscript();
if (typeof window.getGoogleDriveMetadata === 'function') {
return window.getGoogleDriveMetadata(data.id, (function(_this) {
return function(error, metadata) {
@ -687,7 +688,7 @@
console.error(error);
alertBox = window.document.createElement('div');
alertBox.className = 'alert alert-danger';
alertBox.textContent = error.message;
alertBox.textContent = error;
return document.getElementById('ytapiplayer').appendChild(alertBox);
} else {
data.meta.direct = metadata.videoMap;
@ -1019,7 +1020,7 @@
};
TwitchPlayer.prototype.load = function(data) {
var error, error1;
var error;
this.setMediaProperties(data);
try {
if (data.type === 'tv') {
@ -1034,7 +1035,7 @@
};
TwitchPlayer.prototype.pause = function() {
var error, error1;
var error;
try {
this.twitch.pause();
return this.paused = true;
@ -1045,7 +1046,7 @@
};
TwitchPlayer.prototype.play = function() {
var error, error1;
var error;
try {
this.twitch.play();
return this.paused = false;
@ -1056,7 +1057,7 @@
};
TwitchPlayer.prototype.seekTo = function(time) {
var error, error1;
var error;
try {
return this.twitch.seek(time);
} catch (error1) {
@ -1066,7 +1067,7 @@
};
TwitchPlayer.prototype.getTime = function(cb) {
var error, error1;
var error;
try {
return cb(this.twitch.getCurrentTime());
} catch (error1) {
@ -1076,7 +1077,7 @@
};
TwitchPlayer.prototype.setVolume = function(volume) {
var error, error1;
var error;
try {
this.twitch.setVolume(volume);
if (volume > 0) {
@ -1089,7 +1090,7 @@
};
TwitchPlayer.prototype.getVolume = function(cb) {
var error, error1;
var error;
try {
if (this.twitch.isPaused()) {
return cb(0);
@ -1513,7 +1514,7 @@
};
window.loadMediaPlayer = function(data) {
var e, error, error1, error2, error3, error4;
var e, error;
try {
if (window.PLAYER) {
window.PLAYER.destroy();
@ -1525,8 +1526,8 @@
if (data.meta.direct && data.type !== 'gd') {
try {
return window.PLAYER = new VideoJSPlayer(data);
} catch (error2) {
e = error2;
} catch (error1) {
e = error1;
return console.error(e);
}
} else if (data.type === 'gd') {
@ -1536,15 +1537,15 @@
} else {
return window.PLAYER = new GoogleDriveYouTubePlayer(data);
}
} catch (error3) {
e = error3;
} catch (error1) {
e = error1;
return console.error(e);
}
} else if (data.type in TYPE_MAP) {
try {
return window.PLAYER = TYPE_MAP[data.type](data);
} catch (error4) {
e = error4;
} catch (error1) {
e = error1;
return console.error(e);
}
}

View file

@ -3205,3 +3205,54 @@ function stopQueueSpinner(data) {
$("#queueprogress").remove();
}
}
function maybePromptToUpgradeUserscript() {
if (document.getElementById('prompt-upgrade-drive-userscript')) {
return;
}
if (!window.hasDriveUserscript) {
return;
}
var currentVersion = [1, 2];
var userscriptVersion = window.driveUserscriptVersion;
if (!userscriptVersion) {
userscriptVersion = '1.0';
}
userscriptVersion = userscriptVersion.split('.').map(function (part) {
return parseInt(part, 10);
});
var older = false;
for (var i = 0; i < currentVersion.length; i++) {
if (userscriptVersion[i] < currentVersion[i]) {
older = true;
}
}
if (!older) {
return;
}
var alertBox = document.createElement('div');
alertBox.id = 'prompt-upgrade-drive-userscript';
alertBox.className = 'alert alert-info'
alertBox.innerHTML = 'A newer version of the Google Drive userscript is available.';
alertBox.appendChild(document.createElement('br'));
var infoLink = document.createElement('a');
infoLink.className = 'btn btn-info';
infoLink.href = '/google_drive_userscript';
infoLink.textContent = 'Click here for installation instructions';
infoLink.target = '_blank';
alertBox.appendChild(infoLink);
var closeButton = document.createElement('button');
closeButton.className = 'close pull-right';
closeButton.innerHTML = '&times;';
closeButton.onclick = function () {
alertBox.parentNode.removeChild(alertBox);
}
alertBox.insertBefore(closeButton, alertBox.firstChild)
document.getElementById('videowrap').appendChild(alertBox);
}