Skip to content

Instantly share code, notes, and snippets.

@asahasrabuddhe
Created May 30, 2023 08:36
Show Gist options
  • Save asahasrabuddhe/f58cfac71122e82aa9f4c5175052c2c5 to your computer and use it in GitHub Desktop.
Save asahasrabuddhe/f58cfac71122e82aa9f4c5175052c2c5 to your computer and use it in GitHub Desktop.
Arc Boost for GitHub (Copy Monday Button)
// This script injects an element at the top of the page.
// It doesn't work yet. To make it work, handle the TODO.
const button = {
name: 'Copy for Monday',
id: 'copyForMonday',
classList: [
'flex-md-order-2', 'Button--secondary', 'Button--small', 'Button', 'm-0', 'mr-md-0'
],
onclick: () => {
const branch = document.querySelectorAll('span.commit-ref > a > span')[1].innerText;
const pr = window.location.href;
var richText = `
<b>Branch:</b> ${branch}<br/>
<b>PR:</b> ${pr}<br/><br/>
<b>Test Instructions:</b><br/><br/>
<b>Affected Partners to be tested:</b> </i>[All Partners / OAS / OASAM / YSC / ISEF / SigmaXi / ENG / Make/ Self Serve]</i><br/>
<b>Cross-browser/device test required:</b> <i>Yes/No</i><br/>
<b>Any instructions for deploying branch:</b> <i>eg. any script/runner needs to run</i><br/><br/>
<b>If code involves db changes, specify tables/columns affected:</b><br/><br/>
<b>Other instructions:</b> <br/>`;
var tempElement = document.createElement('div');
tempElement.innerHTML = richText;
// Create a range to select the content
const clipboardItem = new ClipboardItem({
"text/plain": new Blob(
[tempElement.innerText],
{ type: "text/plain" }
),
"text/html": new Blob(
[tempElement.outerHTML],
{ type: "text/html" }
),
});
navigator.clipboard.write([clipboardItem]);
}
}
setInterval(function() {
if (window.location.href.includes('pull') && document.getElementById(button.id) === null) {
const element = document.createElement("button");
button.classList.forEach(className => element.classList.add(className));
element.id = button.id;
element.innerText = button.name;
element.onclick = button.onclick;
const headerActions = document.getElementsByClassName('gh-header-actions');
headerActions[0].prepend(element);
}
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment