Skip to content

Instantly share code, notes, and snippets.

@azzgo
Last active April 12, 2023 00:28
Show Gist options
  • Save azzgo/0b1f52fe6d80d657a2e0c37e3e620207 to your computer and use it in GitHub Desktop.
Save azzgo/0b1f52fe6d80d657a2e0c37e3e620207 to your computer and use it in GitHub Desktop.
Excalidraw 更换默认手写体
// ==UserScript==
// @name Trello Board Information Extractor
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Extract and display Trello board information in a modal
// @author ISON
// @match https://*.trello.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
function getConfig() {
// 基准数据,所有累加以此为基准
const basic = 100;
const panels = [
{ name: 'inDev', dom: document.querySelector("#board > div:nth-child(10) > div") },
{ name: 'inQA', dom: document.querySelector("#board > div:nth-child(11) > div") },
{ name: 'ReadForShowCase', dom: document.querySelector("#board > div:nth-child(12) > div") },
];
return {
basic,
panels,
// 不在接待统计内的人员名,目前仅支持单人
excluded: ''
}
}
function getSumOfPane(el, config) {
const _inPaneCardBadges = el.querySelectorAll('.badge.plugin-color-orange');
let inPaneCardBadges = Array.prototype.slice.apply(_inPaneCardBadges);
if (config.excluded) {
inPaneCardBadges = inPaneCardBadges.filter(it=>!it.closest('.list-card-details').querySelector('.list-card-members').innerHTML.includes(config?.excluded));
}
const inPaneCardStoryPoints = inPaneCardBadges.map(it=>Number(it.textContent));
return inPaneCardStoryPoints.reduce((sum, cur) => sum + cur, 0);
}
function getSumofIteration(basic, panels, config) {
const paneSums = panels.map(panel => {
return {
name: panel.name,
sum: getSumOfPane(panel.dom, config)
};
});
const panelsStoryPoints = {};
for (let index = 0; index < paneSums.length; index++) {
const pane = paneSums[index];
panelsStoryPoints[pane.name] = paneSums.slice(index).reduce((sum, cur) => sum + cur.sum, basic);
}
return panelsStoryPoints;
}
function createModal(content) {
const modal = document.createElement('div');
modal.style.position = 'fixed';
modal.style.zIndex = '10000';
modal.style.left = '0';
modal.style.top = '0';
modal.style.width = '100%';
modal.style.height = '100%';
modal.style.overflow = 'auto';
modal.style.backgroundColor = 'rgba(0,0,0,0.4)';
modal.innerHTML = `
<div style="
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 50%;
text-align: center;
">
${content}
<br />
</div>
`;
const button = document.createElement('button');
button.style = `
background-color: #4CAF50;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
margin: 15px 2px;
cursor: pointer;
`;
button.textContent = '关闭';
button.onclick = function() {
modal.remove();
};
modal.children[0].appendChild(button);
document.body.appendChild(modal);
}
function displayModal() {
const config = getConfig()
const info = getSumofIteration(config.basic, config.panels, config);
let content = '<table style="border-collapse: collapse; width: 100%;">';
content += '<tr><th style="border: 1px solid black; padding: 8px;">Panel</th><th style="border: 1px solid black; padding: 8px;">Story Points</th></tr>';
for (const [key, value] of Object.entries(info)) {
content += `<tr><td style="border: 1px solid black; padding: 8px;">${key}</td><td style="border: 1px solid black; padding: 8px;">${value}</td></tr>`;
}
content += '</table>';
createModal(content);
}
function addButton() {
const button = document.createElement('button');
button.textContent = '展示迭代内累积信息';
button.style.position = 'fixed';
button.style.zIndex = '10000';
button.style.right = '20px';
button.style.bottom = '20px';
button.style.padding = '10px';
button.style.backgroundColor = '#0079bf';
button.style.color = 'white';
button.style.border = 'none';
button.style.cursor = 'pointer';
button.addEventListener('click', displayModal);
document.body.appendChild(button);
}
window.addEventListener('load', function() {
addButton();
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment