// ==UserScript== // @name Gitlab, open file in phpstorm // @namespace micoli.phpstorm.openlinks // @version 0.5 // @description add a link to phpstorm in gitlab ci merge requests files // @author You // @match https://gitlab.com/* // @downloadURL none // ==/UserScript== (function () { // defaults write com.google.Chrome URLWhitelist -array "phpstorm://* 'use strict'; let config = {}; let linkCounter = 0; document.querySelectorAll('a[href*="redirectFromReferer"]').forEach((link)=> { link.href = link.href+'?referer='+window.location.href }); 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 phpStormMimeLink = function(link){ const prefix = config[project] || ''; document.location = `phpstorm://open?file=${prefix}${link}`; }; document.phpStormRestApiLink = function (link) { const prefix = config[project] || ''; const hrefLink = `http://localhost:63342/api/file?file=/${prefix}${link}`; const linkWindow = window.open(hrefLink,'ee'); setTimeout(function(){ linkWindow.close(); },2); }; const openLinkInHiddenForm = function (action,parameters) { let hiddenDiv = document.getElementById('phpstorm-autoform'); if (hiddenDiv){ hiddenDiv.parentNode.removeChild(hiddenDiv); } console.log(action); document.querySelector('body').insertAdjacentHTML('beforeEnd', `
`); document.getElementById('phpstorm-autoform').submit(); }; 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 hrefLink = link.innerHTML.trim(); linkCounter++; link .closest('.js-file-title') .querySelector('div.file-header-content') .insertAdjacentHTML('beforeEnd', `