This repository has been archived by the owner on Jan 11, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added the twitter creation date extension
- Loading branch information
Showing
5 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<script> | ||
chrome.extension.onRequest.addListener( | ||
function(request, sender, sendResponse) { | ||
var xhr = new XMLHttpRequest(); | ||
xhr.open("GET", "https://api.twitter.com/1/users/show/"+ request.screen_name + ".json", true); | ||
xhr.send(); | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState == 4) { | ||
if (xhr.status == 200) { | ||
sendResponse(JSON.parse(xhr.responseText)); | ||
} else { | ||
sendResponse({}); | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
</script> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Update created_at value on profile page. | ||
function creation_updatePage(response) { | ||
if(response.created_at) { | ||
var created_at = new Date(response.created_at); | ||
$('#creation_stat').text(created_at.toDateString()); | ||
} | ||
} | ||
|
||
// Identify and validate profile and initiate API call. | ||
var page = $('meta[name=page-user-screen_name]')[0]; | ||
var primary = $('#primary_nav'); | ||
if(page && primary) { | ||
insertLi('http://abrah.am/', '???'); | ||
chrome.extension.sendRequest({screen_name: page.content}, creation_updatePage); | ||
} | ||
|
||
// Insert <li> into profile page | ||
function insertLi(link, text) { | ||
var stat = $('<span>' + text + '</span>'); | ||
stat.addClass('stat_count'); | ||
stat.attr('id', 'creation_stat'); | ||
|
||
var title = $('<span>Created</span>'); | ||
|
||
var anchor = $('<a href="' + link + '"></a>'); | ||
anchor.attr('target', '_blank'); | ||
anchor.attr('id', 'creation_anchor'); | ||
anchor.attr('title', 'Twitter Creation extension built by Abraham Williams (@abraham)'); | ||
anchor.append(stat).append(title); | ||
|
||
var tab = $('<li></li>'); | ||
tab.attr('id', 'creation_tab'); | ||
tab.append(anchor); | ||
|
||
var nav = $('#primary_nav'); | ||
nav.append(tab); | ||
} |
Oops, something went wrong.