User talk:Writ Keeper/Scripts/massRollback.js
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.
var regexResults = /token=([^&]+)/.exec(this.href) if(typeof regexResults[1] == "undefined")
If exec() fails to match the string, it returns
null
, in which caseregexResults[1]
will raise aTypeError
. You probably want something like this:Ifif (regexResults === null) return false;
regexResults
is not null, and because the regex contains an unconditional group, it will always have at least two valid elements.- 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); // ...
- The
exec()
in thepostInfo.title
property can fail, in which case you also end up with aTypeError
because you're subscripting anull
. I also suggest precompiling it outside of the callback. - You are missing a lot of semicolons. Although JavaScript has an automatic semicolon insertion "feature", its use is usually not recommended.
$(selector).each()
executes the callback in the context of the element and passes the element as the second parameter of the callback. In this caseel
andthis
refer to the same object. You should use one or the other for consistency.- 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)
- 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)
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)
- 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)
- Script is missing semicolon at line 129 according to an automated testing tool. Hence I guess the Shift problem. — kashmīrī TALK 13:50, 23 July 2023 (UTC)
- No, semicolons are optional in Javascript (or rather, the Javascript engine will insert a missing semicolon for you). Not sure why it wouldn't be working for y'all; seems to work all right for me. I'll take a look. Writ Keeper ⚇♔ 14:42, 23 July 2023 (UTC)
- Shift still isn't working for me. — kashmīrī TALK 14:58, 23 July 2023 (UTC)
- Thanks for these posts! By the way, do you use script-installer? I would have not seen this update if I hadn't added the sourcepage to my watchlist. It seems as though it does not notify on script updates? Top5a (talk) 14:31, 26 July 2023 (UTC)
- Shift still isn't working for me. — kashmīrī TALK 14:58, 23 July 2023 (UTC)
- No, semicolons are optional in Javascript (or rather, the Javascript engine will insert a missing semicolon for you). Not sure why it wouldn't be working for y'all; seems to work all right for me. I'll take a look. Writ Keeper ⚇♔ 14:42, 23 July 2023 (UTC)