Last active
June 4, 2025 16:09
-
-
Save william-andre/16524e22be84bb177bb5a97819c3fa18 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// ==UserScript== | |
// @name Github Autolink | |
// @namespace http://odoo.com/ | |
// @icon https://odoo.com/web/static/img/favicon.ico | |
// @version 2025-01-10 | |
// @description AutoLink for Odoo | |
// @author [email protected] | |
// @match https://github.com/odoo/* | |
// @grant none | |
// ==/UserScript== | |
const AUTOLINKS = [ | |
['upg-', 'https://upgrade.odoo.com/web#model=upgrade.request&id='], | |
['opw-', 'https://www.odoo.com/odoo/all-tasks/'], | |
['task-', 'https://www.odoo.com/odoo/all-tasks/'], | |
['runbot-', 'https://runbot.odoo.com/odoo/action-573/'], | |
] | |
function githubAutoLinkNode(rootNode) { | |
for (let [prefix, url] of AUTOLINKS) { | |
let xpath = `.//p[contains(., '${prefix}')]`; | |
let references = document.evaluate(xpath, rootNode, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null); | |
for (let i = 0; i < references.snapshotLength; i++) { | |
let node = references.snapshotItem(i); | |
node.innerHTML = node.innerHTML.replaceAll(new RegExp(`\\b${prefix}(\\d+)`, 'g'), (full, taskId) => { | |
return `<a href="${url}${taskId}">${full}</a>` | |
}); | |
} | |
} | |
} | |
function dynamicBody(func) { | |
func(document.body); | |
new MutationObserver((mutationsList, observer) => { | |
for (let mutation of mutationsList) { | |
func(mutation.target); | |
} | |
}).observe(document.body, { childList: true, subtree: true }); | |
} | |
dynamicBody(githubAutoLinkNode); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
By renaming it to *.user.js - it works on chrome too, just drag and drop to chrome://extensions/