User talk:Surjection
Our first steps tour and our frequently asked questions will help you a lot after registration. They explain how to customize the interface (for example the language), how to upload files and our basic licensing policy (Wikimedia Commons only accepts free content). You don't need technical skills in order to contribute here. Be bold when contributing and assume good faith when interacting with others. This is a wiki. More information is available at the community portal. You may ask questions at the help desk, village pump or on IRC channel #wikimedia-commons (webchat). You can also contact an administrator on their talk page. If you have a specific copyright question, ask at the copyright village pump. |
|
-- Wikimedia Commons Welcome (talk) 19:46, 10 January 2018 (UTC)
JS help needed
[edit]Hi Surjection,
you are stating that JS is not a miracle to you. Well, for me it is...
I am trying to keep an orphanized script running, with more or less success.
But some needs I cannot fulfill because my JS knowledge is to poor.
I need help. Not explanations or sophistic discussions, just a small
code snipped that is able to do what is required, that I can use
without understanding all the abouts.
I need to perform a simple existence check, in this case for a user page.
First I want to check the user, if it does not exist I look for his talk page,
when that is also missing I try the users ~wiki and ~wiki talk page.
It is an easy task for a template, and not much more difficult in LUA,
but in JS the asynchronous access troubles me.
I wrote about my problems at User talk:Sarang/simpleSVGcheck/sandbox.js. Do you think that you can solve my problems? -- sarang♥사랑 17:37, 1 November 2021 (UTC)
- pageExist doesn't return any value (it only calls a callback), so you shouldn't be assigning its return value to ns as you are doing with ns = pageexist(... SURJECTION ·talk·contr·log· 17:42, 1 November 2021 (UTC)
- I had been trying many many versions over a couple of weeks; in vain. The code examples are just to show what I wanted. I would prefer a professional solution!
- It will be a great help when somebody who is common with JS creates the needed code for an efficient existence check.
- When it does not work under e.g. Opera, I need a possibility to check which browser is active, so I can avoid useless access.
- Undeniably I am not able to get the needed knowledge and experience within an acceptable time. so I ask for help -- sarang♥사랑 12:57, 2 November 2021 (UTC)
- If I understood correctly, you want a function that can tell you if a user with a specific user name has a user or user talk page and possibly add a ~commonswiki if a user does not exist by the original given name? SURJECTION ·talk·contr·log· 12:59, 2 November 2021 (UTC)
- Yes, that is my need. With my bad half-working script function I check that and finally, after 1, 2, 3 or in the worst case 4 accesses, one of five options is the appropriate one. I am thinking that it cannot be too difficult when you know JS and its usage at the wiki-environment? -- sarang♥사랑 14:22, 2 November 2021 (UTC)
- Example: User:Username – User:UserTalkTest – User:Essjay – User:HandigeHarry – User:not_a_user
- Hi, please try User:Surjection/findUser.js and see if it works. Note that with callbacks, any code that relies on results provided by the callback must be conceptually "inside" the callback, i.e. it must be either within the callback or called by it. SURJECTION ·talk·contr·log· 15:06, 2 November 2021 (UTC)
- Thanx a lot! It looks good. I tried it, but got the same synchronisation problem - it seems that the action is not completed when the result is checked, becaue I get the result "undefined". The function is called with two parameters, the complete pagename and a returncode (namespac) 'when found' (callback function for pageExists boolean true).
function userExists(pagename, namespac) { pageExists(pagename, function(userexists) { var result = userexists ? namespac : 'Un'; callback(result); }); }
- Could you tell me what I am doing wrong ? -- sarang♥사랑 13:34, 4 November 2021 (UTC)
- Only the callback knows the result. Your userExists doesn't even take a callback so it cannot work in this scheme. With callbacks, the return value of a function is largely meaningless -- you have to use the callback and define a function that deals with the result. SURJECTION ·talk·contr·log· 18:30, 4 November 2021 (UTC)
- Could you tell me what I am doing wrong ? -- sarang♥사랑 13:34, 4 November 2021 (UTC)