Skip to content

Commit

Permalink
Support caption format variable for image alt tags
Browse files Browse the repository at this point in the history
  • Loading branch information
qsniyg committed Jan 30, 2025
1 parent 9e36ccb commit f495cf1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ New features:
Improvements:

* Various improvements/fixes to existing rules (including Flickr, Twitch, Reddit)
* Fill `caption` format variable for image alt tags (thanks to Dietz on discord for reporting)

Bugfixes:

* Fix backslash escapes breaking parsing for format strings

Special thanks to arlenestrigger, fyhtma, BlindWanda, chr1sx, James Joint, musicianjam888, Velocidensity, Egor Popov, Froktime, siloricity, Gooberpatrol66 for their contributions and reports for this release
Special thanks to arlenestrigger, fyhtma, BlindWanda, chr1sx, James Joint, musicianjam888, Velocidensity, Egor Popov, Froktime, siloricity, Gooberpatrol66, Dietz for their contributions and reports for this release

---

Expand Down
13 changes: 9 additions & 4 deletions src/userscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130126,7 +130126,7 @@ var $$IMU_EXPORT$$;
return null;
};

var fill_obj_filename = function(newobj, url, respdata) {
var fill_obj_filename = function(newobj, url, respdata, popup_el) {
if (typeof newobj.filename !== "string")
newobj.filename = "";

Expand Down Expand Up @@ -130237,7 +130237,7 @@ var $$IMU_EXPORT$$;
// to avoid formatting the filename multiple times
if (!("_orig_filename" in newobj)) newobj._orig_filename = orig_filename;

var format_vars = {
var format_vars:any = {
filename: newobj._orig_filename
};

Expand Down Expand Up @@ -130347,6 +130347,11 @@ var $$IMU_EXPORT$$;
format_vars.ext = "." + wanted_ext;
}

// thanks to Dietz on discord for reporting:
if (!format_vars.caption && popup_el) {
format_vars.caption = get_caption(newobj, popup_el);
}

newobj.format_vars = shallowcopy(format_vars);

var new_filename = get_filename_from_format(settings.filename_format, format_vars);
Expand Down Expand Up @@ -130419,7 +130424,7 @@ var $$IMU_EXPORT$$;
if (resp.finalUrl)
theobj.url = resp.finalUrl;

fill_obj_filename(theobj, theobj.url, resp);
fill_obj_filename(theobj, theobj.url, resp, popup_el);
popup_obj = theobj;

if (openb === "newtab" || openb === "newtab_bg") {
Expand Down Expand Up @@ -132100,7 +132105,7 @@ var $$IMU_EXPORT$$;

popup_createui_func = create_ui;

fill_obj_filename(newobj, url, data.data.respdata);
fill_obj_filename(newobj, url, data.data.respdata, popup_el);

create_ui();

Expand Down
10 changes: 7 additions & 3 deletions userscript.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -116089,7 +116089,7 @@ var $$IMU_EXPORT$$;
}
return null;
};
var fill_obj_filename = function(newobj, url, respdata) {
var fill_obj_filename = function(newobj, url, respdata, popup_el) {
if (typeof newobj.filename !== "string")
newobj.filename = "";
var modified_date = null;
Expand Down Expand Up @@ -116273,6 +116273,10 @@ var $$IMU_EXPORT$$;
if (wanted_ext)
format_vars.ext = "." + wanted_ext;
}
// thanks to Dietz on discord for reporting:
if (!format_vars.caption && popup_el) {
format_vars.caption = get_caption(newobj, popup_el);
}
newobj.format_vars = shallowcopy(format_vars);
var new_filename = get_filename_from_format(settings.filename_format, format_vars);
if (new_filename) {
Expand Down Expand Up @@ -116328,7 +116332,7 @@ var $$IMU_EXPORT$$;
var resp = data.data.resp || data.data.respdata;
if (resp.finalUrl)
theobj.url = resp.finalUrl;
fill_obj_filename(theobj, theobj.url, resp);
fill_obj_filename(theobj, theobj.url, resp, popup_el);
popup_obj = theobj;
if (openb === "newtab" || openb === "newtab_bg") {
open_in_tab_imu(theobj, openb === "newtab_bg");
Expand Down Expand Up @@ -117705,7 +117709,7 @@ var $$IMU_EXPORT$$;
add_leftright_gallery_button_if_valid(true);
}
popup_createui_func = create_ui;
fill_obj_filename(newobj, url, data.data.respdata);
fill_obj_filename(newobj, url, data.data.respdata, popup_el);
create_ui();
var a = document_createElement("a");
set_el_all_initial(a);
Expand Down

0 comments on commit f495cf1

Please sign in to comment.