Last active
April 8, 2023 03:29
-
-
Save ngseke/5d0f9ef02aa320e969768aaa8e5d888a to your computer and use it in GitHub Desktop.
Convert Wikipedia Links to Desktop Version on Google Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Wikipedia Link Converter | |
// @namespace https//ngseke.me/ | |
// @version 0.1 | |
// @description Convert Wikipedia Links to Desktop Version on Google Search | |
// @author ngseke | |
// @include /^https?\:\/\/.*.google\..*\/.*$/ | |
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== | |
// @grant none | |
// ==/UserScript== | |
(() => { | |
const pattern = /^(http|https):\/\/(.+?)m\.wikipedia\.org/g | |
const links = [...document.querySelectorAll('a')] | |
const wikipediaLinks = links.filter(link => pattern.test(link.href)) | |
const convertToDesktopVersion = url => url.replace('.m.wikipedia', '.wikipedia') | |
wikipediaLinks.forEach(link => { | |
const newHref = convertToDesktopVersion(link.href) | |
link.href = newHref | |
const cite = link.querySelector('cite')?.childNodes?.[0] | |
if (cite) { | |
const citeText = cite.nodeValue | |
const newCiteText = '😎' + convertToDesktopVersion(citeText) | |
cite.nodeValue = newCiteText | |
} | |
}) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment