User talk:The Transhumanist/StripSearchSorted.js: Difference between revisions

Content deleted Content added
top: update
fix instruction manual, work on explanatory notes
Line 1:
: ''I'm using this page as a workspace. The talk page portion of it starts at [[#Discussions]], below.''
 
: '''''This script is operational'''''. ''''Quirk in wikEd: When results are copy and pasted into wikEd, the results are erroneously double spaced. Clicking on undo in wikEd reverts it to single spaced as initially intended. (DonI don't know why. If you do, please tell me.)
 
[[User:The Transhumanist/StripSearchSorted.js|StripSearchSorted.js]]: stripsprovides a menu item to strip search results down to bare pagenamespage names, sortssort them alphabetically, and addsadd bullet list wikicode formatting for easy copying and pasting into articles. The menu item is a toggle switch that turns this function on and off, and remembers its status for all searches. By default, just by being installed, the script removes redirected entries and members of matching categories (as they don't match the search string), even if you don't use the menu item. For Vector skin only.
 
= Script's workshop =
Line 12:
: ''This script is partially operational; it doesn't sort the results yet.''
 
[[User:The Transhumanist/StripSearchStripSearchSorted.js|StripSearchInWikicodeStripSearchSorted.js]]: stripsprovides a menu item to strip search results down to bare pagenamespage names, sort them alphabetically, and addsadd bullet list wikicode formatting for easy copying and pasting into articles. ItBy alsodefault, the script removes redirected entries, and ismembers especiallyof usefulmatching forcategories "intitle:"(as they don't match the search string), even if you don't use the menu searchesitem. For Vector skin only.
 
ThisIn other words, when the menu item is turned on, this script reduces the search results to a list of links. It strips out the data between the page names, including that annoying "from redirect" note. It adds <code>* [[]]</code> to each entry and sorts them so they look like this:
 
<nowiki>* [[</nowiki>[[John Wayne]]<nowiki>]]</nowiki></br>
<nowiki>* [[</nowiki>[[Clint Eastwood]]<nowiki>]]</nowiki></br>
<nowiki>* [[</nowiki>[[Brad Pitt]]<nowiki>]]</nowiki></br>
<nowiki>* [[</nowiki>[[Clint Eastwood]]<nowiki>]]</nowiki></br>
<nowiki>* [[</nowiki>[[Dwayne Johnson]]<nowiki>]]</nowiki></br>
<nowiki>* [[</nowiki>[[John Wayne]]<nowiki>]]</nowiki></br>
<nowiki>* [[</nowiki>[[Tom Cruise]]<nowiki>]]</nowiki></br>
 
ThisThe formatting makes it easier to copy and paste the links from search results into articles.
 
Once installed, the menu item "SR sort" will appear in the side bar tools menu, specifying what action it is ready to perform (either "turn on" or "turn off").
Once installed, the script automatically processes your Wikipedia search results.
 
To install, add this line to your vector.js page:
 
<syntaxhighlight lang="javascript">
importScript("User:The Transhumanist/StripSearchInWikicodeStripSearchSorted.js");
</syntaxhighlight>
 
If you want the detail back in your search results, remove that line, or comment it out by placing two forward slashes (//) at the beginning of it.
 
== Explanatory notes (source code walk-through) ==
Line 57 ⟶ 55:
 
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 [https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Building_blocks/conditionals conditional, '''''if'''''].
 
==== Vector skin activation filter ====
 
I use the Vector skin, and haven't tested the script on any other skin, so the script basically says "''if'' the vector skin is in use, do what's between the curly brackets". (Which includes the entire rest of the program).
 
<syntaxhighlight lang="javascript">
// Only activate on Vector skin
if ( mw.config.get( 'skin' ) === 'vector' ) {
// The rest of the script goes here
}
</syntaxhighlight>
 
 
// Run this script only if " - Search results - Wikipedia" is in the page title
==== Page title activation filter ====
if (document.title.indexOf(" - Search results - Wikipedia") != -1) {
 
<syntaxhighlight lang="javascript">
// Run this script only if " - Search results - Wikipedia" is in the page title
if (document.title.indexOf(" - Search results - Wikipedia") != -1) {
// The rest of the script goes here
}
</syntaxhighlight>
 
 
 
=== Prep work ===