GitHub Repo Share-to-Twitter Button

Add a Twitter share button to repository page

Verze ze dne 08. 07. 2021. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         GitHub Repo Share-to-Twitter Button
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Add a Twitter share button to repository page
// @author       eggplants
// @homepage     https://github.com/eggplants
// @match        *://github.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(window.onload = function() {
    "use strict";

    const owner = document.getElementsByClassName('url fn')[0].textContent;
    const pjname = document.getElementsByClassName('mr-2 flex-self-stretch')[0].textContent.trim();
    const repo = 'https://github.com/' + owner + '/' + pjname;

    var a = document.getElementsByClassName('btn ml-2 d-none d-md-block')[0];

    var set_interval_id = setInterval(function() {
        if(a.parentNode !== undefined) {
            clearInterval(set_interval_id);
        }
    }, 1000);

    var b = document.createElement('a');
    b.className = 'btn btn-info';
    b.setAttribute('target', '_blank');
    b.href = 'http://twitter.com/share?url=' + repo + '&text=[write comments]%0a%0a';
    b.textContent = 'Share to Twitter';

    a.parentNode.insertBefore(b, a);
}());