-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restore options 31 #32
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
12ce972
added drop down list of valid codesy domains to options page
jdungan 8548e56
Merge branch 'master' of https://github.com/jdungan/chrome-extension
jdungan 59d9de7
refactor github.js
jdungan 109e698
add stackoverflow as a target
jdungan cb49e9b
delete github.js
jdungan 3376c4b
change to coffeescript, added gulp, added href watch
jdungan 6381033
hide install buttons
jdungan 777cd52
add xhr event to replace polling
jdungan c0a4c1a
iframe attempt
jdungan b096fa9
coffee source
jdungan ee582c2
remove options
jdungan a1ed8e2
add post calls to attempt CSRF auth - fail
jdungan 2e4ceb5
restore options coffee src
jdungan 681dd70
save storage line
jdungan 80f0d06
add auth input to options
jdungan 5613b71
remove minify and other code review stuff
jdungan 8061899
add options.html
jdungan 6f1925b
send token with bid change
jdungan 0d9fe1b
add package.json and tested npm install, node_modules in gitignore, w…
jdungan cb7641e
refine auth_token lookup
jdungan add49f9
added more logging and timing events
jdungan e7c64c0
point to https://api.codesy.io/
jdungan File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*.swp | ||
node_modules | ||
pkg | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,6 @@ | ||
form#codesy input { width: 100%; margin-bottom: .5em; } | ||
form#codesy_bid_form{ | ||
position: absolute; | ||
background: silver; | ||
margin-bottom: .5em; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
var gulp = require('gulp'); | ||
var gutil = require('gulp-util'); | ||
var coffee = require('gulp-coffee'); | ||
var watch = require('gulp-watch') | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
var stripDebug = require('gulp-strip-debug'); | ||
var zip = require('gulp-zip'); | ||
|
||
|
||
gulp.task('default', function() { | ||
// place code for your default task here | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's drop the |
||
|
||
gulp.task('coffee', function() { | ||
gulp.src('src/*.coffee') | ||
.pipe(coffee({bare: true}).on('error', gutil.log)) | ||
.pipe(gulp.dest('js/')) | ||
}); | ||
|
||
gulp.task('watch', function() { | ||
gulp.watch('./src/*.coffee',['coffee']) | ||
}); | ||
|
||
gulp.task('publish', function () { | ||
gulp.src('js/*.js') | ||
.pipe(stripDebug()) | ||
.pipe(gulp.dest('js/')) | ||
|
||
gulp.src([ | ||
'css/*', | ||
'img/*', | ||
'js/*.js', | ||
'manifest.json', | ||
'options.html', | ||
], {base: "."}) | ||
.pipe(zip('codesy.zip')) | ||
.pipe(gulp.dest('pkg/')); | ||
}); |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1,143 @@ | ||
"use strict"; | ||
var codesy; | ||
|
||
var codesy={}; | ||
console.time('codesy load'); | ||
|
||
(function (cdsy){ | ||
var pages = [ | ||
{ domain:/.github.com/i, | ||
target:{selector:'.discussion-sidebar'}, | ||
before_append:function(){}, | ||
after_append:function(){} | ||
codesy = { | ||
options: { | ||
form: { | ||
heigth: 100, | ||
width: 100 | ||
}, | ||
{ domain:/.bitbucket.org/i, | ||
target:{selector:'dl.issue-attrs', | ||
containers: ['<div class="issue-attr">'] } | ||
}, | ||
{ domain:/.sourceforge.net/i, | ||
target:{selector:'#sidebar', | ||
containers:['<li>','<ul class="sidebarmenu">'] | ||
} | ||
}, | ||
] | ||
|
||
cdsy.options = { | ||
endpoint: '/api', | ||
version: '/v1', | ||
domain: 'codesy-dev.herokuapp.com' | ||
url: "https://api.codesy.io/" | ||
}, | ||
form: null, | ||
bid: {}, | ||
current: { | ||
url: null | ||
} | ||
}; | ||
|
||
codesy.auth_token = function() { | ||
if (codesy.options.auth_token) { | ||
return codesy.options.auth_token; | ||
} else { | ||
|
||
cdsy.appendForm = function(mission,codesyImgUrl, csrfToken) { | ||
var dfd = new $.Deferred(), | ||
|
||
$codesy_link = $('<a href="http://codesy.io" target="_new"><img src="' + codesyImgUrl + '"/></a>' ), | ||
|
||
$codesy_form = $('<form>'), | ||
|
||
$submit_button = $('<button>') | ||
.attr('class','button minibutton') | ||
.text('Bid') | ||
.click(function(){$codesy_form.submit();}); | ||
|
||
$codesy_form | ||
.attr('id', 'codesy') | ||
.attr('action', 'https://' + cdsy.options.domain + '/bids') | ||
.attr('method', 'POST') | ||
.append('<input name="authenticity_token" type="hidden" value="' + csrfToken + '" />') | ||
.append('<input type="hidden" name="bid[url]" value="' + window.location + '" />') | ||
.append('<input type="text" placeholder="offer amount" id="bid_offer" name="bid[offer]"/><br/>') | ||
.append('<input type="text" placeholder="ask amount" id="bid_ask" name="bid[ask]"/><br/>') | ||
.append($submit_button); | ||
|
||
var $codesy_widget = $('<div id="codesy-widget" >') | ||
.append('<hr/>') | ||
.append($codesy_link) | ||
.append($codesy_form); | ||
|
||
if(mission.target.containers){ | ||
mission.target.containers.forEach(function(elem){ | ||
$codesy_widget = $(elem).append($codesy_widget) | ||
}) | ||
} | ||
|
||
$(mission.target.selector).first() | ||
.append($codesy_widget) | ||
|
||
|
||
if($('#codesy-widget').length > 0){ | ||
dfd.resolve() | ||
} else { | ||
dfd.reject() | ||
} | ||
}; | ||
|
||
codesy.bid.get = function(ajax_params) { | ||
console.log('codesy: ' + codesy.options.auth_token); | ||
ajax_params = ajax_params || {}; | ||
return $.ajax({ | ||
beforeSend: function(xhr, settings) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
return xhr.setRequestHeader("Authorization", "Token " + codesy.options.auth_token); | ||
}, | ||
type: "get", | ||
url: codesy.options.url + '/bid/', | ||
data: ajax_params, | ||
dataType: "html" | ||
}); | ||
}; | ||
|
||
codesy.bid.update = function(form) { | ||
form = form || {}; | ||
return $.ajax({ | ||
beforeSend: function(xhr, settings) { | ||
return xhr.setRequestHeader("Authorization", "Token " + codesy.options.auth_token); | ||
}, | ||
type: form.attr('method'), | ||
url: form.attr('action'), | ||
data: form.serialize(), | ||
dataType: "html", | ||
success: function(data) { | ||
return codesy.newpage(); | ||
}, | ||
error: function(err) { | ||
console.log('codesy: bid update failed'); | ||
return console.log(err); | ||
} | ||
|
||
return dfd.promise() | ||
}); | ||
}; | ||
|
||
codesy.isIssue = function(url) { | ||
var rx; | ||
console.log('codesy isIssue : ' + url); | ||
rx = /https:\/\/github.com\/.*\/issues\/./g; | ||
return rx.test(url); | ||
}; | ||
|
||
codesy.positionForm = function() { | ||
var footerLeft, footerTop; | ||
footerTop = $(window).scrollTop() + $(window).height() - codesy.options.form.heigth; | ||
footerLeft = $(window).width() - codesy.options.form.width; | ||
if (($(document.body).height() + footerTop) > $(window).height()) { | ||
return codesy.form.css({ | ||
position: "absolute", | ||
top: footerTop, | ||
left: footerLeft | ||
}); | ||
} else { | ||
return codesy.form.css({ | ||
position: "static", | ||
top: footerTop, | ||
left: footerLeft | ||
}); | ||
} | ||
|
||
cdsy.match = function(location){ | ||
var dfd = new $.Deferred(), | ||
url = location.toString() || dfd.reject('No url defined') | ||
|
||
pages.forEach(function(value){ | ||
if (value.domain.test(url)){ | ||
dfd.resolve(value); | ||
} | ||
}) | ||
|
||
return dfd.promise(); | ||
}; | ||
|
||
codesy.appendForm = function(form_html) { | ||
var dfd; | ||
dfd = new $.Deferred(); | ||
$("body").append(form_html); | ||
if ($("#codesy_bid_form").length > 0) { | ||
codesy.form = $("#codesy_bid_form"); | ||
codesy.positionForm(); | ||
codesy.form.submit(function(e) { | ||
e.preventDefault(); | ||
codesy.bid.update(codesy.form); | ||
return false; | ||
}); | ||
$(window).scroll(codesy.positionForm).resize(codesy.positionForm); | ||
dfd.resolve(); | ||
} else { | ||
dfd.reject(); | ||
} | ||
return dfd.promise(); | ||
}; | ||
|
||
codesy.newpage = function() { | ||
$("#codesy_bid_form").remove(); | ||
if (codesy.isIssue(window.location.href)) { | ||
console.log('codesy: needs bid form'); | ||
console.time("codesy: request form"); | ||
return codesy.bid.get({ | ||
url: window.location.href | ||
}).done(function(data) { | ||
console.timeEnd("codesy: request form"); | ||
return codesy.appendForm(data); | ||
}).fail(function(data) { | ||
console.timeEnd("codesy: request form"); | ||
console.log("codesy: $.ajax failed."); | ||
return console.log(data); | ||
}); | ||
} | ||
}; | ||
|
||
//generic call | ||
var call_api = function(resource, ajax_params) { | ||
ajax_params = ajax_params || {}; | ||
return $.ajax({ | ||
type: "get", | ||
url: "https://" + cdsy.options.domain + cdsy.options.endpoint + cdsy.options.version+resource, | ||
data: ajax_params, | ||
dataType: 'json' | ||
}) | ||
}; | ||
|
||
function API(domain){ | ||
cdsy.options.domain = domain || cdsy.options.domain; | ||
var call_map = [ | ||
['csrf_token','/csrf_token.json'], | ||
['bids', '/bids.json'] | ||
]; | ||
call_map.forEach(function(value) { | ||
this.prototype[value[0]] = function(params) { | ||
return call_api(value[1], params) | ||
} | ||
},API); | ||
|
||
} | ||
|
||
cdsy.api = new API; | ||
chrome.storage.local.get(function(data) { | ||
codesy.options.auth_token = data.auth_token; | ||
return codesy.newpage(); | ||
}); | ||
|
||
}(codesy)); | ||
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { | ||
console.log("codesy: xhr received"); | ||
if (msg.url) { | ||
return codesy.newpage(); | ||
} | ||
}); | ||
|
||
window.onpopstate = function() { | ||
console.log("codesy: popstate"); | ||
return codesy.newpage(); | ||
}; | ||
|
||
console.timeEnd('codesy load'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"version": 3, | ||
"file": "codesy.js", | ||
"sourceRoot": "..", | ||
"sources": [ | ||
"js/codesy.coffee" | ||
], | ||
"names": [], | ||
"mappings": ";AAAA;AAAA,EAAA,YAAA,CAAA;AAAA,MAAA,MAAA;;AAAA,EACA,MAAA,GAAS,EADT,CAAA;;AAAA,EAGA,MAAM,CAAC,KAAP,GAAe;IACX;AAAA,MACE,MAAA,EAAQ,cADV;AAAA,MAEE,MAAA,EACE;AAAA,QAAA,QAAA,EAAU,qBAAV;OAHJ;KADW,EAMX;AAAA,MACE,MAAA,EAAQ,iBADV;AAAA,MAEE,MAAA,EACE;AAAA,QAAA,QAAA,EAAU,gBAAV;AAAA,QACA,UAAA,EAAY,CAAC,4BAAD,CADZ;OAHJ;KANW,EAYX;AAAA,MACE,MAAA,EAAQ,mBADV;AAAA,MAEE,MAAA,EACE;AAAA,QAAA,QAAA,EAAU,UAAV;AAAA,QACA,UAAA,EAAY,CACV,MADU,EAEV,4BAFU,CADZ;OAHJ;KAZW,EAqBX;AAAA,MACE,MAAA,EAAQ,qBADV;AAAA,MAEE,MAAA,EACE;AAAA,QAAA,QAAA,EAAU,UAAV;OAHJ;KArBW;GAHf,CAAA;;AAAA,EA+BA,MAAM,CAAC,OAAP,GACI;AAAA,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,CAAA,CAAE,OAAO,CAAC,MAAM,CAAC,QAAjB,CAA0B,CAAC,KAA3B,CAAA,CAAkC,CAAC,MAAnC,CAA0C,cAA1C,CAdA,CAAA;AAeA,IAAA,IAAG,CAAA,CAAE,gBAAF,CAAmB,CAAC,MAApB,GAA6B,CAAhC;AACE,MAAA,GAAG,CAAC,OAAJ,CAAA,CAAA,CADF;KAAA,MAAA;AAGE,MAAA,GAAG,CAAC,MAAJ,CAAA,CAAA,CAHF;KAfA;WAmBA,GAAG,CAAC,OAAJ,CAAA,EApBgB;EAAA,CA7DpB,CAAA;;AAAA,EAmFA,MAAM,CAAC,KAAP,GAAe,SAAC,QAAD,GAAA;AACX,QAAA,8BAAA;AAAA,IAAA,GAAA,GAAU,IAAA,CAAC,CAAC,QAAF,CAAA,CAAV,CAAA;AAAA,IACA,GAAA,GAAM,QAAQ,CAAC,QAAT,CAAA,CAAA,IAAuB,GAAG,CAAC,MAAJ,CAAW,gBAAX,CAD7B,CAAA;AAEA,UACK,SAAC,KAAD,GAAA;AACD,MAAA,IAAsB,KAAK,CAAC,MAAM,CAAC,IAAb,CAAkB,GAAlB,CAAtB;eAAA,GAAG,CAAC,OAAJ,CAAY,KAAZ,EAAA;OADC;IAAA,CADL;AAAA,SAAA,4CAAA;wBAAA;AACE,UAAI,MAAJ,CADF;AAAA,KAFA;WAKA,GAAG,CAAC,OAAJ,CAAA,EANW;EAAA,CAnFf,CAAA;AAAA" | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add .DS_Store