Wikipedia talk:WikiProject JavaScript: Difference between revisions

Content deleted Content added
Notifying WikiProject of move discussion on Talk:GNOME
 
(222 intermediate revisions by 51 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
 
==Help: IllWill.js==
::<syntaxhighlight lang="javascript">
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)
var nodeScoop2 = new RegExp('\\[\\[\\s*('+RegExp.quote(redlinks[i])+')\\s*\\]\\]','i');
</syntaxhighlight>
 
== [[:React (JavaScript library)]] listed at Requested moves==
::which for example returns <nowiki>[[Geography of France]]</nowiki>, Geography of France
[[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==
::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)
[[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)
:<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>
 
== [[:GNOME]] listed at Requested moves==
: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)
[[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>
== 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)
:: Looking into it. 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)
 
: 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)