Skip to content

Instantly share code, notes, and snippets.

@LucasLarson
Last active November 25, 2019 23:13
Show Gist options
  • Save LucasLarson/38333fea685fb2db75ce0b125680d7c9 to your computer and use it in GitHub Desktop.
Save LucasLarson/38333fea685fb2db75ce0b125680d7c9 to your computer and use it in GitHub Desktop.
www±: A bookmarklet to toggle between a website’s 𝚠𝚠𝚠 and 𝚗𝚘-𝚠𝚠𝚠 URIs
/**
* www±
* v. 0.1
*
* Description: This is the JavaScript behind a bookmarklet to move back and
* forth between the 𝚠𝚠𝚠 and 𝚗𝚘-𝚠𝚠𝚠 versions of a
* website’s URI.
*
* Installation: See bottom
*
*/
/* eslint-env browser */
'use strict'
var url = location.href
if (location.href.includes('://www.')) {
url = url.replace('://www.', '://')
window.open(url, '_self')
} else {
url = url.replace('://', '://www.')
window.open(url, '_self')
}
// Installing bookmarklets is famously tricky (see
// https://mreidsma.github.io/bookmarklets/installing), but when you’re ready,
// the URI to enter into the bookmark’s address field is everything on the line
// between the /* and the */
/*
javascript:'use%20strict';var%20url=location.href;location.href.includes('://www.')?(url=url.replace('://www.','://'),window.open(url,'_self')):(url=url.replace('://','://www.'),window.open(url,'_self'))
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment