Skip to content

Instantly share code, notes, and snippets.

@HybridEidolon
Last active September 17, 2022 18:35
Show Gist options
  • Save HybridEidolon/49630e04ac5c452802594f656be57a25 to your computer and use it in GitHub Desktop.
Save HybridEidolon/49630e04ac5c452802594f656be57a25 to your computer and use it in GitHub Desktop.
Wowhead TSM Group Button UserScript
// ==UserScript==
// @name Wowhead TSM Group Generator
// @namespace https://gist.github.com/HybridEidolon
// @description Adds a TSM Group button to copy the search results as a legacy TSM group import string
// @author Eidolon
// @version 2
// @grant none
// @match https://*.wowhead.com/items*
// @match https://*.wowhead.com/wotlk/items*
// @noframes
// @run-at document-idle
// ==/UserScript==
function ___wh_tsm_mapper_injected() {
function generateGroup() {
let items = window.g_listviews.items.data;
let itemIds = items.map((item) => item.id);
let groupStringItems = idListToGroupString(itemIds);
return groupStringItems;
}
function idListToGroupString(idList) {
return 'group:Wowhead Export,i:' + idList.join(',i:');
}
function generateAndCopyGroup(event) {
let groupString = generateGroup();
navigator.clipboard.writeText(groupString)
.then(
() => {},
(err) => { alert(err); },
);
}
let insertEl = document.querySelector('div.listview-withselected');
let generateButton = document.createElement('button');
generateButton.innerText = 'TSM Group';
insertEl.appendChild(generateButton);
generateButton.addEventListener('click', generateAndCopyGroup);
}
let script = document.createElement('script');
script.textContent = `(${___wh_tsm_mapper_injected.toString()})()`;
document.body.appendChild(script);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment