User talk:Surjection

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Welcome to Wikimedia Commons, Surjection!

-- Wikimedia Commons Welcome (talk) 19:46, 10 January 2018 (UTC)[reply]

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)[reply]

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)[reply]
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)[reply]
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)[reply]
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)[reply]
Example: User:UsernameUser:UserTalkTestUser:EssjayUser: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)[reply]
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)[reply]
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)[reply]