User talk:Awesome Aasim/noeditredlinks.js
Fix handling of red links to different wikis edit
In Wikipedia:Village pump (technical)#File bug with authors who have redlinks and in T345981, it was reported that this script breaks red links to different wikis, e.g. the links to non-existent user pages on Commons in file descriptions.
To fix this, instead of figuring out the link target yourself with window.location.origin + $(this).attr("href")
etc. (which will not work correctly if the href
is not relative), you can ask the browser to do it with $(this).prop("href")
. The difference between these two methods is that attr
accesses the original HTML attributes, while prop
accesses the properties computed based on these attributes – here's a short post with more details about this and more examples of differences: [1]
By the way, you can avoid duplicating the script code by combining the two selectors into a.new, .new a
.
Overall, I would suggest modifying the code as follows:
// this script will remove editing from every redlink
$(document).ready(function() {
window.setInterval(()=> {
$('a.new, .new a').each(function() {
if (new URL($(this).prop("href")).searchParams.get("action")) {
$(this).attr("href", function() {var url = new URL($(this).prop("href"));url.searchParams.delete("action");return url;});
}
});
}, 100);
});
Matma Rex talk 22:24, 9 September 2023 (UTC)
- Courtesy ping: Awesome Aasim QuickQuokka [talk • contribs] 09:43, 10 September 2023 (UTC)
- Done thanks! Aasim - Herrscher of Wikis ❄️ 01:38, 11 September 2023 (UTC)