// ==UserScript== // @name Gitlab, open file in phpstorm // @namespace micoli.phpstorm.openlinks // @version 0.3 // @description add a link to phpstorm in gitlab ci merge requests files // @author You // @match https://gitlab.com/* // @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('beforeEnd', ` ${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 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' ? 'inline-block' : 'none' if (element.style.display == 'inline-block') { document.getElementById("open-in-phpstorm-map").value = JSON.stringify(config); } }; const initPreferenceButton = function () { document.querySelector('.alert-wrapper').insertAdjacentHTML('afterEnd', `