Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

downloader template for gifs #935

Merged
merged 2 commits into from
Sep 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('.'))
};
filename = filename_template.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]);
}
a.download = filename;

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