|
| 1 | +// ==UserScript== |
| 2 | +// @name Open in Codeflow |
| 3 | +// @namespace http://tampermonkey.net/ |
| 4 | +// @homepageURL https://github.com/antfu/open-in-codeflow |
| 5 | +// @supportURL https://github.com/antfu/open-in-codeflow |
| 6 | +// @namespace https://greasyfork.org/en/scripts/ |
| 7 | +// @version 0.1 |
| 8 | +// @description try to take over the world! |
| 9 | +// @author Anthony Fu |
| 10 | +// @license MIT |
| 11 | +// @match https://github.com/** |
| 12 | +// @icon https://www.google.com/s2/favicons?sz=64&domain=pr.new |
| 13 | +// @grant none |
| 14 | +// ==/UserScript== |
| 15 | + |
| 16 | +(function () { |
| 17 | + 'use strict' |
| 18 | + |
| 19 | + const id = 'open-in-codeflow' |
| 20 | + |
| 21 | + function createButton() { |
| 22 | + const a = document.createElement('a') |
| 23 | + a.href = location.href.replace('https://github.com/', 'https://pr.new/') |
| 24 | + a.target = '_blank' |
| 25 | + a.classList.add('btn') |
| 26 | + a.classList.add('btn-sm') |
| 27 | + a.innerText = ' Codeflow ' |
| 28 | + a.id = id |
| 29 | + const icon = document.createElement('img') |
| 30 | + // TODO: update the logo? |
| 31 | + icon.src = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIwLjdlbSIgaGVpZ2h0PSIxZW0iIHZpZXdCb3g9IjAgMCAyNTYgMzY4Ij48cGF0aCBmaWxsPSIjNDlBMkY4IiBkPSJNMTA5LjU4NiAyMTcuMDEzSDBMMjAwLjM0IDBsLTUzLjkyNiAxNTAuMjMzSDI1Nkw1NS42NDUgMzY3LjI0Nmw1My45MjctMTUwLjIzM3oiLz48L3N2Zz4=' |
| 32 | + icon.classList.add('octicon') |
| 33 | + a.prepend(icon) |
| 34 | + return a |
| 35 | + } |
| 36 | + |
| 37 | + function run() { |
| 38 | + if (document.querySelector(`#${id}`)) |
| 39 | + return |
| 40 | + |
| 41 | + const repoActions = document.querySelector('#repository-details-container ul') |
| 42 | + if (repoActions) { |
| 43 | + const li = document.createElement('li') |
| 44 | + li.appendChild(createButton()) |
| 45 | + repoActions.prepend(li) |
| 46 | + return |
| 47 | + } |
| 48 | + |
| 49 | + const prActions = document.querySelector('.gh-header-actions') |
| 50 | + if (prActions) |
| 51 | + prActions.prepend(createButton()) |
| 52 | + } |
| 53 | + |
| 54 | + run() |
| 55 | + |
| 56 | + // listen to github page loaded event |
| 57 | + document.addEventListener('pjax:end', () => run()) |
| 58 | + document.addEventListener('turbo:render', () => run()) |
| 59 | +})() |
0 commit comments