Greasy Fork is available in English.

Publish button in repo on GitHub

5/28/2020, 5:17:05 PM

Versione datata 01/06/2020. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        Publish button in repo on GitHub
// @namespace   Violentmonkey Scripts
// @match       https://github.com/*/*
// @grant       none
// @version     1.0
// @author      -
// @description 5/28/2020, 5:17:05 PM
// ==/UserScript==

var username = $('strong.css-truncate-target').innerText

// DOM-lib
Element.prototype.makeElement = function (tag, options={}) {
  return makeElement(tag, options, this)
}

Element.prototype.find = Element.prototype.querySelector

function makeElement(tag, options={}, parent) {
  const el = document.createElement(tag)
  Object.assign(el, options)
  if (parent) parent.append(el)
  return el
}

function $(selector, text) {
  if (text) return [...$$(selector)].find(el => el.innerText == text)
  return document.querySelector(selector)
}

function $$(selector) {
    return [...document.body.querySelectorAll(selector)].filter(el => el.tagName != "SCRIPT")
}

// Script
if (username == location.href.match(/github.com\/([^\/]*)/)[1]) {
  if (!location.href.endsWith('/settings') && !localStorage.publish) {
    $('.pagehead-actions').makeElement('li').makeElement('button', {className: 'btn btn-sm', innerText: 'Publish'}).onclick = () => {
      console.log('start publish')
      localStorage.publish = 1
      location.href += '/settings'
    }
  }

  else if (location.href.endsWith('/settings') && localStorage.publish == 1) {
    localStorage.publish = 2
    $('[value="master"]').click()
  }

  else if (location.href.endsWith('/settings') && localStorage.publish == 2) {  
    localStorage.publish = 3
    location.href = location.href.replace('/settings', '')
  }

  else if (!location.href.endsWith('/settings') && localStorage.publish == 3) {
    $('span.btn', "Edit").click()
    $('#repo_homepage').value = 'https://' + username + '.github.io/' + location.href.replace('https://github.com/' + username + '/', '');
    $('button.btn', "Save").click()
    delete localStorage.publish
  } 
}