Skip to content

Commit

Permalink
Colorize code
Browse files Browse the repository at this point in the history
Ok it's ugly but very easy to see

Change-Id: I994811de09dfe79c9e7451742c5b59eb8a6c2cdb
  • Loading branch information
kamaradclimber committed Sep 15, 2021
1 parent a7e6cf0 commit 4869bae
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions codify.js
Expand Up @@ -19,22 +19,41 @@
(function() {
'use strict';

var onCommitBoxAvailable = function (resolve) {
var commit_box_class = ".com-google-gerrit-client-change-CommitBox_BinderImpl_GenCss_style-text";
var e = document.querySelector(commit_box_class);
if (e && 0 < e.innerText.length) {
resolve(e);
} else {
window.setTimeout(function () {
console.log("Commit message box not visible, relaunching timer");
onCommitBoxAvailable(resolve);
var onCommitBoxAvailable = function (resolve) {
var commit_box_class = ".com-google-gerrit-client-change-CommitBox_BinderImpl_GenCss_style-text";
var e = document.querySelector(commit_box_class);
if (e && 0 < e.innerText.length) {
resolve(e);
} else {
window.setTimeout(function () {
console.log("Commit message box not visible, relaunching timer");
onCommitBoxAvailable(resolve);

}, 100);
}
}, 100);
}
}

onCommitBoxAvailable(function(element) {
var codify = function(match, backticked_code, offset, string) { return `<code>${backticked_code}</code>`; }
element.innerHTML = element.innerHTML.replaceAll(/`([^`]+)`/g, codify);
})
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
head.appendChild(style);
}


onCommitBoxAvailable(function(element) {
addGlobalStyle(`code {
padding: .2em .4em;
margin: 0;
color: bisque;
font-size: 120%;
background-color: green;
border-radius: 6px;
}`);
var codify = function(match, backticked_code, offset, string) { return `<code>${backticked_code}</code>`; }
element.innerHTML = element.innerHTML.replaceAll(/`([^`]+)`/g, codify);
})
})();

0 comments on commit 4869bae

Please sign in to comment.