Created
December 31, 2015 07:28
-
-
Save laurivers/f373f4c59417f38cead8 to your computer and use it in GitHub Desktop.
Sync douban to goodreads
This file contains hidden or 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
| isReading = false; | |
| isWishing = false; | |
| isRead = false; | |
| xmlHttp = new XMLHttpRequest(); | |
| trySyncGoodReads(); | |
| state = document.getElementsByClassName("mr10")[0]; | |
| if (state == undefined) | |
| { | |
| // not marked | |
| return; | |
| } | |
| info = document.getElementById("info"); | |
| isbn = info.lastElementChild.previousSibling; | |
| isbn = isbn.data.substr(1); | |
| isReading = state.innerText == "我最近在读这本书"; | |
| isWishing = state.innerText == "我想读这本书"; | |
| isRead = state.innerText == "我读过这本书"; | |
| url = "http://www.goodreads.com/book/isbn_to_id/"+ isbn + "?key=[GOODREADS_APIKEY]"; | |
| xmlHttp.onreadystatechange = ProcessRequest; | |
| xmlHttp.open( "GET", url, true ); | |
| xmlHttp.send( null ); | |
| function ProcessRequest() | |
| { | |
| if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) | |
| { | |
| if ( xmlHttp.responseText != "No book with that ISBN" ) | |
| { | |
| shelfName = null | |
| if (isReading) | |
| shelfName = "currently-reading"; | |
| if (isWishing) | |
| shelfName = "to-read"; | |
| if (isRead) | |
| shelfName = "read"; | |
| bookId = xmlHttp.responseText; | |
| url = "http://www.goodreads.com/shelf/add_to_shelf.xml?name=" + shelfName + "&book_id=" + bookId | |
| xmlHttp.onreadystatechange = Result; | |
| xmlHttp.open( "GET", url, true ); | |
| xmlHttp.send( null ); | |
| } else | |
| { | |
| state.innerText += " ( Not found in goodreads )" | |
| } | |
| } | |
| } | |
| function Result() | |
| { | |
| if ( xmlHttp.readyState == 4 && xmlHttp.status == 200 ) | |
| { | |
| state.innerText += " ( Synced with goodreads )" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment