Replace gm4 polyfill

This commit is contained in:
Calvin Montgomery 2017-11-20 18:00:45 -08:00
parent 85169fbb56
commit a260f79c7d
1 changed files with 12 additions and 5 deletions

View File

@ -3,7 +3,6 @@
// @namespace gdcytube
// @description Play Google Drive videos on {SITENAME}
// {INCLUDE_BLOCK}
// @require https://greasemonkey.github.io/gm4-polyfill/gm4-polyfill.js
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest
@ -25,6 +24,17 @@ try {
}
}
function httpRequest(opts) {
if (typeof GM_xmlhttpRequest === 'undefined') {
// Assume GM4.0
debug('Using GM4.0 GM.xmlHttpRequest');
GM.xmlHttpRequest(opts);
} else {
debug('Using old-style GM_xmlhttpRequest');
GM_xmlhttpRequest(opts);
}
}
var ITAG_QMAP = {
37: 1080,
46: 1080,
@ -58,7 +68,7 @@ try {
+ '&hl=en';
debug('Fetching ' + url);
GM.xmlHttpRequest({
httpRequest({
method: 'GET',
url: url,
onload: function (res) {
@ -102,9 +112,6 @@ try {
error.reason = 'HTTP_ONERROR';
return cb(error);
}
}).catch(function (error) {
error.reason = 'GM.xmlHttpRequest error';
return cb(error);
});
}