eduarddit

help Ed remember which link on reddit got him here
git clone https://wehaveforgeathome.hates.computer/eduarddit.git
Log | Files | Refs | LICENSE

commit e1b72a6fc72766e45a2e67997d981e97ff346a96
Author: Ryan Wolf <rwolf@borderstylo.com>
Date:   Mon, 28 Feb 2011 22:44:56 -0800

initial commit

Diffstat:
ALICENSE | 35+++++++++++++++++++++++++++++++++++
Aicon.png | 0
Amanifest.json | 13+++++++++++++
Apopup.html | 41+++++++++++++++++++++++++++++++++++++++++
4 files changed, 89 insertions(+), 0 deletions(-)

diff --git a/LICENSE b/LICENSE @@ -0,0 +1,35 @@ + The Romantic WTF public license. + -------------------------------- + a.k.a. version "<3" or simply v3 + + Dear user, + + Eduarddit, + Copyright 2010, Ryan Wolf <rwolf@borderstylo.com>, + | + | / -- + / -- + / + has been released + under the WTF public license version "<3". + I hereby grant you an irrevocable license to + do what the gentle caress you want to + with this lovely + / project. + / Love, + | / Ryan Wolf + |7L_ + + P.S.: Even though I poured my heart into this work, + I _cannot_ provide any warranty regarding + its fitness for _any_ purpose. You + acknowledge that I will not be held liable + for any damage its use could incur. + + +Icon Author: Fast Icon + +HomePage: http://www.fasticon.com +License: Commercial usage: Allowed + +The images or characters depicted in these icons are &copy; by Respective Copyright Owners diff --git a/icon.png b/icon.png Binary files differ. diff --git a/manifest.json b/manifest.json @@ -0,0 +1,13 @@ +{ + "name": "Eduarddit", + "version": "0.1", + "description": "help Ed remember which link on reddit got him here", + "browser_action": { + "default_icon": "icon.png", + "popup": "popup.html" + }, + "permissions": [ + "http://www.reddit.com/api/", + "tabs" + ] +} diff --git a/popup.html b/popup.html @@ -0,0 +1,41 @@ +... +<script> + var getPageUrl = function (callback) { + chrome.tabs.getSelected(null, function (tab) { callback(tab.url); }); + }; + var getRedditLinks = function (url, callback) { + var xhr = new XMLHttpRequest(); + xhr.open( + 'GET', + 'http://www.reddit.com/api/info.json?url=' + encodeURIComponent(url) + ); + xhr.onload = function () { + var response = JSON.parse(xhr.responseText); + callback(response.data.children); + }; + xhr.send(null); + }; + var displayLinks = function (links, callback) { + if (links.length == 0) { + document.body.textContent = 'nada'; + return; + } + var ul = document.createElement('ul'); + links.forEach(function (link) { + var a = document.createElement('a'); + a.href = 'http://www.reddit.com' + link.data.permalink; + a.textContent = link.data.title; + a.onclick = function () { callback(a.href); }; + var li = document.createElement('li'); + li.appendChild(a); + ul.appendChild(li); + }); + document.body.appendChild(ul); + document.body.removeChild(document.body.firstChild); + }; + getPageUrl(function (url) { + getRedditLinks(url, function (links) { + displayLinks(links, function (url) { chrome.tabs.create({ url: url }); }); + }); + }); +</script>