User talk:Guywan/Scripts/LEA.js

Latest comment: 4 years ago by The Transhumanist in topic Testing, testing...

Suggestions edit

@Guywan: I have a few more suggestions, if you'll hear them. Feel free to ignore.

  1. Wrap the script in an anonymous function, to ensure that it doesn't accidentally interact with other code
    1. Put
      $(function (){
      
      at the top
    2. Put
      });
      
      at the bottom
  2. Wait for the page to be ready before adding the link
    1. Use
      mw.loader.using( 'mediawiki.util', function () {
      
          $(document).ready( function () {
      
      before the start of the main run function
    2. Add
      } );
      
      } );
      
      at the end of that function
  3. Use mw.util.addPortletLink
    1. Replace
      $("#p-tb ul").append("<li id='t-lea'><strong><a>List Entry Annotator</a></strong></li>");
      
      with
      mw.util.addPortletLink ( 'p-tb', 'javascript:void(0)', 'List Entry Annotator', 't-lea', 'Annotate list entries');
      

If you want an example of how I write scripts, see User:DannyS712/Easy-link.js, which is fairly straightforward. --DannyS712 (talk) 17:44, 1 June 2019 (UTC)Reply

Thank you, @DannyS712:. You're suggestions are welcome.
  1. Very useful! I didn't know functions could be declared inside functions.
  2. To my knowledge, $(function(){}); and $(document).ready(function(){}); are synonymous. See the jQuery docs.
  3. An excellent idea!
Guywan (talk) 18:05, 1 June 2019 (UTC)Reply
@Guywan: Hi Guywan, I will definitely be trying out this script. I'll keep you posted.
By the way, I have trouble remembering all these programming details while working on scripts. I sometimes go weeks or months between coding sessions, and after each break I may find it difficult to understand anything I coded. So, I started writing "walk-throughs" of my code on the scripts' talk pages, explaining each script piece by piece, pulling in resources (links, excerpts, etc.) to help grok the code. Here are some entries that you might find useful to further illuminate the concepts presented above:
I haven't tried out your script yet, but will do so soon. Got to go!    — The Transhumanist   04:57, 6 June 2019 (UTC)Reply

Testing, testing... edit

@Guywan: I'm very excited that you created this script, and can't wait until I learn how to use it correctly. At the moment, I don't know how to make it work or what it can work on. I went to Outline of baseball, clicked on List Entry Annotator, and the page hung with the menu still hanging down. Nothing else happened, as far as I could tell.    — The Transhumanist   07:43, 6 June 2019 (UTC)Reply

@The Transhumanist: For large pages like Outline of baseball, this script will take a very long time to complete, and will appear to hang. My browser (Chrome) even told me (a few times) that the page was unresponsive. Just wait, eventually the script will complete (~30 seconds for me). I don't think there is any way to speed up the script, without changing the way it works. You might want to try the script in your sandbox to get the hang of it. GUYWAN ( t · c ) 10:41, 6 June 2019 (UTC)Reply
@Guywan: Thank you. I'll try it again, and will get back to you with comments.    — The Transhumanist   12:23, 10 June 2019 (UTC)Reply