User:Lionel.rowe/vector-skin-desktop-only.js

{ const kv = (key, value) => { return { key, value, *[Symbol.iterator] { yield key yield value }	} }

const param = kv('useskin', 'vector')

const isMobile = => window.navigator.userAgent.includes('Mobi')

const isSameOrigin = href => new URL(href).origin === window.location.origin

const appendSkinParam = href => { const url = new URL(href)

url.searchParams.set(...param)

return url.href }

const selector = 'a[href]'

if (!isMobile) { const url = new URL(window.location.href)

if (url.searchParams.has(param.key)) { url.searchParams.delete(param.key)

window.history.replaceState({}, document.title, url.href) } else { window.history.replaceState({}, document.title, appendSkinParam(window.location.href))

window.location.reload }

document.body.addEventListener('click', e => {		const link = e.target.closest(selector)

if (link) { if (isSameOrigin(link.href) && new URL(link.href).pathname !== window.location.pathname) { e.preventDefault

const href = appendSkinParam(link.href)

if (e.ctrlKey) { window.open(href, '_blank') } else { window.location = href }			}		}	}) }

}