mirror of
https://github.com/Alvin-Zilverstand/return-youtube-dislike.git
synced 2026-11-27 08:37:49 +01:00
Add Greasemonkey compatibility
Greasemonkey in Firefox doesn't have the GM_xmlhttpRequest function, so the script breaks when it tries to call the function. This adds a check before falling back to Greasemonkey's GM.xmlHttpRequest() if available.
This commit is contained in:
1 file changed
+13
-1
@@ -14,12 +14,24 @@
|
|||||||
// @downloadURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
// @downloadURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
||||||
// @updateURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
// @updateURL https://github.com/Anarios/return-youtube-dislike/raw/main/Extensions/UserScript/Return%20Youtube%20Dislike.user.js
|
||||||
// @grant GM_xmlhttpRequest
|
// @grant GM_xmlhttpRequest
|
||||||
|
// @grant GM.xmlHttpRequest
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
function cLog(text, subtext = '') {
|
function cLog(text, subtext = '') {
|
||||||
subtext = subtext.trim() === '' ? '' : `(${subtext})`;
|
subtext = subtext.trim() === '' ? '' : `(${subtext})`;
|
||||||
console.log(`[Return Youtube Dislikes] ${text} ${subtext}`);
|
console.log(`[Return Youtube Dislikes] ${text} ${subtext}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function doXHR(opts) {
|
||||||
|
if (typeof GM_xmlhttpRequest === 'function') {
|
||||||
|
return GM_xmlhttpRequest(opts);
|
||||||
|
}
|
||||||
|
if (typeof GM.xmlHttpRequest === 'function') {
|
||||||
|
return GM.xmlHttpRequest(opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error('Unable to detect UserScript plugin.');
|
||||||
|
}
|
||||||
|
|
||||||
function getButtons() {
|
function getButtons() {
|
||||||
return document
|
return document
|
||||||
.getElementById("menu-container")
|
.getElementById("menu-container")
|
||||||
@@ -72,7 +84,7 @@ function setDislikes(dislikesCount) {
|
|||||||
function setState() {
|
function setState() {
|
||||||
cLog('Fetching votes...');
|
cLog('Fetching votes...');
|
||||||
|
|
||||||
GM_xmlhttpRequest({
|
doXHR({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
responseType: "json",
|
responseType: "json",
|
||||||
url:
|
url:
|
||||||
|
|||||||
Reference in new issue
Block a user