Jump to content

User talk:Awesome Aasim/noeditredlinks.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
[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)[reply]

Courtesy ping: Awesome Aasim QuickQuokka [⁠talkcontribs] 09:43, 10 September 2023 (UTC)[reply]
 Done thanks! Aasim - Herrscher of Wikis ❄️ 01:38, 11 September 2023 (UTC)[reply]

"action=delete" problem

[edit]

Hey @Awesome Aasim:, I noticed a potential issue in the code that might cause problems for the admins. The current logic removes the "action" parameter from URLs across the board. However, there are specific cases, like "action=delete", where we need to keep the parameter.

To address this, I updated the code to ensure that only "action" parameters with values other than "delete" are removed. Here's the updated version:

$(document).ready(function() {
	window.setInterval(() => {
		$('a.new, .new a').each(function() {
			let url = new URL($(this).prop("href"));
			let actionParam = url.searchParams.get("action");
			
			// "action=delete" is excluded from removal
			if (actionParam && actionParam !== "delete") {
				$(this).attr("href", function() {
					url.searchParams.delete("action");
					return url;
				});
			}
		});
	}, 100);
});

This change ensures that we don't remove the "delete" action, preventing potential issues for the admins. Thanks! Wooze 23:30, 23 September 2024 (UTC)[reply]

@Wooze Uhh... This script handles redlinks, which are pages that don't exist. Blue links should not be affected. Please give an example so I can try to reproduce. Awesome Aasim 00:51, 24 September 2024 (UTC)[reply]
@Awesome Aasim, I used this script on Turkish Wikipedia. When I wanted to delete a page, it wouldn't allow me. Therefore, I updated the script. Perhaps there is no such issue on English Wikipedia, but I encountered this issue on Turkish Wikipedia. Wooze 01:23, 24 September 2024 (UTC)[reply]
@Wooze Can you please give an example? This does not touch the address bar, only red links. I cannot look into it unless if you indicate which pages (URLs) it is happening on. Awesome Aasim 01:28, 24 September 2024 (UTC)[reply]