Jump to content

User talk:Writ Keeper/Scripts/massRollback.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Bugs and some recommendations

[edit]

I was browsing ANI when the "400 tabs" caught my eye and landed me here. Tell me if I'm being obnoxious and I shall merrily go away.

  1. var regexResults = /token=([^&]+)/.exec(this.href)
    if(typeof regexResults[1] == "undefined")
    

    If exec() fails to match the string, it returns null, in which case regexResults[1] will raise a TypeError. You probably want something like this:

    if (regexResults === null)
        return false;
    
    If regexResults is not null, and because the regex contains an unconditional group, it will always have at least two valid elements.


  2. Although the regex is simple, it may be more efficient to create it once outside of the callback and reuse it instead of compiling it for each element:
    var r = /token=([^&]+)/;
    
    $("a[href*='action=rollback']").each(function(ind, el)
    {
        var regexResults = r.exec(this.href);
        // ...
    

  3. The exec() in the postInfo.title property can fail, in which case you also end up with a TypeError because you're subscripting a null. I also suggest precompiling it outside of the callback.


  4. You are missing a lot of semicolons. Although JavaScript has an automatic semicolon insertion "feature", its use is usually not recommended.


  5. $(selector).each() executes the callback in the context of the element and passes the element as the second parameter of the callback. In this case el and this refer to the same object. You should use one or the other for consistency.


  6. Various style issues: inconsistent positioning of curly brackets (some on a new line, others not), inconsistent whitespace, long lines, mix of == and ===, etc. It matters little which style you use, as long as it is used consistently.

I understand you inherited this code from someone else, that this is a short and quick script, that you have better things to do and that I'm meddling with things that don't concern me. I will gladly accept indifference and insults. Isa (talk) 16:08, 29 July 2015 (UTC)[reply]

Indifference, maybe (like I said, it was 100% laziness that I never fixed the 4000 tabs issue to begin with), but never insults. I'll look at it again later. Writ Keeper  16:36, 29 July 2015 (UTC)[reply]

Quick Feedback Items/Suggestions

[edit]

Hello! Cool tool!

1.) For some reason, I am not able to shift click autofill between the checkboxes. Do you have this issue? (I have to manually click each box).

2.) Though I can visually see when rollbacks are successful, perhaps you should detect if the number of successes matches the number of boxes checked, and provide a popup at the end. Perhaps a popup regardless of the result, with a message stating that the operation was successfully completed with the number of rollbacks, or that out of X number of attempted rollbacks, only Y were successfully completed. Even better to state which ones were not successful. Just a thought!

Anyway, thanks for your contributions, this tool is very helpful. Top5a (talk) 08:18, 23 March 2023 (UTC)[reply]

I'm also seeing the issue no. 1.
Additionally, the script seems to roll back only the initial ~50 contributions, even when ~150 are displayed. I had to repeat rollback many times in order to complete the task. — kashmīrī TALK 13:40, 23 July 2023 (UTC)[reply]