BrickLink - Navigate Between Orders

Adds buttons to quickly switch between orders on the Order Detail page.

当前为 2025-06-16 提交的版本,查看 最新版本

// ==UserScript==
// @name        BrickLink - Navigate Between Orders
// @name:en     BrickLink - Navigate Between Orders
// @namespace   Violentmonkey Scripts
// @match       https://www.bricklink.com/orderPlaced.asp*
// @match       https://www.bricklink.com/orderDetail.asp*
// @grant       none
// @version     0.1
// @author      The0x539
// @description Adds buttons to quickly switch between orders on the Order Detail page.
// @license     AGPL-3.0
// ==/UserScript==

if (location.pathname.includes('orderPlaced.asp')) {
	const elements = document.querySelectorAll('table.orders-table > * > tr:not(:first-child) > td:first-child > a');
	const ids = [...elements].map(id => id.textContent);
	ids.sort();
	localStorage.setItem('ORDER_IDS', JSON.stringify(ids));

	// TODO: Improve this to use data from past page loads rather than replacing everything with whatever was seen most recently

} else {
	const ids = JSON.parse(localStorage.getItem('ORDER_IDS') ?? '[]');

	if (ids.length < 2) return;

	const currentId = new URLSearchParams(location.search).get('ID');
	const i = ids.findIndex(v => v === currentId);
	if (i < 0) return;

	const header = document.querySelector('center > div');

	const mainHeader = header.firstElementChild;
	mainHeader.classList.replace('left', 'center');

	if (i - 1 > 0) {
		const link = document.createElement('a');
		link.href = `orderDetail.asp?ID=${ids[i-1]}`;
		link.innerHTML = '<< Previous';
		link.style.float = 'left';
		header.insertBefore(link, mainHeader);
	}
	if (i + 1 < ids.length) {
		const link = document.createElement('a');
		link.href = `orderDetail.asp?ID=${ids[i+1]}`;
		link.innerHTML = 'Next >>';
		link.style.float = 'right';
		header.insertBefore(link, mainHeader);
	}
}