Scott's Bookmarklets

Bookmarklets are snippets of JavaScript code that live in your desktop browser’s bookmarks toolbar. The difference from regular bookmarks is that they perform some action when you click on them instead of taking you to a fixed web address. That could be pretty much any kind of interaction with the page you're looking at, or even modifying it.

To save a bookmarklet from below, drag its yellow button onto your bookmarks toolbar. The code for each is shown below for anyone interested in seeing how they work, but you can ignore it.

This collection was inspired by the legendary Jesse's Bookmarklets, by Jesse Ruderman, which has been online since the year 2000 and is still useful.

Facebook

Facebook gives you some ability to reduce how much their advertising system profiles you, but deliberately makes it tiresome (involving a lot of manual clicking) to try and discourage you. These bookmarklets allow you to click all the buttons at once.

Hide every recent advertiser Use on the recent advertisers page in your settings.
let seeMore = document.querySelector('div[aria-label="See More"]')
if (seeMore) seeMore.click()

setTimeout(() => {
	Array.from(document.querySelectorAll('div[aria-label="Hide Ads"]'))
		.forEach(button => button.click())
}, 500)

void 0
Remove all interest categories Use on: ad settings → categories used to reach you → interest categories. (It's impossible to link directly to that page)
let seeAll = document.querySelector('div[aria-label="See All Interests"]')
if (seeAll) seeAll.click()

setTimeout(() => {
	Array.from(document.querySelectorAll('div[aria-label="Remove"]'))
		.forEach(button => button.click())
}, 500)

void 0

Twitter

Get GIF from a tweet Use on: view of an individual tweet. Opens the animation in a new window. Note: Twitter labels them as GIFs but they're actually MP4 video files. If you want to convert them to actual GIFs, you can do it easily with FFmpeg.
(function() {
	window.open(document.getElementsByTagName('video')[0].src, 'video')
})()

Other sites: Navigation

Go to npm package Use anywhere to quickly get to an npm package page. Click to bring up a dialog box, enter the name of a package. Alternatively, highlight a package name on any page and click. This is adapted from Jesse's Google search bookmarklet.
let q = '' + (
	window.getSelection
		? window.getSelection()
		: document.getSelection
			? document.getSelection()
			: document.selection.createRange().text
		)

if (!q) q = prompt('Enter an npm package name', '')

if (q !== null) location = 'https://npmjs.com/package' + escape(q).replace(/ /g, '+')

void 0
See in Wayback Machine Use on: any web page.
location = 'http://wayback.archive.org/web/*/' + location
Previous month Next month Use on: email list archive monthly view pages with yyyyMmm dates in their URLs, as produced by some variety of old archivers. Those pages don’t have links to the previous and next month, so these bookmarklets let you navigate between them.

The buttons below demonstrate how the bookmarklets change the date in the URL for one of those pages.

https://lists.w3.org/Archives/Public/www-style/1996Dec/thread.html

const monthsIndex = new Map();

[ ...Array(12).keys() ]
	.map(monthNum =>
		new Date(0, monthNum).toLocaleString('en', { month: 'short' })
	)
	.forEach((month, index) => {
		monthsIndex.set(month, index + 1)
		monthsIndex.set(index + 1, month)
	})

function changeMonth (input, dir) {
	const incOrDec = val => dir === 'next' ? ++val : --val

	let [ , year, month ] = input.match(/(.{4})(.{3})/)

	let index = monthsIndex.get(month)

	if ((dir === 'prev' && index === 1) || (dir === 'next' && index === 12)) {
		index = index === 12 ? 1 : 12
		year = incOrDec(year)
	} else
		index = incOrDec(index)

	return `${year}${monthsIndex.get(index)}`
}

const yearAndMonth = document.URL.match(/(\d{4}...)/)[0];

if (yearAndMonth)
	document.location.href = document.URL.replace(yearAndMonth, changeMonth(yearAndMonth, 'next'))