From 1ea8dae60cc8181785fcbc7e57a110ad88a17117 Mon Sep 17 00:00:00 2001 From: Index Date: Sun, 14 Jul 2024 16:36:18 -0500 Subject: [PATCH] feat: add "Copy Thread ID" context menu item --- js/background.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/js/background.js b/js/background.js index 85a8ffa..9aaf6ad 100755 --- a/js/background.js +++ b/js/background.js @@ -444,6 +444,15 @@ chrome.contextMenus.removeAll(function () { 'https://polytoria.com/guilds/**' ] }); + chrome.contextMenus.create({ + title: 'Copy Thread ID', + id: 'PolyPlus-CopyThreadID', + contexts: ['link'], + documentUrlPatterns: ['https://polytoria.com/*', SettingsURL], + targetUrlPatterns: [ + 'https://polytoria.com/forum/post/**' + ] + }); // COPY AVATAR HASH CONTEXT MENU ITEM REGISTRATION chrome.contextMenus.create({ @@ -460,12 +469,21 @@ chrome.contextMenus.removeAll(function () { // HANDLE CONTEXT MENU ITEMS chrome.contextMenus.onClicked.addListener(async function (info, tab) { if (["CopyPlaceID", "CopyUserID", "CopyItemID", "CopyGuildID"].indexOf(info.menuItemId.split('-')[1]) !== -1) { - console.log(info.linkUrl.split('/')[3]); let ID = info.linkUrl.split('/')[4]; if (info.linkUrl.split('/')[3] === 'u') { ID = (await (await fetch('https://api.polytoria.com/v1/users/find?username=' + info.linkUrl.split('/')[4])).json()).id; } - console.log(ID); + chrome.scripting + .executeScript({ + target: {tabId: tab.id}, + func: CopyAssetID, + args: [ID] + }) + .then(() => console.log('Copied ID!')); + } + + if (info.menuItemId === 'PolyPlus-CopyThreadID') { + let ID = info.linkUrl.split('/')[5]; chrome.scripting .executeScript({ target: {tabId: tab.id},