Skip to content

Instantly share code, notes, and snippets.

@bluishoul
Last active December 28, 2018 08:08
Show Gist options
  • Save bluishoul/f02dcd5e218a6e5a3c5d26f07c79e8e6 to your computer and use it in GitHub Desktop.
Save bluishoul/f02dcd5e218a6e5a3c5d26f07c79e8e6 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Git local config
// @namespace http://tampermonkey.net/
// @version 0.1
// @include https://codingcorp.coding.net/p/*
// ==/UserScript==
function loadScripts(scripts, callback) {
const promises = [];
for (let src of scripts) {
promises.push(new Promise((resolve, reject) => {
const script = document.createElement('script');
const firstScript = document.getElementsByTagName('script')[0];
script.async = 1;
script.src = src
script.onload = resolve;
firstScript.parentNode.insertBefore(script, firstScript);
}));
}
return Promise.all(promises);
}
loadScripts([
'https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js',
'https://cdn.bootcss.com/clipboard.js/2.0.4/clipboard.min.js'
]).then(async function onload() {
const user = (await jQuery.get('/api/current_user')).data;
function appentGitLocalConfig() {
const gitLocalConfig = `git config --local user.name "${user.name}"
git config --local user.email "${user.email}"`;
const pre = jQuery('[class^="project-right-box"]:last').parent().append(
`<pre style="position: absolute; right: 0; padding: 20px 0 20px 10px; margin: 0; font-size: 12px; height: 300px;">
<code id="git-local-config" style='font-family: Menlo, Consolas, "DejaVu Sans Mono", monospace; cursor: copy;'>${gitLocalConfig}</code>
</pre>`);
const code = document.querySelector('#git-local-config');
new ClipboardJS(code, {
text: function handleClick() {
code.style.color = 'green';
code.style.cursor = 'default';
setTimeout(() => {
code.style.color = 'inherit';
code.style.cursor = 'copy';
}, 600);
return gitLocalConfig;
}
});
}
setTimeout(appentGitLocalConfig, 2000)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment