Skip to content

Commit

Permalink
got the pane to grab the dev info URL and trying to do things
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon McLaren committed Feb 1, 2019
1 parent 66ee912 commit 379a762
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 7 deletions.
4 changes: 2 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ chrome.runtime.onMessage.addListener(
}
);


/*
chrome.runtime.onConnect.addListener(function(devToolsConnection) {
// assign the listener function to a variable so we can remove it later
var devToolsListener = function(message, sender, sendResponse) {
Expand All @@ -50,7 +50,7 @@ chrome.runtime.onConnect.addListener(function(devToolsConnection) {
devToolsConnection.onMessage.removeListener(devToolsListener);
});
});

*/


chrome.commands.onCommand.addListener(function(command) {
Expand Down
7 changes: 4 additions & 3 deletions devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ var Panel = chrome.devtools.panels.create(
"icon-16.png",
"/panel.html"
);

console.log("devtools.js ran");
/*
var backgroundPageConnection = chrome.runtime.connect({
name: "devtools-page"
});
Expand All @@ -12,7 +13,7 @@ backgroundPageConnection.onMessage.addListener(function (message) {
// Handle responses from the background page, if any
});
console.log("devtools.js ran");
Expand All @@ -33,4 +34,4 @@ chrome.permissions.contains({
}
});

*/
27 changes: 26 additions & 1 deletion hsInspector.js
Original file line number Diff line number Diff line change
@@ -1 +1,26 @@
console.log("hsinspector js loaded!");
console.log("hsinspector js loaded!");

var devInfoLinks = document.querySelectorAll(".hs-tools-menu a");

devInfoLinks.forEach(function(el,i){
var linkURL = el.getAttribute("href");
var linkText = el.textContent;
if (linkText.includes("Developer Info")){
console.log(linkText,linkURL);
chrome.runtime.sendMessage({devInfoURL: linkURL}, function(response) {
console.log(response.farewell);
});
}



});

/*
function ready(fn) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}*/
3 changes: 2 additions & 1 deletion panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
</head>
<body>
<h1>omfg it works</h1>
<button id="load">Load Dev Info</button>
<!--<button id="load">Load Dev Info</button>-->
<iframe id="#dummy" onLoad="alert(this.contentWindow.location);"></iframe>
<script src="/jquery-3.2.1.min.js"></script>
<script src="panel.js"></script>
</body>
Expand Down
108 changes: 108 additions & 0 deletions panel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,111 @@
console.log("paneljs loaded");
/*
var test = chrome.devtools.inspectedWindow.eval(
"jQuery.fn.jquery",
function(result, isException) {
if (isException){
console.log("the page is not using jQuery");
return false;
}
else{
console.log("The page is using jQuery v" + result);
return true;
}
}
);
console.log("test:",test);
*/

function getLink(){
console.log("woo I made it!");
}
chrome.tabs.executeScript(chrome.devtools.inspectedWindow.tabId,
{ file: "hsInspector.js" });

chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.devInfoURL){
sendResponse({farewell: "devInfoURL recieved."});
$("h1").text(request.devInfoURL);

$("#dummy").attr('src',request.devInfoURL);


/*
function getUrlVars(){
var vars = [], hash;
var hashes = request.devInfoURL.slice(request.devInfoURL.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
console.log(getUrlVars());
var devInfoData = getUrlVars();
console.log("PORTAL ID:",devInfoData.portalId)
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
var envSuffix = (window.location.hostname.indexOf('qa') !== -1) ? 'qa' : '';
var url = devInfoData.url,
portalId = devInfoData.portalId,
loginApiHost = 'login.hubspot' + envSuffix + '.com',
apiHost = 'api.hubapi' + envSuffix + '.com',
parser = document.createElement('a');
parser.href = url;
$.ajax({
type: 'POST',
url: 'https://' + loginApiHost + '/login/api-verify',
data: {'portalId':portalId},
xhrFields: {
withCredentials: true
}
}).done(function(loginData) {
var accessToken = loginData.auth.access_token.token;
$.ajax({
url: 'https://' + apiHost + '/content/api/v4/domains/by-domain?portalId=' + portalId + '&domain=' + parser.hostname + '&access_token=' + accessToken,
xhrFields: {
withCredentials: true
}
}).done(function(domainData) {
if (domainData.isResolving) {
var redir = parser.protocol + '//' + parser.hostname + '/__context__' + parser.pathname + parser.search;
redir += (redir.indexOf('?') !== -1) ? '&' : '?';
redir += 'portalId=' + portalId + '&access_token=' + accessToken;
window.location.href = redir;
}
});
}).fail(function() {
window.location.href = 'https://' + loginApiHost + '/login';
});
*/


}
}

);

/*
document.querySelector('#load').addEventListener('click', function(event) {
// Permissions must be requested from inside a user gesture, like a button's
// click handler.
Expand All @@ -16,3 +123,4 @@ document.querySelector('#load').addEventListener('click', function(event) {
}
});
});
*/

0 comments on commit 379a762

Please sign in to comment.