User talk:The Transhumanist/hdedit.js

Page contents not supported in other languages.
Source: Wikipedia, the free encyclopedia.
This is an auxiliary support page for the script hdedit.js which is by User:The Evil IP address. This page's purpose is to provide alternative documentation, especially about the source code itself. Please post discussion threads below the section titled Discussions. Thank you. By the way, the various scripts I have written or developed are listed at the bottom of the page.[1]
The script version covered by this page is https://en.wikipedia.org/w/index.php?title=User:The_Evil_IP_address/hdedit.js&oldid=809009432, and has been provided on the adjoining user page for convenience.

hdedit.js is a user script by User:The Evil IP address. This page is an attempt to explain that script, so that the reader (including me) can understand what it does and how it does it.

Script's workshop

This is the work area for developing documentation about the script. The talk page portion of this page starts at #Discussions, below.

Description / instruction manual for hdedit.js

hdedit.js is a user script. Once installed and the user is logged in, it allows the user to click on a heading while viewing a Wikipedia page. That action brings forth a little edit box with the heading in it for the user to edit. There are buttons provided to save or cancel.

How to install the script

To install the script, add this line to your common.js or your vector.js page:

importScript("User:The Evil IP address/hdedit.js");

Save the page and bypass your cache to make sure the changes take effect. By the way, only logged-in users can install scripts.

Explanatory notes (source code walk-through)

This section explains the source code, in detail.

The source code looks like Greek to me, even though I've written several user scripts. And so, below, I shall pick apart the script statement-by-statement and expression-by-expression, explaining them as I go.

My intention is threefold:

  1. to thoroughly document the script so that even relatively new JavaScript beginners can understand what it means and what each piece of it does.
  2. to refresh my memory of exactly how the script works, in case I don't look at the source code for weeks or months.
  3. to facilitate understanding of the underlying programming conventions used in the script, for skill improvement. Once learned, they can be used again and again elsewhere. Therefore, the explanatory notes include examples, and links to relevant documentation pages, tutorials, etc.

In addition to plain vanilla JavaScript code, the script relies heavily on the jQuery library.

General approach

The script uses the <form>, <input>, and <button> HTML elements to create an on-the-fly editor for headings.

More specifically, starting at the beginning...

What's missing? And why...

Note that the script does not include a ready() event listener/handler (which makes the script wait until the DOM is loaded into the browser). That's because it doesn't need one. The script works on headings, and the user can't click on one until it is displayed, and so the script is forced to wait by default.

The script also does not include a bodyguard function to protect its aliases. The script uses two aliases: "$" and "mw" (more about those below).

window.hdedit =

var

This is the reserved word var, which is used to declare variables. A variable is a container you can put a value in. To declare the variable portletlink, write this:

var portletlink

A declared variable has no value, until you assign it one, such as like this:

portletlink = "yo mama";

You can combine declaration and assignment in the same statement, like this:

var portletlink = mw.util.addPortletLink('p-tb', '#', 'Remove red links');

Caveat: if you assign a value to a variable that does not exist, the variable will be created automatically. If it is created outside of a function, it will have global scope. For user scripts used on Wikipedia, having a variable of global scope means the variable may affect other scripts that are running, as the scripts are technically part of the same program, being called via import from a .js page (.js pages are programs). So, be careful. Here are some scope-related resources:

Task list

Bug reports

Desired features

Script dependencies

Discussions

This is where the actual talk page starts. Please post your discussion threads below...
  1. User scripts by The Transhumanist under development
    Semi-automated
    editing
    RedlinksRemover.js – remove red linked list items that are end nodes (last item of a branch), reiteratively, and delink the rest, from outlines and lists.
    Search results page
    enhancements – suite of search features, each on a switch, so you can turn them on and off as desired (and it remembers the switch positions). SearchSuite replaces all the search scripts below.

    StripSearchSorted.js – provides menu item that turns sorted strip search on/off; Includes the features of all the other search scripts below, and sorts the results alphabetically. Co-written by User:Evad37; he did the heavy-duty programming.
    StripSearch.js – provides menu item that turns strip search on/off; strips search results down to bare pagenames.
    StripSearchSansRedirecteds.js – strips search results down to bare pagenames, with redirected entries removed. No off switch.
    StripSearchInWikicode.js – strips search results down to bare pagenames, and presents as bullet list with pagenames enclosed in double square bracket link delimiters (just like in wikicode). Redirected entries are also removed. No off switch.

    StripSearchSimple.js – strips all search results down to bare pagenames. No off switch.
Viewing
enhancements
ViewAnnotationToggler.js – turns list item annotations off and on.

OutlineViewImageToggler.js – turns the display of images off and on, across all outlines.

OutlineViewTOCToggler.js – turns the TOC feature for all outlines off and on.
Viewing
enhancements
for list and
outline editors
hunting for
list items
ViewAsOutline-AllPagesWithPrefix.js – adds list item wikicodes to the on screen results of All pages with prefix, for easy copying/pasting into outlines and lists. No off switch.

ViewAsOutline-Category.js – removes the alphabetical headings, and adds list item wikicodes, for easy copying/pasting into outlines and lists. No off switch.
ViewAsOutline-Book.js – converts page to outline format on screen, with wikicodes for easy copy and paste into outlines and lists. No off switch.
ViewAsOutline-CategoryTree.js – on menu item click, converts tree to outline format on screen, with wikicodes for easy copying/pasting into outlines and lists. Refresh page to undo.
ViewAsOutline-Templates.js – converts navboxes and sidebar boxes on current page into outline format, with wikicodes displayed, for easy copying/pasting into outlines. No off switch. (Needs to be enhanced to show base links rather than pipes.)

ViewAsOutline-Glossary.js – converts glossaries to list format on screen, with wikicodes for easy copy-and-paste into outlines and lists. No off switch. (In early development, very rough. Currently, only converts bullet list glossary format.).
Coming
eventually
QuickPortal.js – portal tool, for creating and restarting portals. Will be expanded for modification and maintenance as well.

P-link.js – place links to portals.

OutlineDedupeHolding.js – remove duplicate list items from the outline's holding sections (See also, holding bin, place these, general concepts, and list section). That is, it will remove from each of these sections, in turn, all topics that exist anywhere else in the body of the page (not in templates).
StripSearchFilter.js – narrow down search results.
OutlineMain2LI.js – convert main links in outline to list items.
TopicPlacerFromBin.js – Topic placer (loads topics from holding bin into an array, then assists in placing each one). For use on lists and outlines.
FetchCategory.js – import category to present location.
FetchCategories.js – import categories to tagged locations.
FetchSection.js – import section to present location.

TopicSender.js – prompts for parent topic (outline), then checks if it is already there, if it isn't, then it sends it to the receiving section of that outline)
PlaceCategory.js

OutlineViewConventional.js – change the viewed formatting of the current outline into that of a conventionally indented outline, without headings.