From 4c981dd4744d7894a4054b9eed930a80749936f4 Mon Sep 17 00:00:00 2001 From: "U-FEEL\\suwa" Date: Sun, 8 Sep 2024 12:02:22 -0700 Subject: [PATCH 1/2] downloader template for gifs --- scripts/helpers.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scripts/helpers.js b/scripts/helpers.js index 842de21b..fe0bc5c2 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -3667,7 +3667,28 @@ async function appendTweet(t, timelineContainer, options = {}) { mde.innerText = ''; let a = document.createElement('a'); a.href = URL.createObjectURL(blob); - a.download = `${t.id_str}.gif`; + + let ts = new Date(t.created_at).toISOString().split("T")[0]; + let extension = 'gif' + let _index = t.extended_entities.media.length > 1 ? "_"+(index+1) : ""; + let filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; + let filename_template = vars.customDownloadTemplate; + + // use the filename from the user's custom download template, if any + if(filename_template && (filename_template.length > 0)) { + const filesave_map = { + "user_screen_name": t.user.screen_name, + "user_name": t.user.name, + "extension": extension, + "timestamp": ts, + "id": t.id_str, + "index": _index, + "filename": url.pathname.substring(url.pathname.lastIndexOf('/') + 1, url.pathname.lastIndexOf('.')) + }; + filename = filename_template.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]); + } + a.download = filename; + document.body.append(a); a.click(); a.remove(); From 621bc6f48f1c4cd0e6269b98bfe4b11c757e7f7a Mon Sep 17 00:00:00 2001 From: "U-FEEL\\suwa" Date: Sun, 8 Sep 2024 12:17:48 -0700 Subject: [PATCH 2/2] oops --- scripts/helpers.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/scripts/helpers.js b/scripts/helpers.js index fe0bc5c2..99e90dab 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -3668,26 +3668,26 @@ async function appendTweet(t, timelineContainer, options = {}) { let a = document.createElement('a'); a.href = URL.createObjectURL(blob); - let ts = new Date(t.created_at).toISOString().split("T")[0]; - let extension = 'gif' - let _index = t.extended_entities.media.length > 1 ? "_"+(index+1) : ""; - let filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; - let filename_template = vars.customDownloadTemplate; - - // use the filename from the user's custom download template, if any - if(filename_template && (filename_template.length > 0)) { - const filesave_map = { - "user_screen_name": t.user.screen_name, - "user_name": t.user.name, - "extension": extension, - "timestamp": ts, - "id": t.id_str, - "index": _index, - "filename": url.pathname.substring(url.pathname.lastIndexOf('/') + 1, url.pathname.lastIndexOf('.')) - }; - filename = filename_template.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]); - } - a.download = filename; + let ts = new Date(t.created_at).toISOString().split("T")[0]; + let extension = 'gif' + let _index = t.extended_entities.media.length > 1 ? "_"+(index+1) : ""; + let filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; + let filename_template = vars.customDownloadTemplate; + + // use the filename from the user's custom download template, if any + if(filename_template && (filename_template.length > 0)) { + const filesave_map = { + "user_screen_name": t.user.screen_name, + "user_name": t.user.name, + "extension": extension, + "timestamp": ts, + "id": t.id_str, + "index": _index, + "filename": url.pathname.substring(url.pathname.lastIndexOf('/') + 1, url.pathname.lastIndexOf('.')) + }; + filename = filename_template.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]); + } + a.download = filename; document.body.append(a); a.click();