User talk:Guywan/Scripts/LEA.js
Appearance
Suggestions
[edit]@Guywan: I have a few more suggestions, if you'll hear them. Feel free to ignore.
- Wrap the script in an anonymous function, to ensure that it doesn't accidentally interact with other code
- Put at the top
$(function (){
- Put at the bottom
});
- Put
- Wait for the page to be ready before adding the link
- Use before the start of the main run function
mw.loader.using( 'mediawiki.util', function () { $(document).ready( function () {
- Add at the end of that function
} ); } );
- Use
- Use
mw.util.addPortletLink
- Replace with
$("#p-tb ul").append("<li id='t-lea'><strong><a>List Entry Annotator</a></strong></li>");
mw.util.addPortletLink ( 'p-tb', 'javascript:void(0)', 'List Entry Annotator', 't-lea', 'Annotate list entries');
- Replace
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)
- Thank you, @DannyS712:. You're suggestions are welcome.
- Very useful! I didn't know functions could be declared inside functions.
- To my knowledge,
$(function(){});
and$(document).ready(function(){});
are synonymous. See the jQuery docs. - An excellent idea!
- Guywan (talk) 18:05, 1 June 2019 (UTC)
- @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:
- Concerning #1 above, I think a bodyguard function would also serve to remove the script from global scope into the local scope of the current script, while reserving aliases for use in the script. For more information, see User talk:The Transhumanist/SearchSuite.js#Bodyguard function.
- For #2 (waiting) above, see User talk:The Transhumanist/SearchSuite.js#The ready() event listener/handler
- For #3 (portletlink) above, see User talk:The Transhumanist/SearchSuite.js#mw.util.addPortletLink
- I haven't tried out your script yet, but will do so soon. Got to go! — The Transhumanist 04:57, 6 June 2019 (UTC)
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)
- @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)
- @Guywan: Thank you. I'll try it again, and will get back to you with comments. — The Transhumanist 12:23, 10 June 2019 (UTC)