User talk:The Transhumanist/ViewAsOutline-Article.js


 * This script is under development, and is not yet functional

= Script's workshop =
 * This is the work area for developing the script and its documentation. The talk page portion of this page starts at, below.

Description / instruction manual for

 * This script is under development, and is not yet functional

When completed, this script will

General approach
(general approach goes here)

More specifically, starting at the beginning...

Change log for

 * 2018-01-04
 * Start script using
 * Turn off bullets using

Desired/completed features

 * Completed features are marked with ✅


 * Must be menu item activated
 * On/off switch would be nice, but reversing everything would be problematic
 * Single function menu item would suffice; undo by reloading page

Development notes for
How will this be able to modify a page without redoing the various templates on the page?

This script needs to avoid adding wikicodes to headings and links that already have them, such as those in navigation footers and sidebars, and on book, glossary, category, and category tree pages.

A partial solution is with activation filters for page types already covered, or unintended:
 * Book pages
 * Category pages
 * Glossary pages
 * Template pages
 * Special pages

Another method that may work would be to have each script that modifies elements to add a class to those elements to indicate that they've been modified. Then elements of those classes could be excluded via the .not method. But this script would have to be run last.

Yet another method would be to combine all the code that is to work on article pages into one script.

Script dependencies
= Discussions =


 * This is where the actual talk page starts for User:. Please post your discussion threads below...

Activation filter for article namespace pages?

 * Originally posted at User talk:Evad37

On some of my scripts, I use an activation filter that checks the title and runs only if the namespace up there matches:

Now I need to do this with articles in the main namespace, but there is no prefix up there in the title to work off of.

What to do? The Transhumanist 13:02, 11 February 2018 (UTC)
 * Test the namespace with conditions like . —&thinsp;JJMC89&thinsp; (T·C) 17:17, 11 February 2018 (UTC)
 * Yep, you can do something like that, for any namespace (namespace numbers are listed at WP:NS). Or check for the inverse situation, so you don't have to nest everything inside an if statement:
 * The  statement only works within functions, but that's generally not a problem – you're whole script is usually wrapped inside a function, assuming you need to wait for the document ready and/or wait for resource loader modules to be loaded. - Evad37 &#91;talk] 00:44, 12 February 2018 (UTC)
 * Many of my scripts approach an insane level of if statement nesting. I definitely need to apply this return approach.
 * I think your program snippet above means "If the namespace is not 'zero', end the function." And "return" ends the program if the body of the script is in the same function, and at the same level (or deeper) in that function, as the if statement. Am I reading that right?   The Transhumanist 14:38, 12 February 2018 (UTC)
 * Yes, the "return" ends the function it is immediately within at the point, and so the program resumes execution from the point where the function was invoked – but since we've wrapped the whole script in ...  there's nothing more left to execute, and so the script ends. It doesn't matter if the "return" is within any number of "if"/"if-else" statements, "for" loops, "while" loops, etc – only having another (sub)function will change the scope it applies to. One thing to watch for, at deeper levels within your programs, is that when you are assigning a variable to a function call, the variable is set to the return value, which is specified with   inside the function. Since we haven't explicitly set a return value, it would be   – but that doesn't matter for our purpose, since the function is just there to make the script wait before executing, and is not assigning a value to a variable. - Evad37 &#91;talk] 02:09, 13 February 2018 (UTC)
 * Thank you JJMC89 and Evad37.   The Transhumanist 14:38, 12 February 2018 (UTC)
 * Thank you JJMC89 and Evad37.   The Transhumanist 14:38, 12 February 2018 (UTC)

What about "or"?
What about doing the same thing for more than one namespace? Such as "run script if the page is in the article namespace or the template namespace"? The Transhumanist 18:03, 13 February 2018 (UTC)
 * You just need to negate the logic to work out when to .  is equivalent to . So in script (and putting the actual namespace number into a variable to avoid duplication), you get something like:
 * Or you could go a bit further and assign the condition to a variable, so you can name it (makes it easier to read, and remember what you were doing), and negate it later with the  operator:
 * And that's alright for a couple of namespaces, but if you need to do more, rather than keep adding more ORs or ANDs to the condition, you can use the array method indexOf for the logical test (which returns -1 if a value isn't in the array tested)
 * - Evad37 &#91;talk] 23:59, 13 February 2018 (UTC)
 * And that's alright for a couple of namespaces, but if you need to do more, rather than keep adding more ORs or ANDs to the condition, you can use the array method indexOf for the logical test (which returns -1 if a value isn't in the array tested)
 * - Evad37 &#91;talk] 23:59, 13 February 2018 (UTC)
 * - Evad37 &#91;talk] 23:59, 13 February 2018 (UTC)