Commit ccfaf579 authored by Christian's avatar Christian
Browse files

Initial commit

parents
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.text === 'get_all_usernames') {
sendResponse(findRedditUsernames());
}
});
function findRedditUsernames() {
var d = document.all[0];
if (domContent) {
//domContent = domContent.replace('\n', ' ');
//domContent = domContent.replace('\r', ' ');
var matches = [];
// Use DOM transverse to find usernames -----
var all = document(domContent).querySelectorAll('.author');
for (var i=0; i<all.length; i++) {
matches.push(all[i].href);
}
// Use Regex to find usernames -----
// g -> global match
// m -> multiline
/*
var re = new RegExp('(?:\<a href\=\"https?\://www\.reddit\.com/user/)([a-zA-Z0-9_-]+)(?:/?\" )', 'gm');
var match = null;
while (match = re.exec(domContent)) {
if ( matches.indexOf(match[1]) < 0 )
matches.push(match[1]);
} */
if (matches) {
renderStatus('Regex raw username matches: ' + matches.length);
return matches;
} else {
renderStatus('Regex did not find any username matches.');
}
}
return [];
}
\ No newline at end of file
{
"manifest_version": 2,
"name": "reddmeet for reddit",
"description": "Adds a link to usernames with a reddmeet profile.",
"version": "0.1",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [{
"matches": ["*://*.reddit.com/*"],
"js": ["content.js"]
}],
"permissions": [
"activeTab",
"https://reddmeet.com/"
]
}
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
font-family: "Segoe UI", "Lucida Grande", Tahoma, sans-serif;
font-size: 100%;
width: 500px;
}
#status {
white-space: normal;
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>
<body>
<div id="status"></div>
</body>
</html>
Object.prototype.getName = function() {
var funcNameRegex = /function (.{1,})\(/;
var results = (funcNameRegex).exec((this).constructor.toString());
return (results && results.length > 1) ? results[1] : "";
};
///////////////////////////////////////////////////////////////////////
document.addEventListener('DOMContentLoaded', function() {
renderStatus('Loading...');
getCurrentTabUrl(function(tab) {
if ( isRedditUrl(tab.url) ) {
renderStatus('This is Reddit...');
chrome.tabs.sendMessage(tab.id, {text: 'get_all_usernames'}, receiveUsernamesList);
}
else {
renderStatus('Some other website.');
};
});
});
///////////////////////////////////////////////////////////////////////
function isRedditUrl(url) {
var re = new RegExp("^https?://(\w+\.)+reddit.com(:\d+)?[$/]");
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 receiveUsernamesList(usernamesList) {
// receives document.all[0] object from content.js
// domContent = domContent ? domContent : '';
renderStatus('DOM content with ' + domContent.length + ' chars... ');
var text = 'Still loading...';
if (domContent) {
var foundUser = findRedditUsernames(domContent);
rmUsers = queryReddmeetUsernames(foundUser);
text = 'FOUND: ';
for (var i=0; i<rmUsers.length && i<100; i++)
text += rmUsers[i] + ', ';
}
renderStatus(text);
}
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;
}
/* chrome.browserAction.onClicked.addListener(function (tab) { }); */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment