User talk:Zvpunry/WikibaseEcho.js

From Wikidata
Jump to navigation Jump to search

Does not work on Chrome

[edit]

@Zvpunry @Ainali pointed out to me over Telegram that the script does not work on Google Chrome. I tried fixing it myself however I wasn't able to do so.

The problem I found is that /^(?:Q\d+)|(?:Lexeme:L\d+)|(?:Property:P\d+)$/.test(strongNode.innerText) always resolves to false, even if strongNode.innerText resolves to a valid string that should produce true from .test(). For example, if you insert the line console.log(/^(?:Q\d+)|(?:Lexeme:L\d+)|(?:Property:P\d+)$/.test("Q123")) before the if statement, it logs true. However with strongNode.innerText it logs false. Even if you check the type of strongNode.innerText it will return string so it's honestly mindblowing what is causing this. I'm guessing it could maybe have to do with strongNode.innerText not returning a string even though it says it is. Or it could be that because the DOM Node it is getting .innerText from is hidden sometimes, so it won't output the correct result. I don't know. It's really frustrating to figure out. Lectrician1 (talk) 17:53, 5 November 2022 (UTC)[reply]

The odd thing is, that the lexemes work in Chrome, but not the regular items. Ainali (talk) 19:32, 5 November 2022 (UTC)[reply]

Fix for Chrome

[edit]

@Zvpunry, Lectrician1: Hello, I found the reason this didn't work in Chrome. Chrome for some stupid reason inserts direction marks (‎ and ‏ in hex form), so the regex doesn't match.

If you replace the code with what I put phab:P45975, it should work.

Also, I would strongly suggest you rewrite the script to use mw.hook( 'ext.echo.notifications.beforeRender' ); instead of this setInterval() business. It should also make the gadget faster, so you don't have to wait for 2 seconds before labels appear. Use the following code in the browser console (and then open the notifications) to see what the hook gives you to work with:

mw.hook( 'ext.echo.notifications.beforeRender' ).add( function( first, second ) {
    console.log( 'first', first );
    console.log( 'second', second );
});

Jon Harald Søby (talk) 13:02, 29 March 2023 (UTC)[reply]

@Lectrician1, Jon Harald Søby: The code has been replaced with the content of the paste. Mahir256 (talk) 15:41, 29 March 2023 (UTC)[reply]
@Mahir256: Thank you! Jon Harald Søby (talk) 15:44, 29 March 2023 (UTC)[reply]