├── plusone.png ├── README.md ├── manifest.json └── content_script.js /plusone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eligolding/github-plusone-extension/master/plusone.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub +1 Chrome Extension 2 | 3 | [![GitHub +1 Chrome Extension](http://i.imgur.com/wJLc7R4.png)](https://chrome.google.com/webstore/detail/github-%201s/lddfkkebajnpiicnpfamebilmhamkeme) 4 | 5 | More information and installation instructions can be found [here](https://chrome.google.com/webstore/detail/github-%201s/lddfkkebajnpiicnpfamebilmhamkeme) on the Chrome Web Store. 6 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Github +1s", 3 | "description": "Shows you the counts and avatars of those noisy '+1' comments and hides the original comments.", 4 | "version": "1.4.0", 5 | "permissions": [ 6 | "activeTab" 7 | ], 8 | "icons": { 9 | "128": "plusone.png" 10 | }, 11 | "manifest_version": 2, 12 | "content_scripts": [ 13 | { 14 | "matches": ["https://github.com/*"], 15 | "js": ["content_script.js"] 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /content_script.js: -------------------------------------------------------------------------------- 1 | function removePlusOnes() { 2 | var comments = [].slice.call(document.querySelectorAll('.timeline-comment-wrapper'), 0); 3 | var avatars = []; 4 | var alreadySeen = []; 5 | comments.forEach(function (comment) { 6 | var text = comment.querySelector('.comment-body').textContent.trim(); 7 | if ( 8 | text.match(/^(\+1|👍)/) || 9 | comment.querySelector('img[title=":+1:"]') || 10 | comment.querySelector('img[title=":thumbsup:"]') 11 | ) { 12 | var avatar = comment.querySelector('a').cloneNode(true); 13 | var user = avatar.href; 14 | if(alreadySeen.indexOf(user) < 0) { 15 | avatars.push(avatar); 16 | alreadySeen.push(user); 17 | } 18 | if(text.match(/^(\+1|👍)$/) || !text) { // there wont be text if the comment is just a 👍 19 | comment.style.display = 'none'; 20 | } 21 | } 22 | }); 23 | 24 | if(avatars.length > 0) { 25 | var div = document.createElement('div'); 26 | div.className = 'js-plus-one-count flex-table gh-header-meta'; 27 | div.innerHTML = '' + 28 | '
' + 29 | '
' + 30 | ' ' + 31 | ' +' + avatars.length + 32 | '
' + 33 | '
' + 34 | '
'; 35 | 36 | var avatarContainer = div.querySelector('.flex-table-item-primary'); 37 | avatarContainer.style.paddingTop = 0; 38 | 39 | avatars.forEach(function (avatar) { 40 | // Tap the power of tooltips 41 | avatar.className = 'avatar-link tooltipped tooltipped-s'; 42 | avatar.setAttribute('aria-label', avatar.getAttribute('href').replace(/^\//, '')); 43 | 44 | var img = avatar.querySelector('img'); 45 | img.className = ''; 46 | img.style.height = '26px'; 47 | img.style.width = '26px'; 48 | img.style.margin = '0 2px'; 49 | img.style.borderRadius = '3px'; 50 | avatarContainer.appendChild(avatar); 51 | }); 52 | 53 | var currentCount = document.querySelector('.js-plus-one-count'); 54 | if (currentCount) { currentCount.remove(); } 55 | 56 | document.querySelector('.gh-header-show').appendChild(div); 57 | } 58 | } 59 | 60 | var observer = new MutationObserver(function(mutations) { 61 | var needsRemoval = false; 62 | mutations.forEach(function(mutation) { 63 | Array.prototype.slice.call(mutation.addedNodes).forEach(function(node) { 64 | if (node instanceof Element && (node.querySelector('.js-comment') || node.classList.contains('js-comment'))) { 65 | needsRemoval = true; 66 | } 67 | }); 68 | }); 69 | 70 | if (needsRemoval) { 71 | removePlusOnes(); 72 | } 73 | }); 74 | 75 | var container = document.getElementById('js-repo-pjax-container'); 76 | observer.observe(container, {childList: true, subtree: true}); 77 | 78 | removePlusOnes(); 79 | --------------------------------------------------------------------------------