Wikipedia talk:User scripts

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Preview edits by a userscript[edit]

A userscript can automatically generate and publish an edit using mw.Api.postWithEditToken(...). This is possible to do from any Wikipedia page to any remote Wikipedia page.

Portlet links which use WP:TemplateScript allow to generate and preview an edit for a page, currently opened in the wikitext editor.

Is there any way for a userscript to show a preview for an automatic edit for a remote page? My particular use case is generating an edit to another user's talk page from their contributions page. That is, a portlet link on a page like Special:Contributions/Example should load a preview with an edit of User talk:Example. —⁠andrybak (talk) 15:40, 10 February 2024 (UTC)[reply]

Use parse API. Here's how Twinkle does it. If you want to be thorough, you can use MW's native live preview API. Nardog (talk) 19:49, 10 February 2024 (UTC)[reply]
Nardog, thank you for the pointer, I'll look into it. Is there anything that allows opening the native editor on the remote page? Similar to how preload templates work? —⁠andrybak (talk) 19:56, 10 February 2024 (UTC)[reply]
You mean you want to open the remote page with certain wikitext instead of the current content? If so you can attach a form element and submit it, e.g.
$('<form>').attr({
	method: 'post',
	action: mw.util.getUrl('Wikipedia:Sandbox', { action: 'edit' }),
	enctype: 'multipart/form-data'
}).append(
	$('<input>').attr({
		name: 'wpTextbox1',
		type: 'hidden'
	}).val('foo')
).appendTo(document.body).trigger('submit').remove();
(There doesn't seem to be a way to suppress the preview.) Nardog (talk) 20:50, 10 February 2024 (UTC)[reply]
Come to think of it, a simpler way is to just store the text in e.g. sessionStorage, open the page the normal way, and modify the textbox (use jquery.textSelection). Nardog (talk) 20:59, 10 February 2024 (UTC)[reply]
Re: There doesn't seem to be a way to suppress the preview. – here are tweaked fields of the form to mimic "Show changes" instead of "Show preview":
/* the data of the edit */
$('<input>').attr({
	name: 'wpTextbox1',
	type: 'hidden'
}).val(newWikitext),
$('<input>').attr({
	name: 'wpSummary',
	type: 'hidden'
}).val(editSummary),

/* show as a diff */
$('<input>').attr({
	name: 'wpDiff',
	type: 'hidden'
}).val(true),

/* wpUltimateParam is needed to avoid the scary error
 * "Some parts of the edit form did not reach the server" */
$('<input>').attr({
	name: 'wpUltimateParam',
	type: 'hidden'
}).val(1)
Just in case anyone else will find it useful. —⁠andrybak (talk) 21:46, 10 February 2024 (UTC)[reply]

CSS items[edit]

@Nardog I mean, that's what User:BrandonXLF/GreenRedirects is. I don't see why it'd be a worse idea than JS, which can actually compromise one's browser. Aaron Liu (talk) 02:54, 21 February 2024 (UTC)[reply]

It's not. common.css and global.css are loaded automatically for the owners and they can put or remove whatever they want there at any time. If you intend some styles to be imported by other users, you should host it as a separate page. Nardog (talk) 03:01, 21 February 2024 (UTC)[reply]
Also, importing an external CSS via JS causes FOUCs. Using @import doesn't, but can delay first paint. Nardog (talk) 06:12, 21 February 2024 (UTC)[reply]
Speaking about that... my @import doesn't seem to be working right now :p Aaron Liu (talk) 16:07, 21 February 2024 (UTC) Fixed that now! Aaron Liu (talk) 03:05, 22 February 2024 (UTC)[reply]

Highlight username[edit]

Hey, do we have a script which can highlight your own username in a page? I remember seeing something similar a while ago but can't find that now. Can sormeone link it please? Thanks. — The Herald (Benison) (talk) 05:35, 25 February 2024 (UTC)[reply]

@The Herald: Not sure if there's a script, but a userscript wouldn't be super necessary; you could just put this in Special:MyPage/common.css:
a[href$="User:The_Herald"] { background-color:#FFFF00; }
Change the username in quotes to change which page gets highlighted, and change the "FFFF00" to any other hex color code to change the color of the highlight.
EDIT:After rereading, I think I misunderstood your ask; the above will highlight any links to your user page (as in your signature or any pings to you), but not any mere use of your username. That *would* require a script. Writ Keeper  13:45, 25 February 2024 (UTC)[reply]
I think I'll give it a ago. I just want my name to get highlighted, especially in AfD discussions, just to avoid double !votes or avoid WP:INVOLVED when I'm closing discussions. Hope it will work for that. Thanks. The Herald (Benison) (talk) 14:06, 25 February 2024 (UTC)[reply]
Update: It works just how I wanted. Thanks a lot. The Herald (Benison) (talk) 14:09, 25 February 2024 (UTC)[reply]

Navigation arrows in WP:USL[edit]

Which tool was used for installing the navigation arrows colored light blue in the top bottom right corner with url params "#top" and "#skip-to-bottom-anchor" [1]?Qwerty284651 (talk) 05:50, 29 May 2024 (UTC)[reply]

@Qwerty284651: It's {{Skip to top and bottom}}. --Redrose64 🌹 (talk) 16:39, 29 May 2024 (UTC)[reply]
@Redrose64, thanks. Qwerty284651 (talk) 16:48, 29 May 2024 (UTC)[reply]