Last active
August 29, 2015 14:09
-
-
Save tranch/f3740b1d79dcf27a6cbf to your computer and use it in GitHub Desktop.
虾米音乐下载 Grease Monkey 插件。
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
| // ==UserScript== | |
| // @name 虾米音乐下载 | |
| // @namespace tranch | |
| // @description 替换下载按钮的链接 | |
| // @include http://www.xiami.com/album/* | |
| // @include http://www.xiami.com/song/* | |
| // @version 0.06 | |
| // @grant none | |
| // ==/UserScript== | |
| (function (d, l) { | |
| var buttons, button, i, attr_val, attr_key='onclick'; | |
| if (l.href.contains('/song/')) { | |
| buttons = d.querySelectorAll('li.do_download a'); | |
| } else if (l.href.contains('/album/')) { | |
| buttons = d.querySelectorAll('a.song_download'); | |
| } | |
| for (i = 0; button = buttons[i]; i++) { | |
| if (attr_val = button.getAttribute(attr_key)) { | |
| if (attr_val.contains('xm_download')) { | |
| button.removeAttribute(attr_key); | |
| button.setAttribute('data-song_id', attr_val.replace(/[^\d]/g, '')); | |
| button.addEventListener('click', function() { | |
| $.getJSON('http://songs.sinaapp.com/apiv3.php?id=' + this.getAttribute('data-song_id') + '&callback=?', function(data) { | |
| l.href = data.location; | |
| }); | |
| }); | |
| } | |
| } | |
| } | |
| })(document, location); |
lizheming
commented
Apr 15, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment