Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 15 additions & 68 deletions pr2markdown.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,70 +46,6 @@
}
};

// Inject CSS styles
function injectStyles() {
const css = `
/* PR to Markdown Extension Styles */

.pr2md-copy-btn {
background: #f6f8fa;
border: 1px solid #d1d9e0;
border-radius: .5rem;
color: #24292f;
cursor: pointer;
font-size: 14px;
padding: 0 12px;
margin-left: 8px;
transition: all 0.2s ease;
display: inline-flex;
max-height: 32px;
align-items: center;
}

.pr2md-copy-btn:hover {
background: #f3f4f6;
border-color: #c7d2fe;
}

.pr2md-copy-btn:active {
background: #e5e7eb;
transform: translateY(1px);
}

/* GitLab Light Theme */
html.gl-light .pr2md-copy-btn {
background-color: #fff;
border: 1px solid #bfbfc3;
}

html.gl-light .pr2md-copy-btn:hover {
background-color: #ececef;
border-color: #89888d;
}

html.gl-light .pr2md-copy-btn:active {
background-color: rgba(137, 136, 141, 0.32);
}

/* GitLab Dark Theme */
html.gl-dark .pr2md-copy-btn {
background-color: rgba(137, 136, 141, 0.4);
border: 1px solid transparent;
}

html.gl-dark .pr2md-copy-btn:hover {
background-color: rgba(137, 136, 141, 0.64);
}

html.gl-dark .pr2md-copy-btn:active {
background-color: rgba(137, 136, 141, 0.32);
}
`;
const style = document.createElement('style');
style.textContent = css;
document.head.appendChild(style);
}

/**
* @typedef {"github" | "gitlab"} Platform
*/
Expand Down Expand Up @@ -237,6 +173,18 @@ html.gl-dark .pr2md-copy-btn:active {
}
}

/**
* @param {Platform} platform
*/
function getButtonClassNamesByPlatform(platform) {
switch (platform) {
case "github":
return "btn-sm btn";
case "gitlab":
return "gl-button btn btn-md btn-default gl-hidden @sm/panel:gl-inline-flex gl-self-start";
}
}

/**
* @param {Platform} platform
*/
Expand All @@ -247,7 +195,7 @@ html.gl-dark .pr2md-copy-btn:active {
}
logger.debug(`On MR page for platform: ${platform}`);

if (document.querySelector(".pr2md-copy-btn")) {
if (document.getElementById("pr2md-copy-btn")) {
logger.debug("Button already exists")
return;
}
Expand All @@ -262,7 +210,8 @@ html.gl-dark .pr2md-copy-btn:active {
logger.debug("Found action section:", actionSection);

const button = document.createElement("button");
button.className = "pr2md-copy-btn";
button.id = "pr2md-copy-btn";
button.className = getButtonClassNamesByPlatform(platform);
button.textContent = "📋";
button.title = "Copy PR as Markdown";

Expand Down Expand Up @@ -297,8 +246,6 @@ html.gl-dark .pr2md-copy-btn:active {
}

function init() {
injectStyles();

logger.info("Userscript loaded on", window.location.href);

const platform = detectPlatform();
Expand Down