NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @namespace https://openuserjs.org/users/yuanoook // @name Gitpod.io - Fetch, release and push // @description Gitpod.io - auto Fetch, release and push // @copyright 2020, yuanoook (https://openuserjs.org/users/yuanoook) // @license MIT // @version 1.2.0 // @include https://*.gitpod.io* // @grant none // ==/UserScript== // ==OpenUserJS== // @author yuanoook // ==/OpenUserJS== const wait = (seconds = 1) => new Promise( resolve => setTimeout(resolve, seconds * 1000) ) const addTimedStyle = async (content, timeLimit = 5) => { const style = document.createElement('style'); style.textContent = content; // document.head.appendChild(style); await wait(timeLimit); style.remove(); } const hideTemporarily = async (selector, timeLimit = 5) => { await addTimedStyle(`${selector}{display:none !important;}`) } const sisyphus = async function (func, timeLimit = 0) { let timeout = false if (timeLimit) wait(timeLimit).then(() => (timeout = true)) while (true) { await wait() try { const result = await func() return result } catch (error) { console.error(error) } if (timeout) throw new Error(`Sisyphus out of time - ${timeLimit}`) } } const sisyphusSelect = (selector, timeLimit = 0) => sisyphus(() => { console.log(`Searching ${selector} ...`) const result = document.querySelector(selector) if (!result) throw new Error(`Didn't get ${selector}`) return result }, timeLimit) const sisphusClick = async (selector, timeLimit = 0) => (await sisyphusSelect('#theia-dialog-shell button.main', timeLimit)).click(); const sisphusSearch = (selector, call, timeLimit = 0) => sisyphus(async () => { console.log(`Searching ${selector} ...`) const result = document.querySelector(selector) if (!result) throw new Error(`Didn't find ${selector}`) await call(result) throw new Error(`I'll keep searching...`) }, timeLimit) ;const autoFetchReleaseAndPush = async function () { const autoChooseOptionSelector = `[aria-label^="Fetch, rebase and push commits from and to"]`; const autoConfirmBtnSelector = '#theia-dialog-shell button.main' await sisphusSearch(autoChooseOptionSelector, async btn => { hideTemporarily('quick-open-container'); hideTemporarily('#theia-dialog-shell'); btn.click(); await sisphusClick(autoConfirmBtnSelector, 2) }) } ;(async function () { await autoFetchReleaseAndPush() })()