User talk:The Transhumanist/ViewAnnotationToggler.js

This is an old revision of this page, as edited by The Transhumanist (talk | contribs) at 09:10, 2 March 2017 (add sections). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Latest comment: 8 years ago by The Transhumanist in topic Completed features

Explanatory notes

( function ( mw, $ ) {}( mediaWiki, jQuery ) );

var

document.get.ElementById()

mw-content-text

cont.outerHTML

outerHTML.replace

wrapping in span tags

cont.outerHTML = cont.outerHTML.replace(/(

  • .*?)( –.*)/g,'$1$2');

    Change log

    Desired features

    Improvements needed:

    • Have the screen stay anchored on its top entry when the toggle is used
    • Find/replace annotations of other formats
      • regular hyphens
      • em dashes
      • no-break space-hyphen combos
      • commas
      • hanging hyphens (hyphen, with no annotation)
      • parenthetic annotations?
      • colons
    • Find/replace annotations of lead list entries (without bullets)
      • Only on pages with the title "Outline of"
      • Match entry that follows heading
      • Match entry that follows "{{Main}}"?
    • Since it hides content, an indicator is needed to show when it is on/off.
    • Fix the conflict with sidebar toggle (it also uses hot-key Shift-Alt-a)
    • load mw:ResourceLoader/Modules#mediawiki.util
    • Test on many pages of every page type
    • Test on other browsers (tested on Firefox 43.0.4)
    • Port to GreaseMonkey
    • Have separate hot-keys for on and off, to be macro-friendly?
    • Convert annotations, and then clone? (then it will toggle with fixed format)
    • Feature to apply and save fixes (conversions) to wikicode (i.e., replace non-standard annotation punctuation in the page source)
    • While in hidden mode, have popup functionality for annotations, when the mouse cursor is hovered over:
      • The topic?
      • The bullet?

    Completed features

    Program on/off switch

    The current objective is to store global variables, and pass them on to the next page, including the current page upon refresh.

    The state of the program can then be controlled from page to page, via conditionals applied upon the global variables.

    Methods that persists data across a page refresh include:

    • iframe – ?
    • ajax – ?
    • cookies – this requires a server call, and is inefficient
    • localstorage
      • localStorage.setItem("annostatus", "hide");
        
      • var annostatus = localStorage.getItem('annostatus');
        

    Feature completed. The Transhumanist 09:06, 11 December 2016 (UTC)Reply

    Went from cloning/regex-to-null to show/hide wrapper

    Initially, the program toggled hide/show in a rather convoluted way: first it saved the mw-content element by cloning it. Then it deleted the annotations using regex. To get them back, it made a clone of the clone, and then replaced mw-content with the second clone. Here's that version:

    https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=759842909

    Then based on a suggestion by Anomie, I simplified the script to wrap each annotation in a classed span (class="anno"), and then used jQuery in the subfunctions to .hide and .show the class. Here's the simplification:

    https://en.wikipedia.org/w/index.php?title=User:The_Transhumanist/anno.js&oldid=760834841


    It shrank by several lines of code. The Transhumanist 13:27, 19 January 2017 (UTC)Reply

    Development notes

    Injecting/inserting/embedding style

    One way to hide/show a class is to define that class on the page, and then toggle its display property. Where are the instructions on how to do this?

    Here are some related links:

    Scroll position

    The goal here is to maintain the position of the scroll, with respect to the topmost list entry on the screen, and have the formatting change while maintaining that position.

    Some potentially relevant resources:

    You can get the position of an element, relative to the viewport, with code from http://stackoverflow.com/questions/442404/retrieve-the-position-x-y-of-an-html-element. You can then keep that element on the screen with code from http://kirbysayshi.com/2013/08/19/maintaining-scroll-position-knockoutjs-list.html. The two websearches I used to find these were https://duckduckgo.com/?q=js+get+top-left+object and https://duckduckgo.com/?q=js+scroll+element+to+viewport+position. (quote from LongHairedFop (talk) 13:53, 11 December 2016 (UTC))

    Find/verify non-li list-lead entries