// ==UserScript== // @name Gitlab, open file in phpstorm // @namespace micoli.phpstorm.openlinks // @version 0.1 // @description add a link to phpstorm in gitlab ci merge requests files // @author You // @match https://gitlab.com/*/-/merge_requests/* // @grant none // @downloadURL none // ==/UserScript== // defaults write com.google.Chrome URLWhitelist -array "phpstorm://* (function () { 'use strict'; let config = {}; const project = $('nav.breadcrumbs ul.js-breadcrumbs-list li a')[1].pathname; const loadPreferences = function () { if (!window.localStorage.getItem('openInPhpStormSettings')) { return {}; } config = JSON.parse(window.localStorage.getItem('openInPhpStormSettings')); } const savePreferences = function () { window.localStorage.setItem('openInPhpStormSettings', JSON.stringify(config)) removeLinks(); setLinks(); } const icon = function (color) { return ` ` }; const setLinks = function(){ document.querySelectorAll('.file-header-content .file-title-name:not(.rgx-add-phpstorm-done)').forEach(function (link) { link.className = link.className + ' rgx-add-phpstorm-done'; const prefix = config[project] || ''; link.closest('.js-file-title').querySelector('div.file-header-content').insertAdjacentHTML('afterEnd', ` ${icon()} `); }); } const removeLinks = function(){ document.querySelectorAll('.js-edit-in-phpstorm').forEach(function (v) { v.parentElement.removeChild(v); }); document.querySelectorAll('.file-header-content .file-title-name').forEach(function (v) { v.class = v.class.replace(/rgx-add-phpstorm-done/, ''); }); } const initPreferenceButton = function () { const isConfigurationValid = function(){ try{ JSON.parse(document.getElementById("open-in-phpstorm-map").value); return true; }catch(e){ return false; } }; const togglePref = function () { var element = document.getElementById('open-in-phpstorm-settings'); element.style.display = element.style.display == 'none' ? 'block' : 'none' if (element.style.display == 'block') { document.getElementById("open-in-phpstorm-map").value = JSON.stringify(config); } }; document.querySelector('.merge-request-tabs-container').insertAdjacentHTML('beforeEnd',` `); document.querySelector('.mr-version-controls .inline-parallel-buttons').insertAdjacentHTML('afterEnd',` `); document.getElementById('js-btn-open-in-phpstorm-settings').addEventListener('click', function () { togglePref(); return false; }); document.getElementById('js-btn-save-in-phpstorm-settings').addEventListener('click', function () { if(isConfigurationValid()){ togglePref(); config = JSON.parse(document.getElementById("open-in-phpstorm-map").value); savePreferences(); } return false; }); } loadPreferences(); setLinks(); window.setTimeout(initPreferenceButton, 1500); window.setInterval(setLinks, 1500); })();