downthemall / anticontainer

DownThemAll! AntiContainer (Extension to a Firefox, Seamonkey extension)
Mozilla Public License 2.0
93 stars 41 forks source link

Expanders break when using "namer" tag - Solution provided #95

Closed MegaScience closed 9 years ago

MegaScience commented 9 years ago

I have been attempting to create an anti-container plugin for Twitter, but ran into an odd issue. I had originally created a Resolver back when Twitter only provided one image per Tweet, and I tried converting this into an Expander format so I could locate all images in the new arrangement. While my Resolver still works - with the disadvantage of only finding the first image - the Expander refused to function whenever I had the "namer" tag defined. As large Twitter images are amended with ":large" at the end, generated names end in "_large", which is problematic, so I require "namer" to correct this.

After looking through the github, I discovered the issue. Under the command run for Expanders, the line setting "name" does not end in a semi-colon ( ; ). This causes the script to break and, as this is within a "while" loop, lock up until the DownThemAll times out the download. Luckily it appears in this language, the "if" statement isolates this mistake, so it only effects anyone attempting a custom filename. Here is the code in question, via anticontainer/content/manager.js:

do {
    try {
        log(LOG_DEBUG, m + " " + urlMatch);
        let name = null;
        let url = this.generateReplacement(obj.generator, m, urlMatch);
        if ("namer" in obj) {
            name = this.generateReplacement(obj.namer, m, urlMatch)
        }
        this.queueDownload(url, name);
    }
    catch (ex) {
        log(LOG_ERROR, "dtaac::generator.replace", ex);
    }
}
while ((m = obj.finder.exec(this.responseText)) != null);

Whenever a "namer" tag is provided for an Expander, this issue will occur. As such, I propose a simple update to fix this. Please and thank you. :)