-
Notifications
You must be signed in to change notification settings - Fork 7
/
background.js
65 lines (58 loc) · 2.65 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
chrome.tabs.onUpdated.addListener(function (tabId, changedInfo, tab) {
console.log('TAB ID = ' + tabId);
if (changedInfo.status === 'complete') {
var GITHUB_URL = "github.com";
var tabUrl = tab.url;
if (tabUrl.indexOf(GITHUB_URL) > -1) {
var JAVA_SOURCE_REGEX = /^(https?):\/\/(github\.com)\/([\w]+)\/([\S]+)\/blob\/([\w]+)\/(.*)\/(src\/main\/java)\/(.*)\/([\w]+\.java)/;
var result = tabUrl.match(JAVA_SOURCE_REGEX);
if (result) {
var len = result.length;
console.log(result);
var protocol = result[1]; // http or https
var domain = result[2]; // github.com
var userName = result[3]; // github username. for example: ishan1604
var repositoryName = result[4]; // github repo name. for example: hoppr
var branchName = result[5]; // current branch. for example: master
var modulename = result[6]; // gradle project module name. for example : mobile
var sourceCodeFolder = result[7]; // root folder java packages are stored. for example: src/main/java
var className = result[len - 1];
var packageNameWithSlashes = result[len - 2];
var packageName = packageNameWithSlashes.replace(/\//g, ".");
console.log("Package Name : " + packageName);
console.log("Class Name : " + className);
var messagePayload = {
task: "activate_class_links",
protocol: result[1], // http or https
domain: result[2], // github.com
userName: result[3], // github username. for example: ishan1604
repositoryName: result[4], // github repo name. for example: hoppr
branchName: result[5], // current branch. for example: master
modulename: result[6], // gradle project module name. for example : mobile
sourceCodeFolder: result[7], // root folder java packages are stored. for example: src/main/java
packageName: packageName
}
/*
https://github.com/NewsInShorts/inshortsapp/blob/master/mobile/src/main/java/com/nis/app/agents/AppAgent.java
Now from a URL like above extract out the current package we are in, for example
Package Name = com.nis.app.agents
Class Name = AppAgent
*/
chrome.tabs.sendMessage(tab.id, messagePayload,
doStuffWithDOM);
}
}
}
});
/* A function creator for callbacks */
function doStuffWithDOM(dataToBeLogged) {
// console.log("I received the following DOM content:\n" + dataToBeLogged);
if (jQuery) {
console.log('Jquery Loaded');
// jQuery loaded
console.log(dataToBeLogged);
} else {
// jQuery not loaded
console.log('Jquery Not Loaded Yet');
}
}