Publish button in repo on GitHub

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

18.05.2021 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

You will need to install an extension such as Tampermonkey to install this script.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

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

const username = $("a.url.fn").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/pages'
    }
  } else if (location.href.endsWith('/settings/pages') && localStorage.publish == 1) {
    localStorage.publish = 2
    setTimeout(() => $('[value=master]').click(), 300)
    setTimeout(() => [...document.forms].find(form => form.action.endsWith("/pages/source")).submit(), 1000)
  } else if (location.href.endsWith('/settings/pages') && localStorage.publish == 2) {  
    localStorage.publish = 3
    location.href = location.href.replace('/settings/pages', '')
  } else if (!location.href.endsWith('/settings/pages') && localStorage.publish == 3) {
    delete localStorage.publish
    repo_homepage.value = 'https://' + username + '.github.io/' + location.href.replace('https://github.com/' + username + '/', '') + '/'
    repo_metadata_form.submit()
  } 
}