Skip to content

Instantly share code, notes, and snippets.

@xl1
Last active October 4, 2015 00:58
Show Gist options
  • Save xl1/2550213 to your computer and use it in GitHub Desktop.
Save xl1/2550213 to your computer and use it in GitHub Desktop.
open phone2chrome last synced page (Chrome extention)
PAGES_URL = "http://dl.dropboxusercontent.com/s/***/pages" # Dropbox/phone2chrome/pages
openedURLs = []
getPages = (callback) ->
xhr = new XMLHttpRequest()
xhr.open 'GET', PAGES_URL, true
xhr.onload = ->
text = xhr.responseText
start = text.indexOf '{'
last = text.lastIndexOf '}'
callback text[start..last]
xhr.send()
openPage = ->
getPages (json) ->
pages = (JSON.parse json).pages
while pages.length > 0
lastPage = pages.pop()
if lastPage.url not in openedURLs
openedURLs.push lastPage.url
chrome.tabs.create { url: lastPage.url }
return
chrome.browserAction.onClicked.addListener openPage
{
"name": "phone2chrome last synced page",
"version": "1.0",
"manifest_version": 2,
"browser_action": {
"default_icon": "icon.png"
},
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"tabs",
"http://dl.dropboxusercontent.com/"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment