Update improved_redgifs.user.js

Added check to make sure the token is valid. If not, refresh token.
This commit is contained in:
2025-12-22 01:28:00 -07:00
parent e4eea9baec
commit 06d85089ea
+10 -7
View File
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Improved RedGIFs
// @namespace BigDuckie.ImprovedRedgifs
// @version 2025.12.21
// @version 2025.12.22
// @description Fix a few annoying "features" and add an easy download button.
// @icon https://www.google.com/s2/favicons?sz=64&domain=redgifs.com
// @author Big Duckie
@@ -10,6 +10,7 @@
// @match https://*.redgifs.com/
// @match https://*.redgifs.com/watch/*
// @match https://*.redgifs.com/niches/*
// @match https://*.redgifs.com/users/*
// @match https://*.redgifs.com/ifr/*
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js
// @require https://raw.githubusercontent.com/pie6k/jquery.initialize/master/jquery.initialize.min.js
@@ -28,10 +29,6 @@
font: var(--s1-medium);
text-shadow: var(--black) 1px 0 5px;
text-align: center;
}
.embeddedPlayer .buttons .button svg {
margin-left: 3px;
}`);
jQuery.noConflict();
@@ -193,8 +190,14 @@
}
async function download(id) {
let token = await getToken()
let gif = await (await fetch(`https://api.redgifs.com/v2/gifs/${id}`, { headers: { Authorization: `Bearer ${token}` } })).json()
let token = await getToken();
let resp = await fetch(`https://api.redgifs.com/v2/gifs/${id}`, { headers: { Authorization: `Bearer ${token}` } });
if (!resp.ok) {
localStorage.removeItem("userscript_access_token");
await download(id);
return
}
let gif = await resp.json();
let url = gif.gif.urls.hd;
GM_download(url, url.split("/").pop().split("?")[0]);
}