Permalink
Browse files

Revert "Added session caching for created dates"

This reverts commit 046192b.
  • Loading branch information...
1 parent 046192b commit 98322f651b1aefb7675fd02782f2f643e675a537 @abraham committed May 23, 2012
Showing with 20 additions and 57 deletions.
  1. BIN born.zip
  2. +3 −21 born/background.js
  3. +16 −32 born/content.js
  4. +1 −4 born/manifest.json
View
Binary file not shown.
View
@@ -1,40 +1,22 @@
chrome.extension.onRequest.addListener(handleUserId);
function handleUserId(request, sender, sendResponse) {
- // Return cached date if present
- if (sessionStorage.getItem(getCacheName(request.userId))) {
- var data = { createdAt: sessionStorage.getItem(getCacheName(request.userId)), userId: request.userId };
- sendResponse({ status: 200, data: data });
- return;
- }
-
+ // TODO: check for cached data
var xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.twitter.com/1/users/show.json?user_id=" + request.userId, true);
xhr.send();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
- var response = { status: xhr.status };
- if (xhr.status === 200) {
- var profile = JSON.parse(xhr.responseText);
- response.createdAt = profile.created_at;
- response.userId = profile.id;
- sessionStorage.setItem(getCacheName(profile.id), profile.created_at);
- }
- sendResponse({ status: xhr.status, data: response });
+ // TODO: cache success data
+ sendResponse({ status: xhr.status, response: JSON.parse(xhr.responseText) });
}
}
}
-// Diplay notification if new install
-// TODO: remove at some point in the future
if (localStorage.getItem('installed') !== 'true') {
var url = chrome.extension.getURL('cracked-twitter.png');
var body = 'The extension Twitter Creation Date is now Born for Twitter and has been updated to work with #newtwitter.';
var popup = window.webkitNotifications.createNotification(url, 'Twitter Creation Date Reborn', body);
popup.show();
localStorage.setItem('installed', 'true');
-}
-
-function getCacheName(id) {
- return 'cache_' + id + '_created_at';
}
View
@@ -1,53 +1,37 @@
// TODO: adds support for modals
var observer = new MutationSummary({
callback: handleProfileChange,
- queries: [
- { element: 'div.profile-card-inner' },
- { element: 'div.profile-modal' }
- ]
+ queries: [{ element: 'div.profile-card-inner' }]
});
function handleProfileChange(summaries) {
- // Full profile
- summaries[0].added.forEach(function(profile) {
+ // TODO: loop through summaries?
+ var summary = summaries[0];
+
+ summary.added.forEach(function(profile) {
var userId = profile.getAttribute('data-user-id');
- profile.className += ' ' + getProfileClassName(userId);
- chrome.extension.sendRequest(null, { userId: userId }, handleResponse);
- });
- // Profile modal
- summaries[1].added.forEach(function(modal) {
- var userId = modal.getElementsByClassName('js-action-profilemenu')[0].getAttribute('data-user-id');
- modal.getElementsByClassName('profile-modal-extended')[0].className += ' ' + getProfileClassName(userId);
+ profile.className += ' born-profile-' + userId;
chrome.extension.sendRequest(null, { userId: userId }, handleResponse);
});
}
function handleResponse(response) {
if (response.status === 200) {
- // TODO: clean up code
- var profilesOnPage = document.getElementsByClassName(getProfileClassName(response.data.userId));
+ // TODO: Clean up code
+ var d = document.createElement('span');
+ d.className = 'divider';
+ d.innerText = '·';
+ var profile = response.response;
+ var profilesOnPage = document.getElementsByClassName('born-profile-' + profile.id);
var s = document.createElement('span');
- s.innerText = 'Born ' + (new Date(response.data.createdAt)).toDateString();
- s.setAttribute('title', 'Born for Twitter created by @abraham');
+ var createdAt = new Date(profile.created_at);
+ s.innerText = 'Born ' + createdAt.toDateString();
+ s.setAttribute('title', 'Born created by @abraham');
var lnu = profilesOnPage[0].getElementsByClassName('location-and-url');
-
- // TODO: clean up if
- // Only add divider if there is a URL present
- if (lnu[0].getElementsByClassName('url')[0].getElementsByTagName('a')[0].getAttribute('href') !== '') {
- var d = document.createElement('span');
- d.className = 'divider';
- d.innerText = '· ';
- lnu[0].appendChild(d);
- }
-
- lnu[0].appendChild(s);
+ lnu[0].appendChild(d).parentNode.appendChild(s);
} else {
// TODO: display rate limit errors
// console.log('Error response');
// console.log(response);
}
-}
-
-function getProfileClassName(id) {
- return 'born-profile-' + id;
}
View
@@ -11,10 +11,7 @@
} ],
"description": "Display when a profile was born on twitter.com. Previously known as Twitter Creation Date.",
"permissions": [
- "https://*.twitter.com/*",
- "https://*.twitter.com/*",
- "http://twitter.com/*",
- "http://twitter.com/*",
+ "https://api.twitter.com/*",
"notifications"
],
"version": "2012.5.22",

0 comments on commit 98322f6

Please sign in to comment.