Skip to content

Commit

Permalink
Merge pull request #6 from steffenbew/main
Browse files Browse the repository at this point in the history
fix(main.js): fix wrong pulseId detection for post urls
  • Loading branch information
timohubois authored Jul 16, 2024
2 parents 8225d90 + 5a4e521 commit 8da5b16
Showing 1 changed file with 44 additions and 24 deletions.
68 changes: 44 additions & 24 deletions scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ async function maybeAddTimerButtonToPulse () {

const pulseActionsWrapper = document.querySelector('.pulse_actions_wrapper')
if (!pulseActionsWrapper) {
setTimeout(await maybeAddTimerButtonToPulse(), 3000)
setTimeout(await maybeAddTimerButtonToPulse, 3000)
return
}
pulseActionsWrapper.insertAdjacentHTML('beforeend', styles)
Expand Down Expand Up @@ -253,30 +253,50 @@ async function addTimerButtonAttributes (element, returnElement = true) {
}
}

async function getDataFromMonday () {
const path = window.location.pathname
const urlBase = new URL(window.location.href).origin

const selectedProject = document.querySelector('.home-control-base-item-component.selected')
const projectName = selectedProject?.querySelector('.text-with-highlights > span')?.textContent || ''

const pulseNameElement = document.querySelector('.pulse_title h2')
const pulseName = pulseNameElement?.textContent || ''

const pulseId = path.substring(path.lastIndexOf('/') + 1) || ''
const boardId = path.split('/')[2] || ''

const permalink = (urlBase && boardId && pulseId)
? `${urlBase}/boards/${boardId}/pulses/${pulseId}`
: (urlBase && boardId && pulseId) ? `${urlBase}/boards/${boardId}` : ''

if (path.includes('/pulses/')) {
return { projectName, pulseName, pulseId, boardId, permalink }
} else if (path.includes('/boards/')) {
return { projectName, pulseName: 'Miscellaneous > REPLACE_THIS_WITH_A_DESCRIPTION', pulseId: 'miscellaneous', boardId, permalink }
} else {
return {}
async function getDataFromMonday() {
const path = window.location.pathname;
const urlBase = new URL(window.location.href).origin;

// Initialize default values
let projectName = '';
let pulseName = 'Miscellaneous > REPLACE_THIS_WITH_A_DESCRIPTION';
let pulseId = 'miscellaneous';
let boardId = '';
let permalink = '';

// Extract boardId and pulseId from path
const pathRegex = /\/boards\/(\d+)\/?.*\/pulses\/(\d+)/;
const pathMatch = path.match(pathRegex);

if (pathMatch) {
boardId = pathMatch[1];
pulseId = pathMatch[2];

// Fetch projectName
const selectedProjectElement = document.querySelector('#mf-header h2');
projectName = selectedProjectElement?.textContent || '';

// Fetch pulseName
const pulseNameElement = document.querySelector('.pulse_title h2');
pulseName = pulseNameElement?.textContent || '';

// Construct permalink
if (boardId) {
if (pulseId) {
permalink = `${urlBase}/boards/${boardId}/pulses/${pulseId}`;
} else {
permalink = `${urlBase}/boards/${boardId}`;
}
}
}

return {
projectName,
pulseName,
pulseId,
boardId,
permalink
};
}

async function updateStorage () {
Expand Down

0 comments on commit 8da5b16

Please sign in to comment.