Skip to content

Instantly share code, notes, and snippets.

@inabhi9
Last active May 28, 2019 11:53
Show Gist options
  • Save inabhi9/d862fcb2e67583252cec45c3bf5fb994 to your computer and use it in GitHub Desktop.
Save inabhi9/d862fcb2e67583252cec45c3bf5fb994 to your computer and use it in GitHub Desktop.
Harvest widget for Gitlab
// Grab JS injection chrome extension
// https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija
// For Gitlab v11
(function () {
var itemName = document.querySelector('.breadcrumbs-sub-title').innerText + ' - ' + document.querySelector('h2.title').innerText,
_url = document.head.querySelector("[property='og:url']").content.split('/'),
itemId = _url.slice(3).join('/'),
baseUrl = _url.slice(0, 3).join('/'),
dataItem = {id: itemId, name: itemName};
if (itemId.indexOf('issues/') < 0) return;
// Injecting button DOM
var injectedContent = document.createElement("div");
injectedContent.setAttribute("class", "harvest-timer");
injectedContent.setAttribute("data-item", JSON.stringify(dataItem));
injectedContent.style.marginTop = '10px';
document.getElementsByClassName('issuable-meta')[0].appendChild(injectedContent);
// Loading Harvest JS
window._harvestPlatformConfig = {
"applicationName": "Gitlab",
"permalink": baseUrl + "/%ITEM_ID%"
};
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "https://platform.harvestapp.com/assets/platform.js";
$("head").append(s);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment