Drive userscript: support violentmonkey (#713)

This commit is contained in:
Calvin Montgomery 2017-11-27 22:42:50 -08:00
parent a260f79c7d
commit 342e5d406a
3 changed files with 21 additions and 14 deletions

View File

@ -8,17 +8,13 @@
// @grant GM.xmlHttpRequest // @grant GM.xmlHttpRequest
// @connect docs.google.com // @connect docs.google.com
// @run-at document-end // @run-at document-end
// @version 1.4.0 // @version 1.5.0
// ==/UserScript== // ==/UserScript==
try { try {
function debug(message) { function debug(message) {
if (!unsafeWindow.enableCyTubeGoogleDriveUserscriptDebug) {
return;
}
try { try {
unsafeWindow.console.log(message); unsafeWindow.console.log('[Drive]', message);
} catch (error) { } catch (error) {
unsafeWindow.console.error(error); unsafeWindow.console.error(error);
} }
@ -74,6 +70,14 @@ try {
onload: function (res) { onload: function (res) {
try { try {
debug('Got response ' + res.responseText); debug('Got response ' + res.responseText);
if (res.status !== 200) {
debug('Response status not 200: ' + res.status);
return cb(
'Google Drive request failed: HTTP ' + res.status
);
}
var data = {}; var data = {};
var error; var error;
res.responseText.split('&').forEach(function (kv) { res.responseText.split('&').forEach(function (kv) {
@ -82,13 +86,13 @@ try {
}); });
if (data.status === 'fail') { if (data.status === 'fail') {
var error = 'Google Docs request failed: ' + var error = 'Google Drive request failed: ' +
unescape(data.reason).replace(/\+/g, ' '); unescape(data.reason).replace(/\+/g, ' ');
return cb(error); return cb(error);
} }
if (!data.fmt_stream_map) { if (!data.fmt_stream_map) {
var error = 'Google Docs request failed: ' + var error = 'Google Drive request failed: ' +
'metadata lookup returned no valid links'; 'metadata lookup returned no valid links';
return cb(error); return cb(error);
} }
@ -107,7 +111,7 @@ try {
}, },
onerror: function () { onerror: function () {
var error = 'Google Docs request failed: ' + var error = 'Google Drive request failed: ' +
'metadata lookup HTTP request failed'; 'metadata lookup HTTP request failed';
error.reason = 'HTTP_ONERROR'; error.reason = 'HTTP_ONERROR';
return cb(error); return cb(error);
@ -197,9 +201,14 @@ try {
}, 1000); }, 1000);
} }
var TM_COMPATIBLES = [
'Tampermonkey',
'Violentmonkey' // https://github.com/calzoneman/sync/issues/713
];
function isRunningTampermonkey() { function isRunningTampermonkey() {
try { try {
return GM_info.scriptHandler === 'Tampermonkey'; return TM_COMPATIBLES.indexOf(GM_info.scriptHandler) >= 0;
} catch (error) { } catch (error) {
return false; return false;
} }
@ -216,7 +225,7 @@ try {
unsafeWindow.console.log('Initialized userscript Google Drive player'); unsafeWindow.console.log('Initialized userscript Google Drive player');
unsafeWindow.hasDriveUserscript = true; unsafeWindow.hasDriveUserscript = true;
unsafeWindow.driveUserscriptVersion = '1.4'; unsafeWindow.driveUserscriptVersion = '1.5';
} catch (error) { } catch (error) {
unsafeWindow.console.error(error); unsafeWindow.console.error(error);
} }

View File

@ -233,5 +233,3 @@ function eraseCookie(name) {
/* to be implemented in callbacks.js */ /* to be implemented in callbacks.js */
function setupCallbacks() { } function setupCallbacks() { }
window.enableCyTubeGoogleDriveUserscriptDebug = getOrDefault("cytube_drive_debug", false);

View File

@ -3247,7 +3247,7 @@ function maybePromptToUpgradeUserscript() {
return; return;
} }
var currentVersion = [1, 4]; var currentVersion = [1, 5];
var userscriptVersion = window.driveUserscriptVersion; var userscriptVersion = window.driveUserscriptVersion;
if (!userscriptVersion) { if (!userscriptVersion) {
userscriptVersion = '1.0'; userscriptVersion = '1.0';