|
22 | 22 | String.format = function(string) { |
23 | 23 | var args = Array.prototype.slice.call(arguments, 1, arguments.length); |
24 | 24 | return string.replace(/{(\d+)}/g, function(match, number) { |
25 | | - return typeof args[number] !== "undefined" ? args[number] : match; |
| 25 | + return typeof args[number] !== 'undefined' ? args[number] : match; |
26 | 26 | }); |
27 | 27 | }; |
28 | 28 |
|
29 | 29 | var socials = { |
30 | 30 | Twitter: { |
31 | | - show: function(/*url, user, description, files, stars, forks, revisions*/) { return true; }, |
| 31 | + show: function( /*url, user, description, files, stars, forks, revisions*/ ) { |
| 32 | + return true; |
| 33 | + }, |
32 | 34 | submit: function(url, user, description, files, stars, forks, revisions) { |
33 | 35 | var stats = []; |
34 | 36 | if (files > 1) { |
35 | | - stats.push(files + " files"); |
| 37 | + stats.push(files + ' files'); |
36 | 38 | } |
37 | 39 | if (stars === 1) { |
38 | | - stats.push(stars + " star"); |
| 40 | + stats.push(stars + ' star'); |
39 | 41 | } else if (stars > 1) { |
40 | | - stats.push(stars + " stars"); |
| 42 | + stats.push(stars + ' stars'); |
41 | 43 | } |
42 | 44 | if (forks === 1) { |
43 | | - stats.push(forks + " fork"); |
| 45 | + stats.push(forks + ' fork'); |
44 | 46 | } else if (forks > 1) { |
45 | | - stats.push(forks + " forks"); |
| 47 | + stats.push(forks + ' forks'); |
46 | 48 | } |
47 | 49 | if (revisions > 1) { |
48 | | - stats.push(revisions + " revisions"); |
| 50 | + stats.push(revisions + ' revisions'); |
49 | 51 | } |
50 | 52 |
|
51 | | - var tweet = String.format("Check out {0} #gist {1} on @github{2} |", |
52 | | - user === document.querySelector(".name").textContent.trim() ? "my" : user + "'s", |
53 | | - description ? "\"" + description + "\"" : "", |
54 | | - stats.length > 0 ? " | " + stats.join(", ") : ""); |
| 53 | + var tweet = String.format('Check out {0} #gist {1} on @github{2} |', |
| 54 | + user === document.querySelector('.name').textContent.trim() ? 'my' : user + '\'s', |
| 55 | + description ? '"' + description + '"' : '', |
| 56 | + stats.length > 0 ? ' | ' + stats.join(', ') : ''); |
55 | 57 |
|
56 | | - return "https://twitter.com/intent/tweet?original_referer=" + encodeURIComponent(url) + |
57 | | - "&source=tweetbutton&url=" + encodeURIComponent(url) + |
58 | | - "&text=" + encodeURIComponent(tweet); |
| 58 | + return 'https://twitter.com/intent/tweet?original_referer=' + encodeURIComponent(url) + |
| 59 | + '&source=tweetbutton&url=' + encodeURIComponent(url) + |
| 60 | + '&text=' + encodeURIComponent(tweet); |
59 | 61 | }, |
60 | | - icon: "https://si0.twimg.com/favicons/favicon.ico" |
| 62 | + icon: 'https://si0.twimg.com/favicons/favicon.ico' |
61 | 63 | }, |
62 | 64 | Dabblet: { |
63 | 65 | /* |
|
76 | 78 | * - https://gist.github.com/3810309/f2815cc6796ea985f74b8f5f3c717e8de3b12d37 |
77 | 79 | * |
78 | 80 | */ |
79 | | - show: function(/*url, user, description, files, stars, forks, revisions*/) { return true; }, |
80 | | - submit: function(url, user/*, description, files, stars, forks, revisions*/) { |
| 81 | + show: function( /*url, user, description, files, stars, forks, revisions*/ ) { |
| 82 | + return true; |
| 83 | + }, |
| 84 | + submit: function(url, user /*, description, files, stars, forks, revisions*/ ) { |
81 | 85 | var linkLong; |
82 | | - if ((linkLong = document.querySelector(".site-container.js-site-container")) && linkLong.dataset.url) { |
83 | | - var linkLongParts = linkLong.dataset.url.split("/"); |
| 86 | + if ((linkLong = document.querySelector('.site-container.js-site-container')) && linkLong.dataset.url) { |
| 87 | + var linkLongParts = linkLong.dataset.url.split('/'); |
84 | 88 | linkLongParts.shift(); |
85 | 89 | if (/^(?:revisions|forks|stars)$/gi.test(linkLongParts[linkLongParts.length - 1])) { |
86 | 90 | linkLongParts.pop(); |
87 | 91 | } |
88 | | - if (new RegExp(user, "gi").test(linkLongParts[0])) { |
| 92 | + if (new RegExp(user, 'gi').test(linkLongParts[0])) { |
89 | 93 | linkLongParts.shift(); |
90 | 94 | } |
91 | | - url = "/" + linkLongParts.join("/"); |
| 95 | + url = '/' + linkLongParts.join('/'); |
92 | 96 | } else { |
93 | | - url = url.replace(new RegExp("https?:\/\/gist.github.com/" + user, "gi"), ""); |
| 97 | + url = url.replace(new RegExp('https?:\/\/gist.github.com/' + user, 'gi'), ''); |
94 | 98 | } |
95 | | - return "http://dabblet.com/gist" + url; |
| 99 | + return 'http://dabblet.com/gist' + url; |
96 | 100 | }, |
97 | | - icon: "http://dabblet.com/favicon.ico" |
| 101 | + icon: 'http://dabblet.com/favicon.ico' |
98 | 102 | }, |
99 | 103 | UserScript: { |
100 | | - show: function(/*url, user, description, files, stars, forks, revisions*/) { |
101 | | - return !!document.querySelector(".file[id^='file-'] .raw-url[href$='.user.js']"); |
| 104 | + show: function( /*url, user, description, files, stars, forks, revisions*/ ) { |
| 105 | + return !!document.querySelector('.file[id^="file-"] .raw-url[href$=".user.js"]'); |
102 | 106 | }, |
103 | | - submit: function(/*url, user, description, files, stars, forks, revisions*/) { |
104 | | - return (document.querySelector(".file[id^='file-'] .raw-url[href$='.user.js']") || { href: "" }).href.trim(); |
| 107 | + submit: function( /*url, user, description, files, stars, forks, revisions*/ ) { |
| 108 | + return (document.querySelector('.file[id^="file-"] .raw-url[href$=".user.js"]') || { |
| 109 | + href: '' |
| 110 | + }).href.trim(); |
105 | 111 | }, |
106 | | - icon: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAKwSURBVHjabJNJTBNRGID/mc5MQYVWVNCGTbEtNZGDBj1ogolEMR5UJA2LBmMoIokxERIj8ehJjx6MYIQoJgq4JIa6gEARkKJFTa2iFFtKWwp2oeDCzNQ+31DQCc5L/nmT/P/3749ACAFBECBxiEPFFds0Ws399DRVhtX2udc97ig0PmgOLBkIbOwjAR8uMRRdvXF7pqv/NfrqnEAOlxsdLas6j3Wk2AEpCRcbKvLydrdu1WUr0lXrITEhAZKUSkhQKvKwXiY2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SkhQKvKwXiY2ppbDRzCcv29P/ZZsDaSqUkCJYVJGwKMnHTDlmWgTZ/CvjkW4sKTScP1WC+oZsKAxpwv5gyEUnAkj2xc70p88Y8Y2a8VBxT0gispOGa413UVDb23IMe6OwaEw+jTqQKMOF3pptqBSw7k74hLEPaDUOu0VmpFDV58ZCJIAkiDB5fUBz0eApmjQqbOgrqa69HhVbZO4jKUfmiBJBctysHJFPPiDYbA7J4DjeJDLaWAYGVAyErIy0uDs6RPH9OXVtULWYgfEmN3emJK8BlYrEsHl8cEvloX4ODnEyRlgKGZhV1iOhcz0VNixM7dOCCp2EBkeMF3u6DaNqDasg1U4CzlFxxSRKMyz8xjmsPAQwNmRsc2jxGPkR0esHp7n9RBFrYbyUi1DUzh1GujFG0UBQrNz8P7DR3j+9NklqTEK3VVkbNLkVNZc9AwNW5Hb60PT/gCamg6gEbsT3XvYjvIP6i9gu2ShhOWb+BvLD13O9o3azWrVdy4K3wKhv5HfWW1Q39BY19nechPbzQrVwX9bhU+iIqnyQMF+mPvJQr/FCsHwDJgG30ADhl8Y2wQ4jIUVkpdaZRnPcd6AfxomJ32AIhEwdvaC8XG7JLwwvmXPmVFn52Tu2lvQjN9Crn3M6bWY+6otr3oGpWCB/SPAAJaJRguGUxB0AAAAAElFTkSuQmCC' |
107 | 113 | } |
108 | 114 | }; |
109 | 115 |
|
110 | 116 | function addMenuItem() { |
111 | | - var link, url, menu, li, user, description, files, stars, forks, revisions; |
| 117 | + var temp, link, url, menu, li, user, description, files, stars, forks, revisions; |
112 | 118 |
|
113 | | - if ((link = document.querySelector(".js-current-repository")) && (menu = document.querySelector('.sunken-menu-group'))) { // check if we're on an actual gists; |
| 119 | + if ((link = document.querySelector('.js-current-repository')) && (menu = document.querySelector('.sunken-menu-group'))) { // check if we're on an actual gists; |
114 | 120 | url = link.href; |
115 | | - user = document.querySelector(".author.vcard").textContent.trim(); |
116 | | - description = (document.querySelector(".gist-description") || link || { textContent: "" }).textContent.trim(); |
117 | | - files = document.querySelectorAll(".file[id^='file-']").length; |
118 | | - stars = parseInt((menu.querySelector("a[href$='/stars'] .counter") || { textContent: "0" }).textContent.trim(), 10); |
119 | | - forks = parseInt((menu.querySelector("a[href$='/forks'] .counter") || { textContent: "0" }).textContent.trim(), 10); |
120 | | - revisions = parseInt((menu.querySelector("a[href$='/revisions'] .counter") || { textContent: "0" }).textContent.trim(), 10); |
| 121 | + user = document.querySelector('.author.vcard').textContent.trim(); |
| 122 | + description = (temp = (document.querySelector('.gist-description') || link)) && temp.textContent.trim() || ''; |
| 123 | + files = document.querySelectorAll('.file[id^="file-"]').length; |
| 124 | + stars = (temp = menu.querySelector('a[href$="/stars"] .counter')) && parseInt(temp.textContent.trim(), 10) || 0; |
| 125 | + forks = (temp = menu.querySelector('a[href$="/forks"] .counter')) && parseInt(temp.textContent.trim(), 10) || 0; |
| 126 | + revisions = (temp = menu.querySelector('a[href$="/revisions"] .counter')) && parseInt(temp.textContent.trim(), 10) || 0; |
121 | 127 |
|
122 | | - menu.appendChild(li = document.createElement("li")); |
123 | | - li.id = "Github_Gist_Share"; |
| 128 | + menu.appendChild(li = document.createElement('li')); |
| 129 | + li.id = 'Github_Gist_Share'; |
124 | 130 |
|
125 | 131 | for (var key in socials) { |
126 | 132 | if (socials.hasOwnProperty(key)) { |
127 | 133 | var social = socials[key], |
128 | | - socialA = document.createElement("a"), |
129 | | - socialImg = document.createElement("img"); |
| 134 | + socialA = document.createElement('a'), |
| 135 | + socialImg = document.createElement('img'); |
130 | 136 |
|
131 | | - if (social.show(url, user, description, files, stars, forks, revisions) !== true) { continue; } |
| 137 | + if (social.show(url, user, description, files, stars, forks, revisions) !== true) { |
| 138 | + continue; |
| 139 | + } |
132 | 140 |
|
133 | 141 | li.appendChild(socialA); |
134 | 142 | socialA.appendChild(socialImg); |
135 | | - socialA.id = String.format("{0}_{1}", li.id, key.replace(/\s+/g, "_")); |
136 | | - socialA.classList.add("sunken-menu-item"); |
| 143 | + socialA.id = (li.id + '_' + key).replace(/\s+/g, '_'); |
| 144 | + socialA.classList.add('sunken-menu-item'); |
137 | 145 | socialA.href = social.submit && social.submit(url, user, description, files, stars, forks, revisions); |
138 | | - socialA.title = String.format("[{0}] {1}", key, socialA.href); |
139 | | - socialA.style.display = "inline-block"; |
140 | | - socialA.target = "_blank"; |
| 146 | + socialA.title = String.format('[{0}] {1}', key, socialA.href); |
| 147 | + socialA.style.display = 'inline-block'; |
| 148 | + socialA.target = '_blank'; |
141 | 149 | socialImg.src = social.icon; |
142 | 150 | socialImg.alt = key; |
143 | 151 | } |
|
149 | 157 | addMenuItem(); |
150 | 158 |
|
151 | 159 | // on pjax; |
152 | | - unsafeWindow.$(document).on("pjax:success", addMenuItem); |
| 160 | + unsafeWindow.$(document).on('pjax:success', addMenuItem); |
153 | 161 |
|
154 | 162 | })(); |
0 commit comments