Skip to content

Instantly share code, notes, and snippets.

@Sakurina
Created June 13, 2012 05:45
Show Gist options
  • Save Sakurina/2922099 to your computer and use it in GitHub Desktop.
Save Sakurina/2922099 to your computer and use it in GitHub Desktop.
onsen - opens the currently playing song for the specified niconico sound entertainment networks (Nsen) channel in the niconico douga iOS app, for MyScripts
# onsen
# API URL
channel = 'lv96524916' # nicoindies
url = "http://live.nicovideo.jp/nsendata?v=#{channel}"
# HELPERS
last = (a) -> a[a.length-1]
id_for_url = (url) -> last url.split('/')
# MAIN
xhr = new XMLHttpRequest()
xhr.open "GET", url, false
xhr.send()
nico_json = JSON.parse xhr.responseText
document.body.innerHTML = nico_json["playing"]
links = document.getElementsByTagName 'a'
last_link = last links
link_url = last_link.getAttribute "href"
link_id = id_for_url link_url
return "nicovideo://#{link_id}"
(function(){var b,a;b=function(a){return a[a.length-1]};a=new XMLHttpRequest;a.open("GET","http://live.nicovideo.jp/nsendata?v=lv96524916",!1);a.send();a=JSON.parse(a.responseText);document.body.innerHTML=a.playing;return"nicovideo://"+function(a){return b(a.split("/"))}(b(document.getElementsByTagName("a")).getAttribute("href"))}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment