Skip to content

Commit

Permalink
it works!
Browse files Browse the repository at this point in the history
  • Loading branch information
jonfriesen committed Aug 28, 2024
1 parent af28104 commit 85537e7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
27 changes: 12 additions & 15 deletions src/content/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import clipboardMdSvg from '../assets/clipboard2.svg'
import checkmarkSvg from '../assets/checkmark.svg'
import buttonStyle from '../styles/button.css?raw'

function createIframeButton(config, formatPreference, selectedStyle) {
function createIframeButton(config, formatPreference, selectedStyle, siteConfigs) {
const iframe = document.createElement('iframe')
iframe.id = `${config.buttonId}-iframe`
iframe.className = `quickcite-button-iframe`
Expand All @@ -28,15 +28,13 @@ function createIframeButton(config, formatPreference, selectedStyle) {

// Add style to iframe
const style = iframeDoc.createElement('style')
style.textContent = buttonStyle // Assuming buttonStyle contains the full CSS content
style.textContent = buttonStyle

iframeDoc.head.appendChild(style)
iframeDoc.body.appendChild(button)

// // Populate button content
// let icon = formatPreference === 'markdown' ? clipboardMdSvg : clipboardTextSvg
// button.className = `copy-button ${selectedStyle}`
// button.innerHTML = `<img src="${chrome.runtime.getURL(icon)}" alt="Copy Info">`
// Setup the button after it's been added to the DOM
setupButton(config, button, formatPreference, selectedStyle, siteConfigs)
}

return iframe
Expand All @@ -47,19 +45,18 @@ export function injectOrUpdateButton(config, formatPreference, selectedStyle, si
let button

if (!iframe) {
iframe = createIframeButton(config, formatPreference, selectedStyle)
iframe = createIframeButton(config, formatPreference, selectedStyle, siteConfigs)
document.body.appendChild(iframe)

// Wait for iframe to load before accessing button
iframe.onload = () => {
button = iframe.contentDocument.getElementById(config.buttonId)
// TODO: This needs tos et the values on load!!
}
} else {
button = iframe.contentDocument.getElementById(config.buttonId)
button.removeEventListener('click', button.clickHandler)
if (button) {
button.removeEventListener('click', button.clickHandler)
setupButton(config, button, formatPreference, selectedStyle, siteConfigs)
}
}
}

function setupButton(config, button, formatPreference, selectedStyle, siteConfigs) {
// sets the button details
let icon = formatPreference === 'markdown' ? clipboardMdSvg : clipboardTextSvg
button.className = `copy-button ${selectedStyle}`
Expand All @@ -70,7 +67,7 @@ export function injectOrUpdateButton(config, formatPreference, selectedStyle, si
button.clickHandler = () => handleButtonClick(config, formatPreference, siteConfigs, button)

// Add the new click event listener
console.log('settings clikc handler')
console.debug('setting click handler')
button.addEventListener('click', button.clickHandler)
}

Expand Down
22 changes: 11 additions & 11 deletions src/content/sites/trello.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ const trello = {
buildPlaintext: (info, url) => `${info.boardName} - ${url}`,
},
// TODO: Add card support
card: {
urlPattern: /^https:\/\/trello\.com\/c\/[a-zA-Z0-9]+(?:\/[^\/]+)?$/,
buttonId: 'trello-card-copy-button',
getInfo: () => {
const cardName = document.querySelector('h2#js-dialog-title').textContent.trim()
const boardName = document.querySelector('h1[data-testid="board-name-display"]').textContent.trim()
return { cardName, boardName }
},
buildMarkdown: (info, url) => `[${info.cardName}](${url}) (${info.boardName})`,
buildPlaintext: (info, url) => `${info.cardName} (${info.boardName}) - ${url}`,
},
// card: {
// urlPattern: /^https:\/\/trello\.com\/c\/[a-zA-Z0-9]+(?:\/[^\/]+)?$/,
// buttonId: 'trello-card-copy-button',
// getInfo: () => {
// const cardName = document.querySelector('h2#js-dialog-title').textContent.trim()
// const boardName = document.querySelector('h1[data-testid="board-name-display"]').textContent.trim()
// return { cardName, boardName }
// },
// buildMarkdown: (info, url) => `[${info.cardName}](${url}) (${info.boardName})`,
// buildPlaintext: (info, url) => `${info.cardName} (${info.boardName}) - ${url}`,
// },
},
}

Expand Down
6 changes: 3 additions & 3 deletions src/styles/button.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
:host {
:root {
--dark-bg: #1f2937;
--dark-border: #4b5563;
--dark-hover-bg: #374151;
Expand All @@ -24,8 +24,8 @@

.copy-button {
position: fixed;
bottom: 20px;
right: 20px;
bottom: 0px;
right: 0px;
z-index: 9999;
width: 50px;
height: 50px;
Expand Down

0 comments on commit 85537e7

Please sign in to comment.