Skip to content

Commit

Permalink
recreated midi and mp3 logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ingui-n committed Feb 6, 2024
1 parent 0ea1a18 commit 66c6b1f
Show file tree
Hide file tree
Showing 4 changed files with 347 additions and 28 deletions.
30 changes: 26 additions & 4 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,41 @@ browser.webRequest.onSendHeaders.addListener(

const id = matchMedia[1];
const index = matchMedia[2];
console.log(index)
const type = matchMedia[3];

if (authHeader) {
const token = authHeader.value;

const tab = await updateCurrentTab();
try {
await browser.tabs.sendMessage(tab.id, {scoreData: [`${id}_${type}_${index}`, token]}).catch(() => null);
} catch (e) {}
await browser.tabs.sendMessage(tab.id, {scoreData: [`${id}_${type}_${index}`, token]});
}
}
},
{
urls: ['https://musescore.com/api/jmuse?id=*&index=*&type=*']
urls: ['https://musescore.com/api/jmuse?id=*&index=*&type=*']//todo test url by params
}, ['requestHeaders']
);

browser.webRequest.onSendHeaders.addListener(
async ({url}) => {
const matchMedia = url.match(/^https:\/\/s3\.ultimate-guitar\.com\/musescore\.scoredata\/g\/\w+\/score_?(\d+)?\.(\w{3})/);

if (matchMedia) {
const urlParams = new URLSearchParams(new URL(url).search);
const date = new Date();
const expires = urlParams.get('X-Amz-Expires');

date.setSeconds(date.getSeconds() + Number(expires));

const index = matchMedia[1] || 0;
const type = matchMedia[2] === 'png' || 'svg' ? 'img' : matchMedia[2];

const tab = await updateCurrentTab();
await browser.tabs.sendMessage(tab.id, {scoreDataUrl: [`${type}_${index}`, {url, expiration: date.toISOString()}]});
}
},
{
urls: ['https://s3.ultimate-guitar.com/musescore.scoredata/g/*/score*']
}
);
Loading

0 comments on commit 66c6b1f

Please sign in to comment.