Greasy Fork is available in English.

Github Gist Share

Share your GitHub Gist to Twitter, Dabblet & as userscript.

اعتبارا من 24-02-2014. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

  1. // ==UserScript==
  2. // @name Github Gist Share
  3. // @namespace https://greatest.deepsurf.us/scripts/54
  4. // @description Share your GitHub Gist to Twitter, Dabblet & as userscript.
  5. // @homepage https://github.com/jerone/UserScripts/tree/master/Github_Gist_Share
  6. // @homepageURL https://github.com/jerone/UserScripts/tree/master/Github_Gist_Share
  7. // @downloadURL https://greatest.deepsurf.us/scripts/54/code.user.js
  8. // @include *://gist.github.com/*
  9. // @version 1.20140224100236
  10. // @grant none
  11. // @updateURL https://greatest.deepsurf.us/scripts/54/code.meta.js
  12. // ==/UserScript==
  13.  
  14.  
  15. String.format = function (string) {
  16. var args = Array.prototype.slice.call(arguments, 1, arguments.length);
  17. return string.replace(/{(\d+)}/g, function (match, number) {
  18. return typeof args[number] != "undefined" ? args[number] : match;
  19. });
  20. };
  21.  
  22. var socials = {
  23. Twitter: {
  24. show: function(url, user, description, files, stars, forks, revisions){
  25. return true;
  26. },
  27. submit: function(url, user, description, files, stars, forks, revisions){
  28. var stats = [];
  29. if(files > 1){
  30. stats.push(files + " files");
  31. }
  32. if(stars == 1){
  33. stats.push(stars + " star");
  34. } else if(stars > 1){
  35. stats.push(stars + " stars");
  36. }
  37. if(forks == 1){
  38. stats.push(forks + " fork");
  39. } else if(forks > 1){
  40. stats.push(forks + " forks");
  41. }
  42. if(revisions > 1){
  43. stats.push(revisions + " revisions");
  44. }
  45.  
  46. var tweet = String.format("Check out {0} #gist {1} on @github{2} |",
  47. user == document.querySelector(".name").textContent.trim() ? "my" : user + "'s",
  48. description ? "\"" + description + "\"" : "",
  49. stats.length > 0 ? " | " + stats.join(", ") : "");
  50.  
  51. return "https://twitter.com/intent/tweet?original_referer=" + encodeURIComponent(url) +
  52. "&source=tweetbutton&url=" + encodeURIComponent(url) +
  53. "&text=" + encodeURIComponent(tweet);
  54. },
  55. icon: "https://si0.twimg.com/favicons/favicon.ico"
  56. },
  57. Dabblet: {
  58. show: function(url, user, description, files, stars, forks, revisions){
  59. // already defined in another UserScript: http://userscripts.org/users/31497/scripts
  60. return !document.getElementById("Github_Gist_Dabblet");
  61. },
  62. submit: function(url, user, description, files, stars, forks, revisions){
  63. var linkLong;
  64. if ((linkLong = document.querySelector(".site-container.js-site-container")) && linkLong.dataset.url) {
  65. var linkLongParts = linkLong.dataset.url.split("/");
  66. linkLongParts.shift();
  67. if (/^(?:revisions|forks|stars)$/gi.test(linkLongParts[linkLongParts.length - 1])) {
  68. linkLongParts.pop();
  69. }
  70. if (new RegExp(user,"gi").test(linkLongParts[0])) {
  71. linkLongParts.shift();
  72. }
  73. url = "/" + linkLongParts.join("/");
  74. } else {
  75. url = url.replace(new RegExp("https?:\/\/gist\.github\.com/" + user, "gi"), "");
  76. }
  77. return "http://dabblet.com/gist" + url;
  78. },
  79. icon: "http://dabblet.com/favicon.ico"
  80. },
  81. UserScript: {
  82. show: function(url, user, description, files, stars, forks, revisions){
  83. return !!document.querySelector(".bubble[id^='file-'] .raw-url[href$='.user.js']");
  84. },
  85. submit: function(url, user, description, files, stars, forks, revisions){
  86. return (document.querySelector(".bubble[id^='file-'] .raw-url[href$='.user.js']") || { href: ""}).href.trim();
  87. },
  88. icon: "http://wiki.greasespot.net/favicon.ico"
  89. }
  90. };
  91.  
  92. function addMenuItem() {
  93. var link, url, menu, li, user, description, files, stars, forks, revisions;
  94.  
  95. if ((link = document.querySelector("[name='link-field']")) && (menu = document.querySelector('ul.menu.gisttabs'))) { // check if we're on an actual gists;
  96. url = link.value;
  97. user = document.querySelector(".author.vcard").textContent.trim();
  98. description = (document.querySelector(".gist-description") || document.querySelector(".js-current-repository") || { textContent: ""}).textContent.trim();
  99. files = document.querySelectorAll(".bubble[id^='file-']").length;
  100. stars = (menu.querySelector("a[href$='/stars'] .counter") || { textContent: ""}).textContent.trim();
  101. forks = (menu.querySelector("a[href$='/forks'] .counter") || { textContent: ""}).textContent.trim();
  102. revisions = (menu.querySelector("a[href$='/revisions'] .counter") || { textContent: ""}).textContent.trim();
  103.  
  104. menu.appendChild(li = document.createElement("li"));
  105. li.id = "Github_Gist_Share";
  106.  
  107. for(var key in socials){
  108. var social = socials[key],
  109. socialA = document.createElement("a"),
  110. socialImg = document.createElement("img");
  111. if (social.show(url, user, description, files, stars, forks, revisions) !== true) continue;
  112. li.appendChild(socialA);
  113. socialA.appendChild(socialImg);
  114. socialA.id = String.format("{0}_{1}", li.id, key.replace(/\s+/g, "_"));
  115. socialA.href = social.submit && social.submit(url, user, description, files, stars, forks, revisions);
  116. socialA.title = String.format("[{0}] {1}", key, socialA.href);
  117. socialA.style.display = "inline-block";
  118. socialA.target = "_blank";
  119. socialImg.src = social.icon;
  120. socialImg.alt = key;
  121. }
  122. }
  123. }
  124.  
  125. // init;
  126. addMenuItem();
  127.  
  128. // on pjax;
  129. $(document).on("pjax:success", addMenuItem);