-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathe.js
More file actions
84 lines (79 loc) · 2.88 KB
/
e.js
File metadata and controls
84 lines (79 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// ==UserScript== //
// @name opw_github
// @match *://github.com/odoo/*
// @match *://github.com/odoo-dev/*
// @match *://github.com/pulls/*
// ==/UserScript==
const insertAfter = (new_node, ref_node) => {
ref_node.parentNode.insertBefore(new_node, ref_node.nextSibling);
}
window.navigation.addEventListener('navigate', (event) => {
if (event.destination.url.match(/github\.com\/odoo(-dev)?/)) {
setTimeout(opwHandle, 1400);
}
});
const addOPWCopyButton = () => {
if (document.querySelector('.opw-copy')) return;
document.querySelectorAll('div[class^="prc-PageHeader-Description"] button[data-component="IconButton"]').forEach(el => {
const el_copy = el.cloneNode(true);
const svg = el_copy.querySelector('svg');
svg.style.color = 'green';
el_copy.classList.add('opw-copy');
el.parentElement.appendChild(el_copy);
el_copy.onclick = () => {
navigator.clipboard.writeText(document.querySelectorAll('a[class^="PullRequestBranchName-module__truncateBranch"]')[1].getAttribute('href').split('/').slice(-1)[0]);
svg.style.color = 'blue';
}
});
}
const addOPWLinks = () => {
const treat = node => {
switch(node.nodeType) {
case 3:
break;
case 1:
for (let i = node.childNodes.length - 1; i >= 0; i--) {
treat(node.childNodes[i]);
}
default:
return;
}
const oval = node.nodeValue;
if (!/opw|task/i.test(oval)) {
return;
}
let done_offset = 0;
oval.replace(/\b((?:opw|task)(?: id)?[: #-] ?)(\d{5,})\b/gi, function(match, prefix, num, offset) {
const link = document.createElement("a");
num = prefix[0].toLowerCase() == 'o' && num < 1E6 ? 1E6 + +num : num;
link.setAttribute("href", "https://www.odoo.com/web#id=" + num + "&view_type=form&model=project.task");
link.appendChild(document.createTextNode(num));
node.nodeValue = oval.slice(done_offset, offset + prefix.length);
done_offset = offset + match.length;
insertAfter(link, node);
node = document.createTextNode(oval.slice(done_offset));
insertAfter(node, link);
});
}
document.querySelectorAll(".comment-body:not([data-opw-handled]),.commit-desc:not([data-opw-handled]),span[class^='Text__StyledText-sc'].text-mono").forEach(n => {
n.setAttribute('data-opw-handled', 1);
treat(n)
})
}
const addCommitDirectClick = () => {
if (document.querySelector('a.TabNav-item.selected[href$="/commits"]')) {
let commits = document.querySelectorAll('[data-testid="commit-row-item"]');
if (commits.length === 1) {
commits[0].querySelector('a').click();
}
}
}
function opwHandle () {
//replace opw-1234 by a link to the odoo.comtask:
addOPWLinks();
//add copy to clipboard button without remote:
addOPWCopyButton();
//direct click on commit tab if only one commit
addCommitDirectClick();
}
window.addEventListener('turbo:load', opwHandle);