// ==UserScript== // @name 用Sourcegraph浏览Github项目 // @author billypon // @description 浏览github项目的时候添加sourcegraph的链接 // @version 1.0.2 // @namespace http://www.canaansky.com/ // @match https://github.com/*/* // @run-at document-idle // @downloadURL https://update.greasyfork.icu/scripts/398190/%E7%94%A8Sourcegraph%E6%B5%8F%E8%A7%88Github%E9%A1%B9%E7%9B%AE.user.js // @updateURL https://update.greasyfork.icu/scripts/398190/%E7%94%A8Sourcegraph%E6%B5%8F%E8%A7%88Github%E9%A1%B9%E7%9B%AE.meta.js // ==/UserScript== const actions = document.querySelector('.pagehead-actions'); if (actions) { const button = document.createElement('button'); button.className = 'btn btn-sm'; button.innerHTML = ''; button.onclick = function () { const array = location.pathname.split('/'); if (array.length) { const menu = document.querySelector('#branch-select-menu .btn'); const target = menu && menu.title && menu.title.indexOf('/') > 0 ? menu.title : array[4]; if (target) { array.splice(3, target.split('/').length + 1, '-', array[3]); array[2] += `@${ target }`; } } location.href = `https://sourcegraph.com/github.com${ array.join('/') }`; } const action = document.createElement('li'); action.append(button); actions.prepend(action); }