Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Switch to GitLab Next
Sign in / Register
Toggle navigation
Open sidebar
Christian
reddmeet-chrome-extension
Commits
84e44157
Commit
84e44157
authored
Feb 21, 2016
by
Christian
Browse files
back to browser action and popup
parent
cc945f93
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
131 deletions
+18
-131
background.js
background.js
+0
-89
content.js
content.js
+0
-2
manifest.json
manifest.json
+3
-9
popup.html
popup.html
+0
-7
popup.js
popup.js
+15
-24
No files found.
background.js
deleted
100644 → 0
View file @
cc945f93
Object
.
prototype
.
getName
=
function
()
{
var
funcNameRegex
=
/function
(
.
{1,})\(
/
;
var
results
=
(
funcNameRegex
).
exec
((
this
).
constructor
.
toString
());
return
(
results
&&
results
.
length
>
1
)
?
results
[
1
]
:
""
;
};
// http://stackoverflow.com/a/13486540/5520354
function
unique_set
(
arr
)
{
return
arr
.
filter
(
function
(
e
,
i
,
arr
)
{
return
arr
.
lastIndexOf
(
e
)
===
i
;
});
}
///////////////////////////////////////////////////////////////////////
var
currCount
=
0
;
var
currUsers
=
null
;
console
.
log
(
'
--> background.js: This is the background page, yo!
'
);
chrome
.
webNavigation
.
onDOMContentLoaded
.
addListener
(
function
(
tabDetails
)
{
// details.tabId The ID of the tab in which the navigation occurs.
// details.url
// details.processId The ID of the process runs the renderer for this tab.
// details.frameId 0 indicates the navigation happens in the tab content window;
// a positive value indicates navigation in a subframe.
// Frame IDs are unique within a tab.
// details.timeStamp The time when the page's DOM was fully constructed,
// in milliseconds since the epoch.
if
(
tabDetails
.
frameId
>
0
)
return
;
// Only watch tab level frames.
console
.
log
(
'
--> background.js: webNavigation.onCompleted at:
'
+
tabDetails
.
url
);
if
(
isRedditUrl
(
tabDetails
.
url
))
{
currCount
+=
1
;
console
.
log
(
'
--> background.js: Hey, tab isRedditUrl, yo! Counter:
'
+
currCount
);
console
.
log
(
'
--> background.js:
'
,
tabDetails
);
chrome
.
tabs
.
sendMessage
(
tabDetails
.
tabId
,
{
text
:
'
harvest_usernames
'
},
function
(
userlist
)
{
if
(
userlist
)
{
console
.
log
(
'
--> background.js: SUCCESS: harvested userlist for tabId "
'
+
tabDetails
.
tabId
+
'
"
'
);
receiveUserlist
(
tabDetails
,
userlist
);
}
else
{
console
.
log
(
'
--> background.js: ERROR: could not harvest userlist for tabId "
'
+
tabDetails
.
tabId
+
'
"
'
);
return
;
}
});
};
});
///////////////////////////////////////////////////////////////////////
function
isRedditUrl
(
url
)
{
var
re
=
new
RegExp
(
"
^https
\
://www
\
.reddit
\
.com/r/
"
);
return
url
.
match
(
re
);
}
//function getCurrentTabUrl(callback) {
// var queryInfo = { active: true, currentWindow: true, };
// chrome.tabs.query(queryInfo, function(tabs) {
// var tab = tabs[0];
// callback(tab);
// });
//}
function
receiveUserlist
(
tabDetails
,
userlist
)
{
console
.
log
(
'
--> background.js: raw userlist.length:
'
+
userlist
.
length
);
userlist
=
unique_set
(
userlist
);
console
.
log
(
'
--> background.js: unique userlist.length:
'
+
userlist
.
length
);
userlist
=
queryReddmeetUsernames
(
userlist
);
console
.
log
(
'
--> background.js: members userlist length:
'
+
userlist
.
length
);
chrome
.
tabs
.
sendMessage
(
tabDetails
.
tabId
,
{
text
:
'
mark_members
'
,
'
userlist
'
:
userlist
},
function
(
response
){
console
.
log
(
'
--> background.js: Return from "mark_members" message:
'
+
response
);
});
}
function
renderStatus
(
statusText
)
{
//document.getElementById('status').textContent += '\n' + statusText;
}
function
queryReddmeetUsernames
(
users
)
{
// For a list of usernames, query the reddmeet API if they have an account.
// The API returns a list of usernames that do have a reddmeet profile.
// ::: TODO :::
return
users
;
}
content.js
View file @
84e44157
...
...
@@ -3,8 +3,6 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
console
.
log
(
'
--> content.js: chrome.runtime.onMessage.addListener
'
);
console
.
log
(
'
--> content.js: msg.text:
'
+
msg
.
text
);
debugger
;
if
(
msg
.
text
==
'
harvest_usernames
'
)
{
console
.
log
(
'
--> content.js: msg.text == "harvest_usernames"
'
);
sendResponse
([
'
user1
'
,
'
user2
'
,
'
user3
'
]);
...
...
manifest.json
View file @
84e44157
...
...
@@ -5,13 +5,9 @@
"description"
:
"Adds a link to usernames with a reddmeet profile."
,
"version"
:
"0.1"
,
"background"
:
{
"persistent"
:
true
,
"scripts"
:
[
"background.js"
,
"content.js"
]
},
"page_action"
:
{
"default_icon"
:
"icon.png"
"browser_action"
:
{
"default_icon"
:
"icon.png"
,
"default_popup"
:
"popup.html"
},
"content_scripts"
:
[{
...
...
@@ -21,8 +17,6 @@
"permissions"
:
[
"activeTab"
,
"webNavigation"
,
"tabs"
,
"https://reddmeet.com/"
]
}
popup.html
View file @
84e44157
...
...
@@ -13,13 +13,6 @@
overflow
:
hidden
;
}
</style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: https://developer.chrome.com/extensions/contentSecurityPolicy
-->
<script
src=
"popup.js"
></script>
<script
src=
"content.js"
></script>
</head>
...
...
popup.js
View file @
84e44157
XXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXX
Object
.
prototype
.
getName
=
function
()
{
var
funcNameRegex
=
/function
(
.
{1,})\(
/
;
var
results
=
(
funcNameRegex
).
exec
((
this
).
constructor
.
toString
());
return
(
results
&&
results
.
length
>
1
)
?
results
[
1
]
:
""
;
};
// http://stackoverflow.com/a/13486540/5520354
function
unique_set
(
arr
)
{
return
arr
.
filter
(
function
(
e
,
i
,
arr
)
{
return
arr
.
lastIndexOf
(
e
)
===
i
;
});
}
///////////////////////////////////////////////////////////////////////
var
currCount
=
0
;
var
currTab
=
null
;
var
currUsers
=
null
;
...
...
@@ -41,10 +19,8 @@ document.addEventListener('DOMContentLoaded', function() {
});
});
///////////////////////////////////////////////////////////////////////
function
isRedditUrl
(
url
)
{
var
re
=
new
RegExp
(
"
^https?://(
\
w+
\
.)+reddit.com(:
\
d+)?[$/]
"
);
return
url
.
match
(
re
);
...
...
@@ -80,3 +56,18 @@ function queryReddmeetUsernames(users) {
// ::: TODO :::
return
users
;
}
///////////////////////////////////////////////////////////////////////
Object
.
prototype
.
getName
=
function
()
{
var
funcNameRegex
=
/function
(
.
{1,})\(
/
;
var
results
=
(
funcNameRegex
).
exec
((
this
).
constructor
.
toString
());
return
(
results
&&
results
.
length
>
1
)
?
results
[
1
]
:
""
;
};
// http://stackoverflow.com/a/13486540/5520354
function
unique_set
(
arr
)
{
return
arr
.
filter
(
function
(
e
,
i
,
arr
)
{
return
arr
.
lastIndexOf
(
e
)
===
i
;
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment