Revisions
-
kejun renamed this gist
Jan 12, 2011 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
kejun created this gist
Jan 12, 2011 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ // ==UserScript== // @name douban_xiami // @namespace org.kejun // @include http://music.douban.com/* // ==/UserScript== //使用说明: // 1. 安装本脚本到Greasemonkey // 2. 到http://music.douban.com/recommended // 3. 点击专辑封面会自动用虾米播放(如果窗口没弹出,检查是否被浏览器拦截) var api = 'http://www.xiami.com/ajax/search-index?key={QUERY}', getAlbumInfo = function(name, cb) { GM_xmlhttpRequest({ method: 'GET', url: api.replace('{QUERY}', name), onload: function(xhr) { cb(xhr); } }); }, handleClick = function(e) { var el = e.target, cd_name; if (el.nodeType > 1) { return; } if (el.tagName.toLowerCase() !== 'img') { return; } cd_name = el.getAttribute('alt'); if (!cd_name || cd_name.indexOf('-') === -1) { return; } e.preventDefault(); e.stopPropagation(); cd_name = encodeURIComponent(cd_name.replace(/\s|-/g, '+').replace(/[+]{2,}/g, '+')); getAlbumInfo(cd_name, function(xhr){ if (xhr.responseText === '') { alert('虾米没有他们的歌'); return; } var songid = xhr.responseText.match(/\"\/album\/(\d+)\"/); if (!songid[1]) { alert('虾米没有他们的专辑'); return; } window.open('http://www.xiami.com/song/play?ids=/song/playlist/id/' + songid[1] + '/type/1','xm_player','width=760,height=560'); }); }; document.body.addEventListener('click', handleClick, false);