├── README.md ├── bin ├── GithubForkConfirmation.1.0.0.zip └── GithubForkConfirmation1.0.1.zip ├── meta ├── Screenshot - Chrome Store.png └── Screenshot.png └── source ├── Chrome ├── _locales │ └── en │ │ └── messages.json ├── icons │ ├── icon128.png │ ├── icon16.png │ ├── icon19.png │ ├── icon256.png │ ├── icon48.png │ └── svg256.svg ├── manifest.json └── src │ └── inject │ └── inject.js └── UserScript └── GithubForkConfirmation.user.js /README.md: -------------------------------------------------------------------------------- 1 | # Github Fork Confirmation 2 | 3 | Are you always accidentally forking repositories? I know I am. This Chrome Extension (or User Script!) will help. It adds a confirm dialog to the Fork button on Github repositories and Gists. 4 | 5 | Available on the Chrome store: 6 | [https://chrome.google.com/webstore/detail/github-fork-confirmation/mofjdkidemhjconaodballcmpnaofeod](https://chrome.google.com/webstore/detail/github-fork-confirmation/mofjdkidemhjconaodballcmpnaofeod) 7 | 8 | Or as a [User Script](source/UserScript/GithubForkConfirmation.user.js) 9 | 10 | Here's what you can expect: 11 | ![Screenshot](/meta/Screenshot.png) 12 | 13 | ---------- 14 | 15 | ## Changelog 16 | 17 | ### v1.0.1 (August 25, 2015) 18 | - Updated the selector used to find the "Fork" button. Github changed their HTML. 19 | -------------------------------------------------------------------------------- /bin/GithubForkConfirmation.1.0.0.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/bin/GithubForkConfirmation.1.0.0.zip -------------------------------------------------------------------------------- /bin/GithubForkConfirmation1.0.1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/bin/GithubForkConfirmation1.0.1.zip -------------------------------------------------------------------------------- /meta/Screenshot - Chrome Store.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/meta/Screenshot - Chrome Store.png -------------------------------------------------------------------------------- /meta/Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/meta/Screenshot.png -------------------------------------------------------------------------------- /source/Chrome/_locales/en/messages.json: -------------------------------------------------------------------------------- 1 | { 2 | "ConfirmRepository": { 3 | "message":"Are you positive you want to fork this repository?" 4 | ,"description":"Confirmation text for forking a repository." 5 | } 6 | ,"ConfirmGist": { 7 | "message":"Are you positive you want to fork this Gist?" 8 | ,"description":"Confirmation text for forking a Gist." 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /source/Chrome/icons/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/source/Chrome/icons/icon128.png -------------------------------------------------------------------------------- /source/Chrome/icons/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/source/Chrome/icons/icon16.png -------------------------------------------------------------------------------- /source/Chrome/icons/icon19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/source/Chrome/icons/icon19.png -------------------------------------------------------------------------------- /source/Chrome/icons/icon256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/source/Chrome/icons/icon256.png -------------------------------------------------------------------------------- /source/Chrome/icons/icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexcpendleton/GithubForkConfirmation/eca64a632421e203f3533a44dfb4b45892fd3f71/source/Chrome/icons/icon48.png -------------------------------------------------------------------------------- /source/Chrome/icons/svg256.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Layer 1 6 | ? 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /source/Chrome/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Github Fork Confirmation", 3 | "version": "1.0.1", 4 | "manifest_version": 2, 5 | "description": "Adds a confirmation dialog to the Github and Gist Fork button.", 6 | "homepage_url": "https://github.com/alexcpendleton/GithubForkConfirmation", 7 | "icons": { 8 | "16": "icons/icon16.png", 9 | "48": "icons/icon48.png", 10 | "128": "icons/icon128.png" 11 | }, 12 | "default_locale": "en", 13 | "permissions": [ 14 | "https://github.com/*", 15 | "https://gist.github.com/*" 16 | ], 17 | "content_scripts": [ 18 | { 19 | "matches": [ 20 | "https://github.com/*", 21 | "https://gist.github.com/*" 22 | ], 23 | "js": [ 24 | "src/inject/inject.js" 25 | ] 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /source/Chrome/src/inject/inject.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | function GithubForkConfirmer(messageSource) { 3 | var gfcAttributeName = "githubForkConfirmer"; 4 | var gfcAttributeValue = "true" 5 | function isGist() { 6 | return window.location.toString().toLowerCase().indexOf("https://gist.github") > -1; 7 | } 8 | function createConfirmationMessage() { 9 | var messageName = isGist() ? "ConfirmGist" : "ConfirmRepository"; 10 | return messageSource.getMessage(messageName); 11 | } 12 | function onFork(event) { 13 | var result = confirm(createConfirmationMessage()); 14 | if (!result) { 15 | event.preventDefault(); 16 | event.stopPropagation(); 17 | event.stopImmediatePropagation(); 18 | return false; 19 | } 20 | return true; 21 | } 22 | 23 | function findAndSetBindings() { 24 | // When going to a Gist from the "All Gists" page, this script is never reloaded because it's using the History API or something 25 | // From a content script we don't have access to history events (I couldn't find them anyway) 26 | // So instead we wait for any click event on the page and then look for the fork button and subscribe to its click event 27 | document.addEventListener("click", function(event) { 28 | var selector = "form[action*='/fork'] button[type='submit']"; 29 | var forkButton = document.querySelector(selector); 30 | if(forkButton) { 31 | var hasAttribute = forkButton.getAttribute(gfcAttributeName); 32 | if(!hasAttribute) { 33 | forkButton.setAttribute(gfcAttributeName, gfcAttributeValue); 34 | forkButton.addEventListener("click", onFork); 35 | } 36 | } 37 | }, true); 38 | } 39 | this.bind = function() { 40 | findAndSetBindings(); 41 | } 42 | } 43 | var confirmer = new GithubForkConfirmer(chrome.i18n); 44 | confirmer.bind(); 45 | })(); 46 | -------------------------------------------------------------------------------- /source/UserScript/GithubForkConfirmation.user.js: -------------------------------------------------------------------------------- 1 | // ==UserScript== 2 | // @name Github Fork Confirmation 3 | // @namespace https://alexcpendleton.com/ 4 | // @version 1.0.1 5 | // @description Adds a Confirm dialog to Github's Fork button 6 | // @match https://github.com/* 7 | // @match https://gist.github.com/* 8 | // @include https://github.com/* 9 | // @include https://gist.github.com/* 10 | // @copyright 2014+, Alex Pendleton 11 | // ==/UserScript== 12 | 13 | (function () { 14 | function GithubForkConfirmer(messageSource) { 15 | var gfcAttributeName = "githubForkConfirmer"; 16 | var gfcAttributeValue = "true" 17 | function isGist() { 18 | return window.location.toString().toLowerCase().indexOf("https://gist.github") > -1; 19 | } 20 | function createConfirmationMessage() { 21 | var messageName = isGist() ? "ConfirmGist" : "ConfirmProject"; 22 | return messageSource.getMessage(messageName); 23 | } 24 | function onFork(event) { 25 | var result = confirm(createConfirmationMessage()); 26 | if (!result) { 27 | event.preventDefault(); 28 | event.stopPropagation(); 29 | event.stopImmediatePropagation(); 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | function findAndSetBindings() { 36 | // When going to a Gist from the "All Gists" page, this script is never reloaded because it's using the History API or something 37 | // From a content script we don't have access to history events (I couldn't find them anyway) 38 | // So instead we wait for any click event on the page and then look for the fork button and subscribe to its click event 39 | document.addEventListener("click", function(event) { 40 | var selector = "form[action*='/fork'] button[type='submit']"; 41 | var forkButton = document.querySelector(selector); 42 | if(forkButton) { 43 | var hasAttribute = forkButton.getAttribute(gfcAttributeName); 44 | if(!hasAttribute) { 45 | forkButton.setAttribute(gfcAttributeName, gfcAttributeValue); 46 | forkButton.addEventListener("click", onFork); 47 | } 48 | } 49 | }, true); 50 | } 51 | this.bind = function() { 52 | findAndSetBindings(); 53 | } 54 | } 55 | function MessageProvider() { 56 | this.getMessage = function(name) { 57 | var map = { 58 | "ConfirmProject": { 59 | "message":"Are you positive you want to fork this project?" 60 | ,"description":"Confirmation text for forking a project." 61 | } 62 | ,"ConfirmGist": { 63 | "message":"Are you positive you want to fork this Gist?" 64 | ,"description":"Confirmation text for forking a Gist." 65 | } 66 | }; 67 | var message = map[name]; 68 | return message ? message.message : ""; 69 | }; 70 | } 71 | var confirmer = new GithubForkConfirmer(new MessageProvider()); 72 | confirmer.bind(); 73 | })(); 74 | --------------------------------------------------------------------------------