├── .gitignore ├── art ├── logo.psd └── screenshots.psd ├── gulpfile.js ├── package-lock.json ├── package.json ├── readme.md └── src ├── background.js ├── gist-inject.less ├── github-inject.less ├── icons ├── icon128.png ├── icon16.png ├── icon19.png ├── icon38.png └── icon48.png ├── includes └── breakpoints.less ├── manifest.json ├── options.html └── options.js /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | bower_components/ 4 | ext/ 5 | dist/ 6 | .vscode/ 7 | *.log* -------------------------------------------------------------------------------- /art/logo.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodejunkie/github.expandinizr/b1dd9ef9d65679b2d20dd90081fe859b7ecb424f/art/logo.psd -------------------------------------------------------------------------------- /art/screenshots.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodejunkie/github.expandinizr/b1dd9ef9d65679b2d20dd90081fe859b7ecb424f/art/screenshots.psd -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp') 2 | var less = require('gulp-less') 3 | var clean = require('gulp-clean') 4 | var sourcemaps = require('gulp-sourcemaps') 5 | var jeditor = require('gulp-json-editor') 6 | var uglify = require('gulp-uglify') 7 | var rename = require('gulp-rename') 8 | var cleanCSS = require('gulp-clean-css') 9 | var imagemin = require('gulp-imagemin') 10 | var cleanHtml = require('gulp-cleanhtml') 11 | var stripDebug = require('gulp-strip-debug') 12 | var zip = require('gulp-zip') 13 | 14 | var packageInfo = require('./package') 15 | 16 | gulp.task('watch', function () { 17 | return gulp.watch('./src/**', gulp.series('default')) 18 | }) 19 | 20 | gulp.task('clean', function () { 21 | return gulp.src(['./ext/*', './dist/*'], { read: false }) 22 | .pipe(clean()) 23 | }) 24 | 25 | gulp.task('styles', function () { 26 | return gulp.src('./src/*.less') 27 | .pipe(sourcemaps.init()) 28 | .pipe(less({ 29 | strictMath: 'on' 30 | })) 31 | .pipe(cleanCSS()) 32 | .pipe(sourcemaps.write()) 33 | .pipe(rename({ suffix: '.min' })) 34 | .pipe(gulp.dest('./ext/content')) 35 | }) 36 | 37 | gulp.task('html', function () { 38 | return gulp.src('./src/*.html') 39 | .pipe(cleanHtml()) 40 | .pipe(gulp.dest('./ext/content')) 41 | }) 42 | 43 | gulp.task('scripts', function () { 44 | var npmAssets = [ 45 | './node_modules/jquery/dist/jquery.min.js' 46 | ] 47 | 48 | gulp.src(npmAssets).pipe(gulp.dest('./ext/content')) 49 | 50 | return gulp.src('./src/*.js') 51 | .pipe(sourcemaps.init()) 52 | .pipe(stripDebug()) 53 | .pipe(uglify()) 54 | .pipe(sourcemaps.write()) 55 | .pipe(rename({ suffix: '.min' })) 56 | .pipe(gulp.dest('./ext/content')) 57 | }) 58 | 59 | gulp.task('images', function () { 60 | return gulp.src('./src/icons/*.png') 61 | .pipe(imagemin()) 62 | .pipe(gulp.dest('./ext/icons')) 63 | }) 64 | 65 | gulp.task('manifest', function () { 66 | var options = { 67 | 'name': packageInfo.name, 68 | 'version': packageInfo.version, 69 | 'description': packageInfo.description, 70 | 'homepage_url': packageInfo.repository.url 71 | } 72 | 73 | return gulp.src('./src/manifest.json') 74 | .pipe(jeditor(options)) 75 | .pipe(gulp.dest('./ext')) 76 | }) 77 | 78 | gulp.task('zip', function () { 79 | var manifest = require('./ext/manifest') 80 | var fileName = manifest.name + ' v' + manifest.version + '.zip' 81 | 82 | return gulp.src('./ext/**') 83 | .pipe(zip(fileName)) 84 | .pipe(gulp.dest('dist')) 85 | }) 86 | 87 | gulp.task('default', gulp.series('clean', gulp.parallel('images', 'scripts', 'html', 'styles'), 'manifest')) 88 | 89 | gulp.task('dist', gulp.series('default', 'zip')) 90 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github.expandinizr", 3 | "version": "2.0.2", 4 | "description": "Chrome extension that improves the GitHub experience", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/thecodejunkie/github.expandinizr" 8 | }, 9 | "keywords": [ 10 | "github", 11 | "responsive", 12 | "chrome" 13 | ], 14 | "author": "Andreas Håkansson", 15 | "license": "MIT", 16 | "bugs": { 17 | "url": "https://github.com/thecodejunkie/github.expandinizr/issues" 18 | }, 19 | "homepage": "https://github.com/thecodejunkie/github.expandinizr", 20 | "devDependencies": { 21 | "gulp": "^4.0.2", 22 | "gulp-clean": "^0.4.0", 23 | "gulp-clean-css": "^4.2.0", 24 | "gulp-cleanhtml": "^1.0.3", 25 | "gulp-imagemin": "^6.0.0", 26 | "gulp-json-editor": "^2.2.1", 27 | "gulp-less": "^4.0.1", 28 | "gulp-rename": "^1.2.2", 29 | "gulp-sourcemaps": "^2.6.1", 30 | "gulp-strip-debug": "^3.0.0", 31 | "gulp-uglify": "^3.0.0", 32 | "gulp-zip": "^5.0.0" 33 | }, 34 | "dependencies": { 35 | "jquery": "^3.5.0" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Github.ExpandinizR 2 | 3 | [![devDependencies](http://img.shields.io/david/dev/thecodejunkie/github.expandinizr.svg?style=flat)](https://david-dm.org/thecodejunkie/github.expandinizr#info=devDependencies) 4 | 5 | Chrome extension that improves the GitHub experience. 6 | 7 | [![Github.ExpandinizR](https://developer.chrome.com/webstore/images/ChromeWebStore_Badge_v2_340x96.png)](https://chrome.google.com/webstore/detail/cbehdjjcilgnejbpnjhobkiiggkedfib) 8 | 9 | Currently enhances the following: 10 | 11 | - Removes the truncating of file and directory names in the repository browser 12 | - Really long file and directory names will word-wrap 13 | - Fully expands the website, with breakpoints at 1400px, 1600px and 1800px 14 | - Removes truncation in notifications 15 | - Adds shrink/expand button for comment form 16 | - Adds possibility to collapse code previews 17 | 18 | ## Authors 19 | 20 | Andreas Håkansson, Kristian Hellang 21 | 22 | ## Contributors 23 | 24 | - [Andreas Håkansson](http://github.com/thecodejunkie) 25 | - [Bjarki Heiðar Ingason](https://github.com/bjarki) 26 | - [Christopher Campanale](https://github.com/ccampanale) 27 | - [Frank Radocaj](https://github.com/frankradocaj) 28 | - [Kristian Hellang](https://github.com/khellang) 29 | - [Phillip Haydon](https://github.com/phillip-haydon) 30 | - [Benjamin Chris](https://github.com/LuRenJiasWorld) 31 | 32 | ## Changelog 33 | 34 | - v2.0.2 35 | - Adapted to GitHub's new UI - @LuRenJiasWorld 36 | - v2.0.1 37 | - Fixed issue with huge profile avatars 38 | - Fixed issue where extension would be disabled because body hadn't been initialized yet 39 | - v2.0.0 40 | - Expanded main menu bar 41 | - Play nicely with [Octotree](https://github.com/buunguyen/octotree) 42 | - Added page action to turn the extension on/off 43 | - Removed outdated expand/collapse button for PR files 44 | - Fixed right menu issues when using split-diff 45 | - Fully expand timeline view 46 | - Fixed PR branch/remote picker width 47 | - v1.8.0 48 | - Fixed a bug where file names were not expanded - @khellang 49 | - Added support for GitHub Enterprise! :sparkles: @ccampanale 50 | - v1.7.1 - Removed ugly `aria-label`s 51 | - v1.7.0 52 | - Removed truncation in notifications - @khellang 53 | - Fixed commit comment width - @khellang 54 | - Fixed collapse code file button - @khellang 55 | - Added shrink/expand button for comment form - @khellang 56 | - v1.6.0 - Complete rewrite, added build with gulp - @khellang 57 | - v1.5.1 - Removed side-bar expansion, it broke too much stuff 58 | - v1.5.0 - Added possibility to collapse code previews 59 | - v1.4.0 - Expands side-bar for 1400, 1600 and 1800 break points 60 | - v1.3.2 - Improved expanding of activity stream 61 | - v1.3.1 - Fixed a couple of small layout bugs 62 | - v1.3.0 - Changed to a responsive approach - @khellang 63 | - v1.2.0 - Improved the un-truncting to word-wrap - @frankradocaj 64 | - v1.1.1 - Fix for labels on the expanded issue form 65 | - v1.1.0 - Expands the issue form to full width - @phillip-haydon 66 | - v1.0.0 - First release of the extension 67 | 68 | ## License 69 | 70 | The MIT License (MIT) 71 | 72 | Copyright (c) 2013 Andreas Håkansson, Kristian Hellang and contributors 73 | 74 | Permission is hereby granted, free of charge, to any person obtaining a copy 75 | of this software and associated documentation files (the "Software"), to deal 76 | in the Software without restriction, including without limitation the rights 77 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 78 | copies of the Software, and to permit persons to whom the Software is 79 | furnished to do so, subject to the following conditions: 80 | 81 | The above copyright notice and this permission notice shall be included in 82 | all copies or substantial portions of the Software. 83 | 84 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 85 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 86 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 87 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 88 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 89 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 90 | THE SOFTWARE. 91 | -------------------------------------------------------------------------------- /src/background.js: -------------------------------------------------------------------------------- 1 | /* global chrome */ 2 | 3 | var defaultOptions = { 4 | enabled: true, 5 | public_gist_enabled: true, 6 | public_github_enabled: true 7 | } 8 | 9 | chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { 10 | if (changeInfo.status !== 'loading') { 11 | return 12 | } 13 | 14 | chrome.tabs.executeScript(tabId, { 15 | code: 'var injected = window.expandinizrInjected; window.expandinizrInjected = true; injected;', 16 | runAt: 'document_start' 17 | }, function (res) { 18 | if (chrome.runtime.lastError || // don't continue if error (i.e. page isn't in permission list) 19 | res[0]) { // value of `injected` above: don't inject twice 20 | return 21 | } 22 | 23 | var cssFiles = [ 24 | 'content/github-inject.min.css' 25 | ] 26 | 27 | var gistCssFiles = [ 28 | 'content/gist-inject.min.css' 29 | ] 30 | 31 | chrome.storage.sync.get(defaultOptions, function (options) { 32 | if ((/https:\/\/gist\.github\.com/.test(tab.url) && options.public_gist_enabled) || 33 | (/https:\/\/github\.com/.test(tab.url) && options.public_github_enabled) || 34 | (!/gist\.github\.com/.test(tab.url) && !/github\.com/.test(tab.url))) { 35 | if ((/https:\/\/gist\.github\.com/.test(tab.url) && options.public_gist_enabled) || /\/gist\//.test(tab.url)) { // if we are in a gist site, inject gist css 36 | if (options.enabled) { 37 | chrome.tabs.executeScript(tabId, { 38 | code: 'document.documentElement.classList.add(\'expandinizr\')', 39 | runAt: 'document_start' 40 | }) 41 | } 42 | 43 | eachItem(gistCssFiles, inject('insertCSS')) 44 | } else if ((/https:\/\/github\.com/.test(tab.url) && options.public_github_enabled) || 45 | (!/gist\.github\.com/.test(tab.url) && !/github\.com/.test(tab.url))) { // otherwise, inject github js and css 46 | if (options.enabled) { 47 | chrome.tabs.executeScript(tabId, { 48 | code: 'document.documentElement.classList.add(\'expandinizr\')', 49 | runAt: 'document_start' 50 | }) 51 | } 52 | 53 | eachItem(cssFiles, inject('insertCSS')) 54 | } 55 | } 56 | }) 57 | 58 | function inject (fn) { 59 | return function (file, cb) { 60 | chrome.tabs[fn](tabId, { file: file, runAt: 'document_start' }, cb) 61 | } 62 | } 63 | }) 64 | }) 65 | 66 | chrome.runtime.onInstalled.addListener(function () { 67 | chrome.declarativeContent.onPageChanged.removeRules(undefined, function () { 68 | chrome.declarativeContent.onPageChanged.addRules([{ 69 | actions: [ new chrome.declarativeContent.ShowPageAction() ], 70 | conditions: [ 71 | new chrome.declarativeContent.PageStateMatcher({ 72 | pageUrl: { hostSuffix: 'github.com' } // TODO: Use permissions in some way. 73 | }) 74 | ] 75 | }]) 76 | }) 77 | 78 | chrome.pageAction.onClicked.addListener(function (tab) { 79 | chrome.storage.sync.get(defaultOptions, function (options) { 80 | chrome.storage.sync.set({ enabled: !options.enabled }, function () { 81 | chrome.tabs.executeScript(tab.id, { 82 | code: 'document.documentElement.classList.toggle(\'expandinizr\')' 83 | }) 84 | }) 85 | }) 86 | }) 87 | }) 88 | 89 | function eachTask (tasks, done) { 90 | function next (index) { 91 | if (index === tasks.length) { 92 | done && done() 93 | } else { 94 | tasks[index](function () { next(index + 1) }) 95 | } 96 | } 97 | next(0) 98 | } 99 | 100 | function eachItem (arr, iter, done) { 101 | var tasks = arr.map(function (item) { 102 | return function (next) { 103 | iter(item, next) 104 | } 105 | }) 106 | return eachTask(tasks, done) 107 | } 108 | -------------------------------------------------------------------------------- /src/gist-inject.less: -------------------------------------------------------------------------------- 1 | @import "includes/breakpoints"; 2 | 3 | .ruleset(@breakpoint) { 4 | .width(@width) { 5 | width: (@breakpoint - @width) !important 6 | } 7 | 8 | .max-width(@width) { 9 | max-width: (@breakpoint - @width) !important 10 | } 11 | 12 | .container-lg, .container-xl { 13 | .max-width(120px); 14 | } 15 | 16 | .container { 17 | .width(120px); 18 | 19 | & .gist-content { 20 | .width(320px); 21 | } 22 | } 23 | } 24 | 25 | .expandinizr { 26 | @media (min-width: @md-breakpoint) { 27 | .ruleset(@md-breakpoint); 28 | } 29 | 30 | @media (min-width: @lg-breakpoint) { 31 | .ruleset(@lg-breakpoint); 32 | } 33 | 34 | @media (min-width: @xlg-breakpoint) { 35 | .ruleset(@xlg-breakpoint); 36 | } 37 | 38 | @media (min-width: @xxl-breakpoint) { 39 | .ruleset(@xxl-breakpoint); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/github-inject.less: -------------------------------------------------------------------------------- 1 | @import "includes/breakpoints"; 2 | .ruleset(@breakpoint) { 3 | .width(@width) { 4 | width: (@breakpoint - @width) !important 5 | } 6 | .max-width(@width) { 7 | max-width: (@breakpoint - @width) !important 8 | } 9 | .pinned-repo-item { 10 | .width(950px); 11 | } 12 | .range-editor .fork-suggester .css-truncate-target { 13 | .max-width(1120px); 14 | } 15 | .container-lg, .container-xl { 16 | .max-width(120px); 17 | } 18 | .container { 19 | .octotree-show& { 20 | width: calc(~"100% - 20px") !important; 21 | } 22 | .width(120px); 23 | .split-diff & { 24 | padding-left: 0 !important; 25 | padding-right: 0 !important; 26 | } 27 | & .news .css-truncate.css-truncate-target { 28 | .max-width(530px); 29 | } 30 | & .notifications-list .css-truncate { 31 | .max-width(900px); 32 | & .css-truncate-target { 33 | .max-width(900px); 34 | } 35 | } 36 | & .repo-and-owner { 37 | .max-width(1030px); 38 | } 39 | & .repo-description.css-truncate-target { 40 | .max-width(1020px); 41 | white-space: normal !important; 42 | word-wrap: break-word !important; 43 | } 44 | & .org-main { 45 | .width(410px); 46 | } 47 | & .repo-list-description { 48 | .max-width(450px); 49 | } 50 | & .repository-with-sidebar { 51 | &.with-full-navigation { 52 | & .repository-content { 53 | .width(300px); 54 | } 55 | } 56 | & .repository-content { 57 | .width(170px); 58 | } 59 | } 60 | & .comment-holder { 61 | .max-width(140px); 62 | } 63 | & .timeline-comment { 64 | width: 100% !important; 65 | } 66 | & .timeline-new-comment .timeline-comment { 67 | .full-width& { 68 | .width(450px); 69 | } 70 | .width(400px); 71 | .octotree-show& { 72 | width: 100% !important; 73 | } 74 | } 75 | & .discussion-timeline-actions { 76 | .width(404px); 77 | .octotree-show& { 78 | width: 100% !important; 79 | } 80 | } 81 | & .discussion-timeline { 82 | .full-width& { 83 | .width(450px); 84 | } 85 | .width(340px); 86 | .octotree-show& { 87 | width: calc(~"100% - 220px") !important; 88 | } 89 | } 90 | & .merge-pr { 91 | .width(340px); 92 | .octotree-show& { 93 | width: 100% !important; 94 | } 95 | } 96 | } 97 | } 98 | 99 | .expandinizr { 100 | .css-truncate-button a { 101 | color: gray; 102 | margin-right: 5px; 103 | text-decoration: none !important; 104 | } 105 | .news .message { 106 | max-width: inherit !important; 107 | } 108 | .open>.merge-branch-manually { 109 | max-width: inherit !important; 110 | } 111 | .timeline-new-comment { 112 | max-width: inherit !important; 113 | } 114 | &.split-diff, 115 | &.full-width { 116 | & .new-pr-form { 117 | max-width: none !important; 118 | } 119 | } 120 | .capped-card { 121 | margin-right: 10px !important; 122 | margin-left: 10px !important; 123 | } 124 | table.files td.content { 125 | width: inherit !important; 126 | max-width: inherit !important; 127 | } 128 | @media (min-width: @md-breakpoint) { 129 | .ruleset(@md-breakpoint); 130 | } 131 | @media (min-width: @lg-breakpoint) { 132 | .ruleset(@lg-breakpoint); 133 | } 134 | @media (min-width: @xlg-breakpoint) { 135 | .ruleset(@xlg-breakpoint); 136 | } 137 | @media (min-width: @xxl-breakpoint) { 138 | .ruleset(@xxl-breakpoint); 139 | } 140 | } -------------------------------------------------------------------------------- /src/icons/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodejunkie/github.expandinizr/b1dd9ef9d65679b2d20dd90081fe859b7ecb424f/src/icons/icon128.png -------------------------------------------------------------------------------- /src/icons/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodejunkie/github.expandinizr/b1dd9ef9d65679b2d20dd90081fe859b7ecb424f/src/icons/icon16.png -------------------------------------------------------------------------------- /src/icons/icon19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodejunkie/github.expandinizr/b1dd9ef9d65679b2d20dd90081fe859b7ecb424f/src/icons/icon19.png -------------------------------------------------------------------------------- /src/icons/icon38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodejunkie/github.expandinizr/b1dd9ef9d65679b2d20dd90081fe859b7ecb424f/src/icons/icon38.png -------------------------------------------------------------------------------- /src/icons/icon48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thecodejunkie/github.expandinizr/b1dd9ef9d65679b2d20dd90081fe859b7ecb424f/src/icons/icon48.png -------------------------------------------------------------------------------- /src/includes/breakpoints.less: -------------------------------------------------------------------------------- 1 | @md-breakpoint: 1400px; 2 | @lg-breakpoint: 1600px; 3 | @xlg-breakpoint: 1800px; 4 | @xxl-breakpoint: 2000px; 5 | -------------------------------------------------------------------------------- /src/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github.expandinizr", 3 | "version": "0.0.0", 4 | "manifest_version": 2, 5 | "description": "Chrome extension that improves the GitHub experience", 6 | "homepage_url": "http://github.com/thecodejunkie/github.expandinizr", 7 | "icons": { 8 | "16": "icons/icon16.png", 9 | "48": "icons/icon48.png", 10 | "128": "icons/icon128.png" 11 | }, 12 | "permissions": [ 13 | "storage", 14 | "activeTab", 15 | "declarativeContent", 16 | "https://github.com/*", 17 | "https://gist.github.com/*" 18 | ], 19 | "optional_permissions": [ 20 | "http://*/", 21 | "https://*/" 22 | ], 23 | "options_ui": { 24 | "page": "content/options.html", 25 | "chrome_style": true, 26 | "open_in_tab": true 27 | }, 28 | "page_action": { 29 | "default_title": "Toggle ExpandinizR", 30 | "default_icon": { 31 | "19": "icons/icon19.png", 32 | "38": "icons/icon38.png" 33 | } 34 | }, 35 | "background": { 36 | "scripts": [ "content/background.min.js" ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 27 |
28 |
29 |

Github.ExpandinizR

30 |
31 |

Bellow is a list of authorized sites on which Github.ExpandinizR is allowed to run; add to and remove from this list as you see fit.

32 |
    33 |
  • 34 |
    35 |
    36 | 37 |
    38 |
    39 | 40 | 41 | 42 |
    43 |
    44 |
  • 45 |
46 |
47 |
48 |
49 | 50 | 51 | -------------------------------------------------------------------------------- /src/options.js: -------------------------------------------------------------------------------- 1 | var allPermissions = {} 2 | var extOptions = {} 3 | 4 | function getAuthorizedSites() { 5 | chrome.permissions.getAll( function (permissions) { 6 | allPermissions = permissions; 7 | }); 8 | } 9 | 10 | function showAuthorizedSites() { 11 | chrome.permissions.getAll( function (permissions) { 12 | allPermissions = permissions; 13 | chrome.storage.sync.get({ 14 | public_gist_enabled: true, 15 | public_github_enabled: true 16 | }, 17 | function(options) { 18 | extOptions = options; 19 | $.each(permissions.origins, function (key, value) { 20 | if (value == "https://gist.github.com/*" || value == "https://github.com/*") { 21 | // check options and set button 22 | var newItem = $("
  • \ 23 |
    \ 24 | \ 25 |
    \ 26 | " + value + "\ 27 |
  • "); 28 | if (value == "https://gist.github.com/*" && !extOptions.public_gist_enabled) { 29 | console.debug(value + " " + extOptions.public_gist_enabled); 30 | newItem.find("input") 31 | .removeClass("btn-danger") 32 | .addClass("btn-primary") 33 | .val("Enable") 34 | .click(function() { 35 | addAuthorizedSite(key, value); 36 | }); 37 | } else if (value == "https://github.com/*" && !extOptions.public_github_enabled) { 38 | console.debug(value + " " + extOptions.public_gist_enabled); 39 | newItem.find("input") 40 | .removeClass("btn-danger") 41 | .addClass("btn-primary") 42 | .val("Enable") 43 | .click(function() { 44 | addAuthorizedSite(key, value); 45 | }); 46 | } else { 47 | newItem.find("input").click(function() { 48 | removeAuthorizedSite(key, value); 49 | }); 50 | } 51 | $("#permissions").prepend(newItem); 52 | } else { 53 | var newItem = $("
  • \ 54 |
    \ 55 | \ 56 |
    \ 57 | " + value + "\ 58 |
  • "); 59 | newItem.find("input").click(function() { 60 | removeAuthorizedSite(key, value); 61 | }); 62 | $("#new_auth_url_item").before(newItem); 63 | } 64 | }); 65 | }); 66 | }); 67 | } 68 | 69 | function addAuthorizedSite(id, URL) { 70 | console.debug(id + " " + URL); 71 | if (id != undefined && URL != undefined) { 72 | if (URL == "https://gist.github.com/*") { 73 | chrome.storage.sync.set({ public_gist_enabled: true }); 74 | $("#new_auth_url_" + id) 75 | .find("input") 76 | .removeClass("btn-primary") 77 | .addClass("btn-danger") 78 | .val("Disable") 79 | .unbind("click") 80 | .click(function() { 81 | removeAuthorizedSite(id, URL); 82 | }); 83 | } else if (URL == "https://github.com/*") { 84 | chrome.storage.sync.set({ public_github_enabled: true }); 85 | $("#new_auth_url_" + id) 86 | .find("input") 87 | .removeClass("btn-primary") 88 | .addClass("btn-danger") 89 | .val("Disable") 90 | .unbind("click") 91 | .click(function() { 92 | removeAuthorizedSite(id, URL); 93 | }); 94 | } 95 | } else { 96 | var newURL = $("#new_auth_url").val().trim(); 97 | if (newURL != '') { 98 | if (newURL.slice(-2) != '/*') newURL = newURL + '/*' 99 | if (newURL.slice(-1) === '/') newURL = newURL + '*' 100 | } 101 | chrome.permissions.contains({ 102 | origins: [newURL] 103 | }, function(result) { 104 | if (result) { 105 | // The extension has the permissions already. 106 | $("li:contains(" + newURL + ")").addClass("highlight") 107 | .delay(4500) 108 | .queue(function() { 109 | $(this).removeClass("highlight"); 110 | $(this).dequeue(); 111 | }); 112 | $("#new_auth_url_msg").text("Duplicate URL - " + newURL); 113 | } else { 114 | // The extension doesn't have the permissions.s 115 | chrome.permissions.request({ 116 | origins: [newURL] 117 | }, function (granted) { 118 | if (granted) { 119 | getAuthorizedSites(); 120 | var new_auth_url_id = allPermissions.origins.length; 121 | 122 | var newItem = $("
  • \ 123 |
    \ 124 | \ 125 |
    \ 126 | " + newURL + "\ 127 |
  • "); 128 | newItem.find("input").click(function() { 129 | removeAuthorizedSite(new_auth_url_id, newURL); 130 | }); 131 | $("#new_auth_url_item").before(newItem); 132 | $("#new_auth_url").val(""); 133 | $("#new_auth_url_submit").prop('disabled', true); 134 | $("#new_auth_url_msg").text(""); 135 | } else { 136 | // permissions not granted (by user or error) 137 | var lastError = chrome.runtime.lastError; 138 | if (lastError) { 139 | console.log(lastError.message); 140 | $("#new_auth_url_msg").text(lastError.message); 141 | } 142 | } 143 | }); 144 | } 145 | }); 146 | } 147 | } 148 | 149 | function removeAuthorizedSite(id, URL) { 150 | var r = confirm("Really remove/disable " + URL + "?"); 151 | if (r) { 152 | chrome.permissions.contains({ 153 | origins: [URL] 154 | }, function(result) { 155 | if (result) { 156 | // The extension has the permissions. 157 | if (URL == "https://gist.github.com/*") { 158 | chrome.storage.sync.set({ public_gist_enabled: false }); 159 | $("#new_auth_url_" + id) 160 | .find("input") 161 | .removeClass("btn-danger") 162 | .addClass("btn-primary") 163 | .val("Enable") 164 | .unbind("click") 165 | .bind('click', function() { 166 | addAuthorizedSite(id, URL); 167 | }); 168 | } else if (URL == "https://github.com/*") { 169 | chrome.storage.sync.set({ public_github_enabled: false }); 170 | $("#new_auth_url_" + id) 171 | .find("input") 172 | .removeClass("btn-danger") 173 | .addClass("btn-primary") 174 | .val("Enable") 175 | .unbind("click") 176 | .bind('click', function() { 177 | addAuthorizedSite(id, URL); 178 | }); 179 | } else { 180 | chrome.permissions.remove({ 181 | origins: [URL] 182 | }, function(removed) { 183 | if (removed) { 184 | // The permissions have been removed. 185 | $("#new_auth_url_" + id).remove(); 186 | } else { 187 | // The permissions have not been removed (e.g., you tried to remove 188 | // required permissions). 189 | alert("Required permissions cannot be removed.") 190 | } 191 | }); 192 | } 193 | } else { 194 | // The extension doesn't have the permissions. 195 | console.debug("not found"); 196 | } 197 | }); 198 | } 199 | } 200 | 201 | function setupUI() { 202 | showAuthorizedSites(); 203 | $("#new_auth_url_submit").click(addAuthorizedSite); 204 | $("#new_auth_url").keyup( function () { 205 | if($(this).val() == '' ) { 206 | $("#new_auth_url_submit").prop("disabled", true); 207 | } else { 208 | $("#new_auth_url_submit").prop("disabled", false); 209 | } 210 | }); 211 | } 212 | 213 | document.addEventListener('DOMContentLoaded', setupUI); 214 | --------------------------------------------------------------------------------