Skip to content

Commit

Permalink
Merge pull request #26 from leonhartX/add-star
Browse files Browse the repository at this point in the history
add star with token
  • Loading branch information
leonhartX authored Jul 31, 2017
2 parents 2077130 + 06ab1c3 commit 6ba763f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 19 deletions.
4 changes: 4 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
machine:
node:
version: 6.1.0

dependencies:
override:
- npm install --dev
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.2",
"version": "2.0.3",
"manifest_version": 2,
"default_locale": "en",
"name": "__MSG_appName__",
Expand Down
4 changes: 4 additions & 0 deletions options/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
.form .login-container .login-item-otp {
display: none;
}
.form p input {
width: 15px;
margin: 15px 0 0 0;
}


body {
Expand Down
2 changes: 2 additions & 0 deletions options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
<input id="otp" type="text" placeholder="authentication code">
</div>
<button id="login">github login</button>
<p class="label"><input type="checkbox" name="star" id="star">Star this extension on Github for support</p>
<p class="message">Using Github Enterprise? <a href="#">Login to Github Enterprise</a></p>
<p class="error" style="display: none">Can not create access token, please check your username and password.</p>
</div>
Expand All @@ -41,6 +42,7 @@ <h2>Logged in as: <a target="_blank" id="login-user">XXX</a></h2>
<input id="ghe-otp" type="text" placeholder="authentication code">
</div>
<button id="ghe-login">github enterprise login</button>
<p class="message">Please star this extension on <a href="https://github.com/leonhartX/gas-github">Github</a> for support</p>
<p class="message">Using github.com? <a href="#">Login to github.com</a></p>
<p class="error" style="display: none">Can not create access token, please check your GHE domain, username and password.</p>
</div>
Expand Down
60 changes: 42 additions & 18 deletions options/options.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"use strict";
$(() => {
$('.message a').click(function(){
$('.error').hide();
$('.login-container').animate({height: "toggle", opacity: "toggle"}, "slow");
$('.error').hide();
$('.login-container').animate({height: "toggle", opacity: "toggle"}, "slow");
});
$('#login').click((e) => {
addCred(getGithubParam());
Expand Down Expand Up @@ -80,14 +80,18 @@ function addCred(param) {
}

if (param.password !== "") return loginGithub(param);
chrome.storage.sync.set({ user: param.username, token: param.token, baseUrl: param.baseUrl}, () => {
location.reload();
});
chrome.storage.local.get("tab", (item) => {
if(item.tab) {
chrome.tabs.reload(item.tab);
}
});

addStar(param.token)
.then(() => {
chrome.storage.sync.set({ user: param.username, token: param.token, baseUrl: param.baseUrl}, () => {
location.reload();
});
chrome.storage.local.get("tab", (item) => {
if(item.tab) {
chrome.tabs.reload(item.tab);
}
});
})
}

function loginGithub(param) {
Expand Down Expand Up @@ -117,14 +121,17 @@ function loginGithub(param) {
data: JSON.stringify(payload)
})
.done((response) => {
chrome.storage.sync.set({ user: username, token: response.token, baseUrl: baseUrl}, () => {
location.reload();
});
chrome.storage.local.get("tab", (item) => {
if(item.tab) {
chrome.tabs.reload(item.tab);
}
});
addStar(response.token)
.then(() => {
chrome.storage.sync.set({ user: username, token: response.token, baseUrl: baseUrl}, () => {
location.reload();
});
chrome.storage.local.get("tab", (item) => {
if(item.tab) {
chrome.tabs.reload(item.tab);
}
});
})
})
.fail((err) => {
if (err.status == 401 &&
Expand Down Expand Up @@ -157,4 +164,21 @@ function checkToken() {
else reject(new Error("can not get access token"));
});
})
}

function addStar(token) {
if(!$('#star').is(':checked') || $('#star').is(':hidden')) {
return Promise.resolve(null);
}
return new Promise(resolve => {
$.ajax({
url: `https://api.github.com/user/starred/leonhartX/gas-github`,
headers: {
"Content-Length": 0,
"Authorization": `token ${token}`
},
method: "PUT",
})
.always(resolve);
})
}

0 comments on commit 6ba763f

Please sign in to comment.