Skip to content

Commit

Permalink
Merge pull request #935 from suwacrab/master
Browse files Browse the repository at this point in the history
downloader template for gifs
  • Loading branch information
dimdenGD authored Sep 8, 2024
2 parents 6bde627 + 621bc6f commit cca9893
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion scripts/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('.'))

This comment has been minimized.

Copy link
@vampiricwulf

vampiricwulf Oct 11, 2024

ReferenceError: url is not defined

};
filename = filename_template.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]);
}
a.download = filename;

document.body.append(a);
a.click();
a.remove();
Expand Down

0 comments on commit cca9893

Please sign in to comment.