User talk:The Transhumanist/StripSearch.js


 * This script is functional

StripSearch.js: strips Wikipedia search results down to bare pagenames. It provides the "SR detail" menu item to hide/show the search results' details and the sister project results. Search results are preprocessed to remove all redirected entries and members of matching categories, so that they do not show up at all.

Note that a newer script, called SearchSuite.js provides each of these features on their own switches, plus it has a sort feature, and a feature that can add wikicode to list items for easy copying and pasting.

= 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

 * This script is functional

StripSearch.js: strips Wikipedia search results down to bare pagenames. It provides the "SR detail" menu item to hide/show the search results' details and the sister project results. Search results are preprocessed to remove all redirected entries and members of matching categories, so that they do not show up at all.

When initially installed, the program adds the "SR detail (hide)" item to the Tools menu in the side bar, which appears when a search results page is displayed. Clicking on that turns the search results into a bare single spaced list of article links, makes the sister project results disappear, and the menu item becomes "SR detail (show)". In case you missed it, "SR" stands for "search results".

The program remembers its mode between pages, and so all search results will be stripped until "SR detail (show)" is clicked. Then it will go back to showing search results in the original format, including the sister project results in the right hand column.

How to install this script
To install this script, do the following:

In your common.js page or your skin.js page (replace "skin" with the name of the skin you are using), add this line:



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

General approach
The script uses the jQuery method .hide for stripping the elements by class name. Here's an example of stripping out elements with the class name "searchalttitle":

Learn about methods at https://www.w3schools.com/js/js_object_methods.asp

Learn about .hide at http://api.jquery.com/hide/

Activation filters
I didn't know what else to call these. I wanted the program to only work when intended, and only on intended pages (search result pages). So, I applied the conditional, if.

The script basically says "if we are on the search results page, do what's between the curly brackets". (Which includes the entire rest of the program). Actually, we're using a double negative "if the title does not not have this in the title". means "not equal to", and the  indicates "does not exist".

Prep work
There is no prep work in this script. This would be the declaration of global variables and so on.

Core program
This is the part controls the main flow of the script (decides what to do under what circumstances):

So, what this does is 4 things:

First, it checks if the Vector skin is being used and runs the rest of the script only if it is.

Then it applies the jQuery method .hide on all elements labeled as any of these 3 classes: searchalttitle, searchresult, or mw-search-result-data.

To use an object method, you append it to the end of an element, as is done with  3 times above. Don't forget the parentheses, and be sure to end your statements with a semicolon.

Learn more about .hide at http://api.jquery.com/hide/

mw.config.get ( 'skin' )
This looks up the value for skin (the internal name of the currently used skin) saved in MediaWiki's configuration file.


 * jQuery get Method
 * mw.config

logical operators
" " means "equal value and equal type"


 * JavaScript Comparison and Logical Operators

Strip out the sister project results
To write the above, I searched the pagesource for the classes of the data displayed in the right-hand column, traced back to their parent "id="mw-interwiki-results", wrapped that in a jQuery object ("$" means "jQuery"), and then attached the hide method to it.

Change log

 * 2017-09-25
 * Started script
 * Version 1.0 complete
 * Removes lines with page data from the search results
 * Removes content excerpts from the search results
 * Removes "from redirect" comments from the search results
 * Strips out sister project results (from right-hand column)

Desired/completed features

 * Completed features are marked with ✅

Improvements that would be nice:


 * Remove lines with page data from search results ✅
 * Remove content excerpts from search results ✅
 * Remove "from redirect" comments from search results ✅
 * Strip sister project results ✅
 * Remove the drawn lines between the search result entries problem went away
 * Remove alternating background colors from behind the search results problem went away
 * Reduce spacing between result entries ✅
 * Remove redirected entries and members of matching categories from the search results ✅
 * A note at the top of the search column "search results formatted by StripSearch.js", linked to the instruction manual section of the script's workshop page.
 * Try catch on the menu item calls
 * There's a bug buried in the  sequence that is rendered moot by the searchalttitle removal statement. The bug should still be fixed for the sake of future forks of this program.

Trycatch needed, and more

 * The Transhumanist, where you use local storage.getItem or setItem you should always wrap that in try catch, as it can fail at any moment (even if you checked previously). This can be due to the browser running out of storage space for the domain, or because the browser is running in privacy mode or with an ad blocker extensions or something. Also, your new RegExp calls should be lifted outside of the for loops, so that they aren't continuously recreated. For wpTextbox1.value, realise that sometimes the content might be managed by an editor (The syntaxhighlighting beta does this for instance). We use the jquery.textSelection plugin to abstract way from these differences. Don't check document.title, check mw.config.get( 'wgTitle' ) or mw.config.get( 'wgPageName' ). And when you use mw.util.addPortlink, you have to ensure that the mediawiki.util plugin is loaded already, which you can do by using mw.loader.using. —Th e DJ (talk • contribs) 14:47, 27 October 2017 (UTC)

Add note to search results page
Add a note at the top of the search column "search results formatted by StripSearch.js, linked to the instruction manual section of the script's workshop page.