Douban Programme

豆瓣歌单自动生成脚本

Stan na 24-07-2015. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name  Douban Programme
// @namespace https://malash.me/
// @author  Malash <[email protected]>
// @icon  http://img3.douban.com/favicon.ico
// @version 1.0.1
// @description 豆瓣歌单自动生成脚本
// @homepageURL https://github.com/malash/douban-programme
// @include http://music.douban.com/subject/*
// ==/UserScript==

!(function(window) {
    var _onload = window.onload;
    window.onload = function() {
        _onload && _onload();
        $ || ($ = jQuery);
        function make() {
            function getCk() {
                var cookies = document.cookie.split(';');
                cookies = cookies.filter(function(cookie) {
                    return $.trim(cookie).startsWith('ck=');
                });
                if (cookies.length === 0) {
                    return null;
                }
                var cookie = cookies[0];
                return cookie.substring(cookie.indexOf('=') + 2, cookie.length - 1);
            }
            var ck = getCk();
            if (!ck) {
                alert('请登录后操作');
                return;
            }
            var title = $('#wrapper h1 span').html();
            if (!title) {
                alert('请在专辑页面运行')
                return;
            }
            $.post('http://music.douban.com/j/songlist/create', { sl_title: title, ck:ck }, function(result) {
                if (result.r !== 'success') {
                    return;
                }
                var url = result.sl_url;
                var programmeID = parseInt(url.substring(url.lastIndexOf('/') + 1, url.length));
                console.log('添加收藏:', programmeID);
                var elItems = $('.song-item');
                for (var i = 0; i < elItems.length; i++) {
                    var songId = $(elItems[i]).attr('id');
                    $.ajax({
                        type: 'POST',
                        url: 'http://music.douban.com/j/songlist/addsong',
                        data: { sl_id: programmeID, song_id: songId, ck: ck },
                        async: false,
                        success: function(){
                            console.log('添加歌曲', i, ':', songId);
                        }
                    });
                    console.log('添加完成');
                    window.location.href = url;
                }
            })
        }

        if (!$('#wrapper h1 span').html()) {
            return;
        }
        $('<button>自动生成豆瓣歌单</button><span id="douban-programme"></span>').appendTo('#wrapper h1').click(function(){
            make();
        });
    }
 
})(window);