Wikipedia talk:WikiProject JavaScript: Difference between revisions

Content deleted Content added
Notifying WikiProject of move discussion on Talk:GNOME
 
(198 intermediate revisions by 47 users not shown)
Line 1:
{{Talk header |shortcut=WT:JS }}
{{WikiProject banner shell|
{{WikiProject JavaScript}}
}}
 
{{archive box}}
== User script: [[User:The Transhumanist/anno.js]] ==
 
This script makes the annotations of bullet list entries disappear and reappear with the click of a toggle, or the press of a hot key.
 
But, it has a problem. When material above the reader's current position on the page is removed, it displaces the reader from what he was reading. The text shifts up relative to the viewport and may even go off the screen.
 
If you know how to adjust the positioning of the viewport, please let me know.
 
Thank you. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 06:49, 6 April 2017 (UTC)
 
== User script: [[User:The Transhumanist/OLUtils.js]] ==
 
This is going to have a bunch of features optimized for working on outlines.
 
It's first and only feature at this time is a redlink remover. I've adapted a pre-existing script and added a section for removing redlinked list entries from outlines, which is currently in the testing and bug-fixing phase. It doesn't work yet, but I'm hopeful.
 
I'm in the process of documenting the code liberally with comments, and with extensive explanatory notes on the [[User talk:The Transhumanist/OLUtils.js|script's talk page]]. Commentary and questions are welcome! [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 01:10, 14 April 2017 (UTC)
 
== What scripts are you working on or maintaining, or would like to build? ==
 
Feel free to share the details of your user script projects, your problems, your ideas, and your JavaScript-related technological fantasies hereon this page. :) [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 01:10, 14 April 2017 (UTC)
 
== Looking for a userscript demonstrating a function ==
== [[:Yeoman (computing)]] listed at Requested moves==
[[File:Information.svg|30px|left]]A [[Wikipedia:Requested moves|requested move]] discussion has been initiated for [[:Yeoman (computing)]] to be moved to [[Yeoman (software)]]. This page is of interest to this WikiProject and interested members may want to participate in the discussion [[Talk:Yeoman (computing)#Requested move 4 May 2017 |here]].<!-- Talk:Yeoman (computing)#Requested move 4 May 2017 crosspost --> —[[User:RMCD bot|RMCD bot]] 18:32, 4 May 2017 (UTC)
:<small>To opt out of RM notifications on this page, transclude {{tlp|bots|2=deny=RMCD bot}}, or set up [[Wikipedia:Article alerts|Article alerts]] for this WikiProject.</small>
 
I'm looking to build a userscript the interacts with a template call, and I was hoping that there's another one out there that I can see how this functionality works. Specifically, I want the userscript to do the following:
== Nested RegExp ==
# Scan a page on load for a particular template call.
# Insert a button for openning up a javascript window if the template is found, preferably at the template's ___location on the page.
# Load template parameters into fields in the new javascript window.
Does anyone know of a userscript that does something like this, or a set of userscripts that together do all of these functions? Am I completely crazy thinking this is even possible? It's been about 20 years since I last programmed anything in javascript, so I'm very much looking for a place to start connecting the dots again. Thanks for any help you have. [[User:Vanisaac|Van]][[User talk:Vanisaac|Isaac]]<sub><small>[[WP:WikiProject Writing systems|WS]]</small></sub><sup style="margin-left:-3.0ex">[[Special:Contributions/Vanisaac|cont]]</sup> 18:28, 24 June 2020 (UTC)
:For looking for a template call within wikitext, and finding the parameters and their values, you can use the {{tt|parseTemplates}} function of [[MediaWiki:Gadget-libExtraUtil.js]] (which is a gadget, so can be loading using [[mw:ResourceLoader/Core modules|ResourceLoader]]'s {{tt|mw.loader.using}}). Actually finding the parsed html of the template within the page's html is going to be more tricky, and may not be possible, e.g. if the template output is indistinguishable from regular wikitext, such as {{tl|ndash}} or other formatting templates. - <u>'''[[User:Evad37|Evad]]''37'''''</u>&nbsp;<span style="font-size:95%;">&#91;[[d:w:User talk:Evad37|talk]]]</span> 03:24, 25 June 2020 (UTC)
:I've wanted a user script that finds and highlights occurrences of a given template for a while – extending such a user script to meet your specification wouldn't be that hard. Both scripts are completely feasible with Parsoid. However, from my [[User:Enterprisey/reply-link|past experience]], I know they'll probably be pretty annoying/difficult to write, so I haven't written anything yet. I'd be happy to give advice or an outline of how to proceed to anyone who wants it, though. [[User:Enterprisey|Enterprisey]]&nbsp;([[User talk:Enterprisey|talk!]]) 06:42, 25 June 2020 (UTC)
::It's certainly fine to have this script parse wikitext only while editing if that makes things easier. But since the script is only useful interacting with a few specific templates, it's completely reasonable to just program the templates with custom HTML classes for the script data. I would assume that would vastly simplify extracting those values. [[User:Vanisaac|Van]][[User talk:Vanisaac|Isaac]]<sub><small>[[WP:WikiProject Writing systems|WS]]</small></sub><sup style="margin-left:-3.0ex">[[Special:Contributions/Vanisaac|cont]]</sup> 18:04, 25 June 2020 (UTC)
 
A little late, but is it supposed to scroll down to where the template is and open up a screen, then load the parameters? <div style="background-color: #fef1d5;width:200px;font-size:1.25em;">[[User:SikiWtideI|'''SikiWtideI's user page''']]<div style="clear:both;"></div> [[User talk:SikiWtideI|<sup>'''Talk'''<sub>to the backwards police</sub></sup>]] </div> 00:37, 15 January 2023 (UTC)
I'm working on a script ([[User:The Transhumanist/OLUtils.js]]) to remove redlinks from outlines, and I've run into a problem with regular expressions:
 
== Calling for volunteers for [[WP:RedWarn|RedWarn]] - a fast growing new JavaScript counter-vandalism tool ==
<syntaxhighlight lang="javascript">
{{Wikipedia:RedWarn/Volunteer}}
1 var nodeScoop2 = new RegExp('('+RegExp.quote(redlinks[i])+')','i');
- [[User:Ed6767|<span style="font-family:'Roboto',sans-serif;font-weight:300;text-shadow: 2px 2px 10px black;color:black;">Ed<span style="color:red;">6767</span></span>]] [[User talk:Ed6767|<span style="color:black;"><strong>talk!</strong></span>]] 15:09, 15 July 2020 (UTC)
2 var matchString2 = wpTextbox1.value.match(nodeScoop2);
3 alert(matchString2);
</syntaxhighlight>
 
== OneClickUnarchiver ==
The above returns two matches, when I was expecting one. The second one is coming from the nested RegExp constructor.
 
It's not uncommon to need to restore a discussion from a talk venue archive, but it's not easy to do it correctly and exceeds the ability of many editors. I wonder if anyone would be interested in creating a restore-from-archive script modeled after [[Wikipedia:One click archiving|OneClickArchiver]]. Instead of clicking an "Archive" link on a talk page, one would click a "Restore" link on an archive page. The coding would be a little simpler than OneClickArchiver, which has to worry about whether it's time to create a new archive page. Any taker? ―[[User:Mandruss|<span style="color:#775C57;">'''''Mandruss'''''</span>]]&nbsp;[[User talk:Mandruss|<span style="color:#888;">&#9742;</span>]] 22:08, 27 November 2020 (UTC)
Is there another way to specify a variable within a regular expression? If so, what?
 
== Proposal to change the user scripts header message ==
Also, I can't find any documentation on the plus signs as used here. Can you explain them, or point me to an explanation?
 
The [[Mediawiki:Clearyourcache]] message should link "scripts" to [[WP:US]]. I made a proposal at [[Template talk:Script doc auto#Proposal: link to WP:US]]. [[User:Enterprisey|Enterprisey]]&nbsp;([[User talk:Enterprisey|talk!]]) 21:50, 13 December 2020 (UTC)
What would the RegExp look like in literal notation?
:So I did this, and then out of curiosity looked at the pageviews stats for WP:US. Looks like they went from 60-80ish daily earlier this year, and then plunged at the beginning of May to 20-40ish daily, where they remain. Did it get de-linked from somewhere big? (pinging people from the discussion at TT:Script doc auto, who definitely didn't ask to get pinged but I figure might still be interested: {{ping|Sj|SD0001|DannyS712|prefix=|p=}}) [[User:Enterprisey|Enterprisey]]&nbsp;([[User talk:Enterprisey|talk!]]) 09:25, 19 December 2020 (UTC)
:: Interesting. Can't think of a reason... <span style="color:#666">&ndash;&nbsp;[[User:Sj|SJ]][[User Talk:Sj|<span style="color:#f90;">&nbsp;+</span>]]</span> 03:12, 24 December 2020 (UTC)
 
== Moving snippets to user space ==
Thank you. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 11:07, 5 May 2017 (UTC)
:This is the way Twinkle specifies variables in a regular expression; to my knowledge it's the only way to do it. The plus signs are acting as string concatenation operators [https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators#Addition_() (string + string = concatenation)]. And you couldn't express this in literal notation, because literal notation can't accept variables (it is literal after all).
:As an example of using <code>new RegExp</code>, this regexp in literal notation: <code>/^Hello\s+/gi</code> is entirely equivalent to <code>new RegExp('^Hello\\s+', 'gi')</code>. Note the double escaping! This is because character escapes in regular expression are processed separately from character escapes in strings.
:As to why it is returning two matches instead of one, I really couldn't tell you. Could you provide a simplified test case or example? — <span style="border:dashed #666;border-width:1px 0 0 1px">[[User:This, that and the other|This, that]]</span> and <span style="border:dashed #666;border-width:0 1px 1px 0">[[User talk:This, that and the other|the other<small> (talk)</small>]]</span> 12:40, 5 May 2017 (UTC)
:: {{ping|This, that and the other}} Thank you for the explanation. In answer to your question, "yes". Run the script [[User:The Transhumanist/OLUtils.js]] on any article with "Outline of" in the title, and that has red links in it, and the alerts will show you. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 15:35, 5 May 2017 (UTC)
 
Hi there! I am going to suggest moving [[Wikipedia:User scripts#Snippets|these user script "snippets"]] formerly managed by WikiProject User scripts to be migrated to user space. This brings multiple advantages, but mainly improves security (they would be interface-admin protected essentially), and readability / ease-of-use (the pages that are not currently marked as JS in terms of content model would be able to be installed using scripts like scriptinstaller). [[User:EpicPupper|🐶 EpicPupper]] <sup>(he/him &#124; [[User talk:EpicPupper|talk]])</sup> 19:13, 13 March 2022 (UTC)
:{{ec}}{{Reply to|The Transhumanist}} It's difficult to quickly assess exactly what's going on without seeing the data it's being run against and the matches you are seeing. Is it possible that there's actually multiple matches in the input text? E.g. if you look for "apple" in "apple, orange, pineapple", two matches is the expected result. You would need to look for "\bapple\b" to restrict both ends to word boundaries, but that would still give multiple matches against "red apple, green apple, orange". There is nothing about that code snippet which suggests that multiple matches should be unexpected behaviour.
:I think your problem here is that you need to deal with the text before and after the thing the regexp is supposed to match. Looking at Alex's original script, I believe you need to use something like his original regular expressions, as it looks like they already deal with the beginning and end of the string. I don't see why you appear to be reinventing the wheel here, as it looks like Alex's script already deals with that issue.
:As for "plus signs as used here", do you mean the string concatenation operators? If you don't recognise basic JS operators and string concatenation, I suggest that you may need to learn fundamental JS programming before continuing. Try the tutorials and guides at https://developer.mozilla.org/en-US/docs/Web/JavaScript.
:Literal notation? If you feed "apple" into the above snipped, via the "redlinks" array, you'd get the equivalent of <code>/(apple)/i</code>. That's very basic stuff, so you should probably be doing some reading on Mozilla's MDN site (or some other JS learning resource).
:[[User:Murph9000|<span style="color:white;background-color:purple;padding:0.1em 0.1em 0.1em 1em;">Murph</span><span style="color:white;background-color:black;padding:0.1em 1em 0.1em 0.1em;">9000</span>]] ([[User talk:Murph9000|talk]]) 12:55, 5 May 2017 (UTC)
:: {{ping|Murph9000}} Thank you for the input. I've been having much difficulty with this script. The answer is "no" on the multiple matches. The original statement was
::<syntaxhighlight lang="javascript">
var nodeScoop2 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i])+')\\s*\\]\\]','i');
</syntaxhighlight>
::which for example returns <nowiki>[[Geography of France]]</nowiki>, Geography of France
::So I figure it's the nested RegExp that is the second match. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 15:33, 5 May 2017 (UTC)
:::Ok, now it's clearer exactly what you are talking about. This is expected behaviour, it's standard regexp group stuff as Syockit explained below. Don't use the term "nested RegExp" like that, as that's not what it is and that term just adds to the confusion here. [[User:Murph9000|<span style="color:white;background-color:purple;padding:0.1em 0.1em 0.1em 1em;">Murph</span><span style="color:white;background-color:black;padding:0.1em 1em 0.1em 0.1em;">9000</span>]] ([[User talk:Murph9000|talk]]) 20:50, 5 May 2017 (UTC)
 
==Help: IllWill.js==
:The parentheses creates a [https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references capturing group]. The first match is the whole matched string, while the second one is the captured group. Try with <code>RegExp(RegExp.quote(redlinks[i]),'i')</code> and see if it works. [[User:Syockit|Syockit]] ([[User talk:Syockit|talk]]) 12:57, 5 May 2017 (UTC)
There is a problem with the behaviour of [[User:Cobaltcigs]]'s [[User:Cobaltcigs/IllWill.js|IllWill.js]]: If I fill in the edit summary as I go along editing an article, and then invoke that script, it overwrites my edit summary with its own. I'm no expert in JavaScript, but it occurs to me that changing in line 162 the operator <code>=</code> to <code>+=</code> would fix that. Then again, it might need more elaborate coding. I [[Special:diff/1235258054|left a message]] on the user's talk page, but he hasn't edited for some months, so I would appreciate it if someone here could fix this. -- [[User:Michael Bednarek|Michael Bednarek]] ([[User talk:Michael Bednarek|talk]]) 07:11, 31 July 2024 (UTC)
 
== [[:React (JavaScript library)]] listed at Requested moves==
Wow. It's been many moons since anyone has asked me for JS help- I thought I'd become just a mostly-faded memory for a few editors. With that being said, [[User:Syockit|Syockit]] is right as far as I can tell in that the parentheses create a capturing group. I'm not entirely sure why they're there at all- I'd use the same nodeScoop2 you currently have without the parentheses around the RegExp.quote; i.e. try:
[[File:Information.svg|30px|left]]A [[Wikipedia:Requested moves|requested move]] discussion has been initiated for [[:React (JavaScript library)]] to be moved to [[React (software)]]. This page is of interest to this WikiProject and interested members may want to participate in the discussion [[Talk:React (JavaScript library)#Requested move 8 November 2024|here]].<!-- Talk:React (JavaScript library)#Requested move 8 November 2024 crosspost --> —[[User:RMCD bot|RMCD bot]] 03:50, 8 November 2024 (UTC)
:<small>To opt out of RM notifications on this page, transclude {{tlp|bots|2=deny=RMCD bot}}, or set up [[Wikipedia:Article alerts|Article alerts]] for this WikiProject.</small>
 
== [[:A-Frame (virtual reality framework)]] listed at Requested moves==
<syntaxhighlight lang="javascript">
[[File:Information.svg|30px|left]]A [[Wikipedia:Requested moves|requested move]] discussion has been initiated for [[:A-Frame (virtual reality framework)]] to be moved to [[A-Frame (extended reality framework)]]. This page is of interest to this WikiProject and interested members may want to participate in the discussion [[Talk:A-Frame (virtual reality framework)#Requested move 18 April 2025|here]].<!-- Talk:A-Frame (virtual reality framework)#Requested move 18 April 2025 crosspost --> —[[User:RMCD bot|RMCD bot]] 08:12, 18 April 2025 (UTC)
var nodeScoop2 = new RegExp('\\[\\[\\s*'+RegExp.quote(redlinks[i])+'\\s*\\]\\]','i');
:<small>To opt out of RM notifications on this page, transclude {{tlp|bots|2=deny=RMCD bot}}, or set up [[Wikipedia:Article alerts|Article alerts]] for this WikiProject.</small>
</syntaxhighlight>
 
== [[:GNOME]] listed at Requested moves==
Best, [[User:Kangaroopower|'''<span style="color:#009933;font-family:Tempus Sans ITC;">Kangaroo</span>''']][[User Talk:Kangaroopower|'''<span style="color:#000080;font-family:Tempus Sans ITC;">powah</span>''']] 20:09, 5 May 2017 (UTC)
[[File:Information.svg|30px|left]]A [[Wikipedia:Requested moves|requested move]] discussion has been initiated for [[:GNOME]] to be moved to [[GNOME (desktop environment)]]. This page is of interest to this WikiProject and interested members may want to participate in the discussion [[Talk:GNOME#Requested move 7 July 2025|here]].<!-- Talk:GNOME#Requested move 7 July 2025 crosspost --> —[[User:RMCD bot|RMCD bot]] 12:01, 7 July 2025 (UTC)
 
:<small>To opt out of RM notifications on this page, transclude {{tlp|bots|2=deny=RMCD bot}}, or set up [[Wikipedia:Article alerts|Article alerts]] for this WikiProject.</small>
:: {{ping|Kangaroopower}} I tried what you suggested in [[User:The Transhumanist/redlinkstest.js]], and it doesn't seem to work. I'll keep at it, thgouh. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 20:34, 5 May 2017 (UTC)
 
:: {{ping|Kangaroopower}} I forgot the quotes. So I put those back, and adjusted the replace strings to account for the removal of the control group delimiters, and it worked. Now to try it on the current script... [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 02:29, 6 May 2017 (UTC)
 
::: {{ping|The Transhumanist}} Glad I could help. Best, --03:34, 6 May 2017 (UTC)
 
:Perhaps you are looking for String.indexOf(). Oftentimes people discover regular expressions and somehow convince themselves that everything must be expressed in terms of regexes. If regex is not working for you, it is ok not to use it. [[Special:Contributions/91.155.195.247|91.155.195.247]] ([[User talk:91.155.195.247|talk]]) 20:07, 5 May 2017 (UTC)
 
:: According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf , that returns a number. I'm looking for specific strings, not the position (index) of a string. Thank you, as I was unaware of what this method does. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 11:00, 6 May 2017 (UTC)
 
 
: I cannot clear see what do you want to achieve, but I find these codes overkill. Mediawiki add titles of actual destinations as attribute <code>title</code> to links and class <code>new</code> for red links.
 
: This jQuery one-liner simply unlinks all red links. This snippet actually inserts linked texts before links and then remove these links.
<syntaxhighlight lang="javascript">
$("a.new").before(function(){ return this.textContent }).remove();
</syntaxhighlight>
 
: The function in <code>before</code> returns what to remain after link removal. The <code>this</code> refers to the currently iterated element due to jQuery's design. If we want to completely remove a link, make the function return nothing then. The following example completely removes red category links and treat other red links as usual.
 
:<syntaxhighlight lang="javascript">
$("a.new").before(function(){
if (!this.title.startsWith("Category:"))
return this.textContent;
}).remove();
</syntaxhighlight>
: [[User:Jdh8|Chen-Pang He]] ([[User talk:Jdh8|talk]]) <!--Template:Undated--><small class="autosigned">—Preceding [[Wikipedia:Signatures|undated]] comment added 07:40, 6 May 2017 (UTC)</small> <!--Autosigned by SineBot-->
 
Sorry, but I don't understand what you are trying to achieve. If you want to remove red links from the DOM (in the generated code of the view), then you can use Javascript (faster) or jQuery (slower) to remove or replace all of them eventually at once, or do more things on each of them in a loop. With Javascript you need to use one of "getElementsByClassName" (for example applied to <code>class="new"</code>) or "getElementsByTagName" for all <code><a></code> elements, and then you can apply styles ('_color_', '_cursor_', &hellip;) or replace them with your own content such as their "innerHTML" values. With jQuery >= 1.2 you can use something like <code>$(".new").replaceWith(function() { return $(this).text(); });</code> or <code>$(".new").replaceWith(function() { return this.innerHTML; });</code>, while with jQuery >= 1.4 you can use the <code>unwrap</code> function like this: <code>$(".new").contents().unwrap();</code>. jQuery seems to be shorter, but this is because you do not see the whole code that is behind the execution of it, and it is much slower than doing it in native Javascript (when it is well written, of course). All of them, Javascript and jQuery, should be wrapped into a document ready function (via Javascript or jQuery), a setTimeout functions or both. If you need to store their values, then you can create a <code>for</code> or a <code>while</code> loop for each of them and the do whatever you want to. Of course, if you are working on the source code, then the above does not apply at all. About the regex, I need more about the data, plus tests and examples. The reason for its multiple matches has been well explained above. Just a note, if you are sending and parsin a huge quantity of data, for example the whole content of an article, then something like [[Perl|PERL]] is always the faster and the better solution possible because it was conceived for reporting of the big log files such as those generated by a server. [[AWK]] and [[Sed|sed]] are also good with this. Unfortunately, I do not think that they are available here. –[[User:Pjoef|p<span style="color: #802400">joe</span>f]] <small>(''[[User talk:Pjoef|talk]]'' • [[Special:Contributions/Pjoef|contribs]])</small> 12:18, 6 May 2017 (UTC)
 
: {{ping|Pjoef|Jdh8}} First, the script is supposed to remove list item entries (including bullet and carriage return) that are comprised entirely of redlinks, but only if they have no children. Red end nodes. It goes through several iterations, just in case the removal of a red end node renders other red entries into end nodes. After all those have been removed, then the script delinks the remaining embedded red links, and finally deletes any red category links. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 14:12, 6 May 2017 (UTC)
 
=== The whole regex ===
{{ping|Jdh8|Kangaroopower|Syockit|Murph9000|SMcCandlish|TheDJ}}
 
The sample I posted at the beginning of this thread was simplified to show the problem that it was returning 2 matches instead of the expected 1. So, I thought the script might do unexpected replacements, but that has not happened (yet). But I've run into other problems...
 
The regex from the script is more involved than the sample, and is for matching the line the key topic (redlinks[i]) is included on plus the whole next line:
 
:<syntaxhighlight lang="javascript">
var nodeScoop2 = new RegExp('\\n((\\*)+)[ ]*?\\[\\[\\s*'+(RegExp.quote(redlinks[i]))+'\\s*\\]\\].*?\\n(.*?\\n)','i');
</syntaxhighlight>
 
The reason the whole next line is included is because I'd like to delete entries based upon the type of line that follows (or more accurately, does not follow). If the entry is not followed by a child, then it gets deleted, but should be kept if it does have a child. The weird thing is, that the part matching the whole next line is in the 4th set of parentheses, so you would expect $4 to back reference that. In practice, it is $3 that accesses that capturing group. And I don't know why. Though the solution (ignoring the parentheses around the embedded RegExp, when counting the capturing groups) seems to be working. But, I've run into a worse problem...
 
:<syntaxhighlight lang="javascript">
// Here is the regular expression for matching the scoop target (to "scoop up" the redlinked entry with direct (non-piped) link, plus the whole next line)
var nodeScoop2 = new RegExp('\\n((\\*)+)[ ]*?\\[\\[\\s*'+(RegExp.quote(redlinks[i]))+'\\s*\\]\\].*?\\n(.*?\\n)','i');
// To actualize the search string above, we create a variable with method:
var matchString2 = wpTextbox1.value.match(nodeScoop2);
alert(matchString2); // for testing
 
// Declare match patterns
var patt1 = new RegExp(":");
var patt2 = new RegExp(" – ");
var patt3 = /$1\*/;
 
// Here's the fun part. We use a big set of nested ifs to determine if matchString2 does not match criteria. If it does not match, delete the entry:
// If matchString2 isn't empty
if (matchString2 !== null) {
 
// If has no coloned annotation (that is, does not have a ":")
if (patt1.test(matchString2) === false) {
 
// If has no hyphenated annotation (that is, does not have " – ")
if (patt2.test(matchString2) === false) {
 
// ...and if the succeeding line is not a child (that is, does not have more asterisks)
if (patt3.test(matchString2) === false) {
 
// ... then replace nodeScoop2 with the last line in it, thereby removing the end node entry
wpTextbox1.value = wpTextbox1.value.replace(nodeScoop2,"\n$3");
incrementer++;
alert("removed entry");
}
}
}
}
</syntaxhighlight>
 
The problem is patt3. I'm trying to check for the asterisks at the beginning of the second line. If there is one more asterisk on that line than in the line before it, it means it is a child. In which case I do not want to delete the parent. But, the above code deletes the parents anyways.
 
In the example below, $1 should match the asterisk at the beginning of the parent line, and $1\* (patt3) should match the asterisks at the beginning of the child line. But it doesn't seem to be working. And when I add an alert to test for the value of patt3 or $1, the script crashes!
 
<nowiki>* Parent</nowiki><br>
<nowiki>** Child</nowiki>
 
If $1 includes asterisks in it, does it return those asterisks escaped?
 
Any ideas on how to solve my patt3 problem? [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 12:14, 6 May 2017 (UTC)
 
:Try to double-escape the aterisk <code>\\*</code> in a <code>RegExp</code> constructor or in this way <code>/\*</code>. –[[User:Pjoef|p<span style="color: #802400">joe</span>f]] <small>(''[[User talk:Pjoef|talk]]'' • [[Special:Contributions/Pjoef|contribs]])</small> 12:26, 6 May 2017 (UTC)
 
:: {{ping|Pjoef}} I did. See the RegExp below. Notice that the double escaped asterisk is inside a capturing group. When you use $1 to refer to that capturing group, will the asterisks in there still be escaped? When I try to use alert to test for $1, it crashes the script.
 
:<syntaxhighlight lang="javascript">
var nodeScoop2 = new RegExp('\\n((\\*)+)[ ]*?\\[\\[\\s*'+(RegExp.quote(redlinks[i]))+'\\s*\\]\\].*?\\n(.*?\\n)','i');
</syntaxhighlight>
 
:: I look forward to your reply. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 13:58, 6 May 2017 (UTC)
 
:Running the code in generated document seems to be easier because we can make use of HTML structure. A leaf link safe to remove is the only child of <code>li</code>.
 
:<syntaxhighlight lang="javascript">
$("a.new").replaceWith(function(){
if (this.title.startsWith("Category:"))
return null;
 
if (this.matches("li > :only-child"))
return null;
 
return this.textContent;
});
</syntaxhighlight>
 
:Cheers, [[User:Jdh8|Chen-Pang He]] ([[User talk:Jdh8|talk]]) <!--Template:Undated--><small class="autosigned">—Preceding [[Wikipedia:Signatures|undated]] comment added 15:19, 6 May 2017 (UTC)</small> <!--Autosigned by SineBot-->
 
:: )
 
I got your message. It looks like you may have gotten the help you need. When working with RegExp, I like to try them on some sample strings to see what each one is actually matching, and what it's returning. There's a great website for doing that: [https://regex101.com/ regex101]. [[User:Nathanm mn|Nathanm mn]] ([[User talk:Nathanm mn|talk]]) 16:12, 6 May 2017 (UTC)
 
: {{ping|Nathanm mn}} We still haven't figured it out. The problem I'm trying to solve is how to identify when a list item has a child. A child list item will have one more asterisk at the beginning than the parent. So, I set up a capturing group for the asterisks at the beginning of the parent (so $1 would be the back reference), and then try to match that number of asterisks plus one more in the child (using $1\*). But it isn't working. I am stuck. There are other criteria which the entries to be removed must fail, otherwise I wish to keep them. So simply getting rid of all children isn't what I'm after. We already know they are red linked entries, because the first half of the program puts all redlinks into an array, which we process in the second half of the program. Then the nested if structure checks first for whether the current redlink in the array has no entry. If it doesn't, then we check to see if it has no colon annotation. If it doesn't have a colon separator, then we check to see if it doesn't have a hyphenated annotation. If it doesn't have an en dash separator, then we check to see if it has no children. If it doesn't have a child, then we delete it from the wiki source, modifying the actual article itself.
: Once all redlinked entries that fail our tests are removed, then the rest of the program mops up, deleting red category links, and delinking all redlinks that still remain after that. We know, due to the extensive filtering we just subjected them to, that they are all embedded redlinks, the content of which we want to keep. I'll make a sample below that presents examples of the data instances to be processed. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 22:12, 6 May 2017 (UTC)
 
== Use of Wikipedian programmer categories ==
{{Reply to|The Transhumanist}} '''''Was it really appropriate to spam over 500 users with a notice of this discussion using [[WP:AWB]]?''''' That seems to me to be an inappropriate use of that tool. [[User:Murph9000|<span style="color:white;background-color:purple;padding:0.1em 0.1em 0.1em 1em;">Murph</span><span style="color:white;background-color:black;padding:0.1em 1em 0.1em 0.1em;">9000</span>]] ([[User talk:Murph9000|talk]]) 13:21, 5 May 2017 (UTC)
:: 90% of them haven't logged in for months or years, but were still listed in the js users categories. It's the only feasible way I could think of to reach the other 10%. You wouldn't happen to know of a script that can sort or screen a user list by the date of their last edit, would you? That would be very helpful. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 15:07, 5 May 2017 (UTC)
:: {{done}} Found a way. See [[#Tracking down recent editors]], below. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 17:10, 5 May 2017 (UTC)
 
: Yeah, OP shouldn't have done that. If you want to recruit programming helpers, try Stack Overflow! [[User:Tomalak geretkal|Tomalak Geret&#39;kal]] ([[User talk:Tomalak geretkal|talk]]) 13:29, 5 May 2017 (UTC)
:: Just contacted users in the js wikipedian categories, which is what those categories are for, per [[WP:UCAT]]. For help with a script to improve the encyclopedia. I'll look into a way to filter out dead user accounts from a list. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 15:19, 5 May 2017 (UTC)
:: {{done}} See [[#Tracking down recent editors]], below. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 19:26, 5 May 2017 (UTC)
: For real. Wikipedia ''is not'' StackOverflow. [[User:Julesmazur|Julesmazur]] ([[User talk:Julesmazur|talk]]) 14:00, 5 May 2017 (UTC)
:: The programming userboxes are to enable Wikipedians to contact each other about programming, per [[WP:UCAT]]. That's why we list our JavaScript skill-level, right? [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 15:07, 5 May 2017 (UTC)
:::Consider that I've deleted several pages that you created through these mass messages that were not, in fact, user talk pages. Examples (not exhaustive, and I got bored of deleting them after a few): [[User talk:X!/egapresu siht tide t'nod esaelP]], [[User talk:Vanished user 98wiejfno34tijsfoiwefjlok5y/infobox]], [[User talk:Godlvall2/UserBoxes]]. Those userboxes are for ''identification'', sure, but they're not for automated mass messaging. [[User:Writ Keeper|Writ&nbsp;Keeper]]&nbsp;[[User Talk: Writ Keeper|&#9863;]][[Special:Contributions/Writ_Keeper|&#9812;]] 15:35, 5 May 2017 (UTC)
:::: Thanks. My bad. I didn't notice them right away, and then started skipping them. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 16:52, 5 May 2017 (UTC)
 
:Also, was it really necessary to use AWB to post an invitation to 300+ ''mainspace'' talk pages? I don't think that's where they go. [[User:Writ Keeper|Writ&nbsp;Keeper]]&nbsp;[[User Talk: Writ Keeper|&#9863;]][[Special:Contributions/Writ_Keeper|&#9812;]] 14:11, 5 May 2017 (UTC)
:: {{ping|Writ Keeper}} I've converted those to informational notices concerning upkeep of JavaScript articles, with a more encyclopedic tone. Thank you for the feedback. [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 16:51, 5 May 2017 (UTC)
 
== Tracking down recent editors ==
 
I'd like to contact recent editors (say, in the past month) from the users listed at:
 
[[:Category:User js-4]]
 
Many of the users listed here haven't logged in for years.
 
Any ideas? [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 11:43, 5 May 2017 (UTC)
 
: Hi [[User:The Transhumanist|The Transhumanist]]. Quarry is awesome for stuff like this. Here you go :) https://quarry.wmflabs.org/query/18396 --[[User:EpochFail|<span style="display:inline-block;padding:0 .25em;border-bottom:2px solid #008;background: #f6f6f6;" title="aka halfak">EpochFail</span>]] ([[User_talk:EpochFail|talk]] &bull; [[Special:Contributions/EpochFail|contribs]]) 16:05, 5 May 2017 (UTC)
:: Perfect. I ran it again for the other cats. Thank you for the script! [[User talk:The Transhumanist|<i>The&nbsp;Transhumanist</i>]] 19:08, 5 May 2017 (UTC)
 
 
== Data type section needed in [[JavaScript]] article ==
In my eyes the article misses a section describing the available data types. Can somebody with knowledge about the subject add this?
--[[Special:Contributions/79.213.185.195|79.213.185.195]] ([[User talk:79.213.185.195|talk]]) 06:37, 22 April 2017 (UTC)