Created
August 4, 2016 23:23
-
-
Save koush/18a6c40b7d04cf250da80e34792d3d9a to your computer and use it in GitHub Desktop.
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
function getAuthToken(interactive, cb) { | |
chrome.identity.getAuthToken({ | |
interactive: interactive, | |
// must use the exact same scopes used to submit the license or the token shits | |
scopes: | |
['https://www.googleapis.com/auth/userinfo.profile', | |
'https://www.googleapis.com/auth/userinfo.email', | |
'https://www.googleapis.com/auth/chromewebstore.readonly'] | |
}, | |
function(token) { | |
if (!token) | |
console.error('unable to get authToken', chrome.runtime.lastError) | |
cb(token); | |
}); | |
} | |
(function() { | |
var log = console.log; | |
var error = console.error; | |
var current = ''; | |
console.log = function() { | |
log.apply(console, arguments); | |
var args = Array.prototype.slice.call(arguments); | |
current += args.join(' ') + '\n'; | |
} | |
window.getConsoleLog = function() { | |
return current; | |
} | |
function getLogFromWindow(w) { | |
return (w.getConsoleLog && w.getConsoleLog()) || 'getConsoleLog not found'; | |
} | |
window.gistConsoleLog = function(cb) { | |
chrome.runtime.getBackgroundPage(function(background) { | |
var files = {}; | |
files['background.txt'] = { | |
content: getLogFromWindow(background) | |
} | |
var windows = chrome.app.window.getAll(); | |
for (var w in windows) { | |
w = windows[w]; | |
files['window-' + w.id + '.txt'] = { | |
content: getLogFromWindow(w.contentWindow) | |
} | |
} | |
var gist = { | |
"description": chrome.runtime.getManifest().name + ' console log', | |
"public": true, | |
"files": files | |
} | |
fetch('https://api.github.com/gists', { | |
method: 'POST', | |
body: JSON.stringify(gist) | |
}) | |
.then(function(response) { | |
response.json().then(function(json) { | |
cb(json.html_url); | |
}) | |
}) | |
}); | |
} | |
})(); | |
I feel happy now to join with github.thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
get me updates