64 |
65 |
--------------------------------------------------------------------------------
/js/utility.js:
--------------------------------------------------------------------------------
1 | /*
2 | utility js code
3 |
4 | Copyright (C) 2012 QI Wen
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | */
19 |
20 | // select the content of specified element id
21 | function selectElementContents(id) {
22 | var el = document.getElementById(id);
23 | var body = document.body, range, sel;
24 | if (body.createTextRange) {
25 | range = body.createTextRange();
26 | range.moveToElementText(el);
27 | range.select();
28 | } else if (document.createRange && window.getSelection) {
29 | range = document.createRange();
30 | range.selectNodeContents(el);
31 | sel = window.getSelection();
32 | sel.removeAllRanges();
33 | sel.addRange(range);
34 | }
35 | }
36 |
37 | // show or hide div
38 | function showDiv(div_name, show) {
39 | if (show) {
40 | document.getElementById(div_name).style.visibility="visible";
41 | document.getElementById(div_name).style.display="";
42 | } else {
43 | document.getElementById(div_name).style.visibility="hidden";
44 | document.getElementById(div_name).style.display="none";
45 | }
46 | }
47 |
48 | // UTF8.encode(s): Converts from ANSI to UTF-8
49 | // UTF8.decode(s): Converts from UTF-8 to ANSI
50 | UTF8 = {
51 | encode: function(s){
52 | for(var c, i = -1, l = (s = s.split("")).length, o = String.fromCharCode; ++i < l;
53 | s[i] = (c = s[i].charCodeAt(0)) >= 127 ? o(0xc0 | (c >>> 6)) + o(0x80 | (c & 0x3f)) : s[i]
54 | );
55 | return s.join("");
56 | },
57 | decode: function(s){
58 | for(var a, b, i = -1, l = (s = s.split("")).length, o = String.fromCharCode, c = "charCodeAt"; ++i < l;
59 | ((a = s[i][c](0)) & 0x80) &&
60 | (s[i] = (a & 0xfc) == 0xc0 && ((b = s[i + 1][c](0)) & 0xc0) == 0x80 ?
61 | o(((a & 0x03) << 6) + (b & 0x3f)) : o(128), s[++i] = "")
62 | );
63 | return s.join("");
64 | }
65 | };
66 |
--------------------------------------------------------------------------------
/js/douban.js:
--------------------------------------------------------------------------------
1 | /*
2 | used to get HTML code(music information) from douban.com, and send message to background.html
3 |
4 | Copyright (C) 2014 Wen Qi
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | */
19 |
20 | function getElementsByClass(searchClass, domNode, tagName) {
21 | if (domNode == null)
22 | domNode = document;
23 | if (tagName == null)
24 | tagName = '*';
25 | var el = new Array();
26 | var tags = domNode.getElementsByTagName(tagName);
27 | var tcl = " " + searchClass + " ";
28 | for (i = 0, j = 0; i < tags.length; i++) {
29 | var test = " " + tags[i].className + " ";
30 | if (test.indexOf(tcl) != -1)
31 | el[j++] = tags[i];
32 | }
33 | return el;
34 | }
35 |
36 | function getContentAndPost() {
37 | var record_viewer = document.getElementById("record_viewer");
38 | if (!record_viewer) {
39 | alert("unexpected");
40 | return;
41 | }
42 |
43 | var bottom_pager = document.getElementById("bottom_pager");
44 | if (bottom_pager.innerText.length == 0) {
45 | setTimeout(getContentAndPost, 500);
46 | return;
47 | }
48 |
49 | var props = getElementsByClass("props", record_viewer);
50 | if (props.length == 0) {
51 | alert("empty list");
52 | }
53 |
54 | var info = {};
55 |
56 | var liked_or_banned = document.URL.match("liked");
57 | if (liked_or_banned) liked_or_banned = true;
58 |
59 | var startFromStr = document.URL.match(/[0-9]+/);
60 | if (!startFromStr || startFromStr.length <= 0) {
61 | alert("unexpected");
62 | return;
63 | }
64 | info.startFrom = new Number(startFromStr[0]);
65 |
66 | var target = liked_or_banned?"nav_liked":"nav_banned";
67 | var totalStr = document.getElementsByClassName("total").item(0).innerText.trim();
68 | if (totalStr && totalStr.length) {
69 | info.total = new Number(totalStr.substring(1, totalStr.length - 1));
70 | } else {
71 | alert("unexpected");
72 | return;
73 | }
74 |
75 | info.musics = [];
76 | for (var i = 0; i < props.length; ++i) {
77 | var prop = props[i];
78 | var musicName = getElementsByClass("song_title", prop);
79 | var performer = getElementsByClass("performer", prop);
80 | var source = prop.getElementsByTagName("a");
81 | var sourceURL = source[0].href;
82 | var sourceName = source[0].innerText;
83 | info.musics.push({
84 | "musicName" : musicName[0].innerText,
85 | "sourceURL" : sourceURL,
86 | "sourceName" : sourceName,
87 | "performer" : performer[0].innerText
88 | });
89 | }
90 | chrome.extension.connect().postMessage(info);
91 | }
92 |
93 | getContentAndPost();
94 |
--------------------------------------------------------------------------------
/js/FileSaver.min.js:
--------------------------------------------------------------------------------
1 | /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
2 | var saveAs=saveAs||function(e){"use strict";if(typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),i="download"in r,o=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},a=/Version\/[\d\.]+.*Safari/.test(navigator.userAgent),f=e.webkitRequestFileSystem,u=e.requestFileSystem||f||e.mozRequestFileSystem,s=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},c="application/octet-stream",d=0,l=1e3*40,w=function(e){var t=function(){if(typeof e==="string"){n().revokeObjectURL(e)}else{e.remove()}};setTimeout(t,l)},p=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var i=e["on"+t[r]];if(typeof i==="function"){try{i.call(e,n||e)}catch(o){s(o)}}}},v=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob(["",e],{type:e.type})}return e},y=function(t,s,l){if(!l){t=v(t)}var y=this,m=t.type,S=false,h,R,O=function(){p(y,"writestart progress write writeend".split(" "))},g=function(){if(R&&a&&typeof FileReader!=="undefined"){var r=new FileReader;r.onloadend=function(){var e=r.result;R.location.href="data:attachment/file"+e.slice(e.search(/[,;]/));y.readyState=y.DONE;O()};r.readAsDataURL(t);y.readyState=y.INIT;return}if(S||!h){h=n().createObjectURL(t)}if(R){R.location.href=h}else{var i=e.open(h,"_blank");if(i===undefined&&a){e.location.href=h}}y.readyState=y.DONE;O();w(h)},b=function(e){return function(){if(y.readyState!==y.DONE){return e.apply(this,arguments)}}},E={create:true,exclusive:false},N;y.readyState=y.INIT;if(!s){s="download"}if(i){h=n().createObjectURL(t);setTimeout(function(){r.href=h;r.download=s;o(r);O();w(h);y.readyState=y.DONE});return}if(e.chrome&&m&&m!==c){N=t.slice||t.webkitSlice;t=N.call(t,0,t.size,c);S=true}if(f&&s!=="download"){s+=".download"}if(m===c||f){R=e}if(!u){g();return}d+=t.size;u(e.TEMPORARY,d,b(function(e){e.root.getDirectory("saved",E,b(function(e){var n=function(){e.getFile(s,E,b(function(e){e.createWriter(b(function(n){n.onwriteend=function(t){R.location.href=e.toURL();y.readyState=y.DONE;p(y,"writeend",t);w(e)};n.onerror=function(){var e=n.error;if(e.code!==e.ABORT_ERR){g()}};"writestart progress write abort".split(" ").forEach(function(e){n["on"+e]=y["on"+e]});n.write(t);y.abort=function(){n.abort();y.readyState=y.DONE};y.readyState=y.WRITING}),g)}),g)};e.getFile(s,{create:false},b(function(e){e.remove();n()}),b(function(e){if(e.code===e.NOT_FOUND_ERR){n()}else{g()}}))}),g)}),g)},m=y.prototype,S=function(e,t,n){return new y(e,t,n)};if(typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob){return function(e,t,n){if(!n){e=v(e)}return navigator.msSaveOrOpenBlob(e,t||"download")}}m.abort=function(){var e=this;e.readyState=e.DONE;p(e,"abort")};m.readyState=m.INIT=0;m.WRITING=1;m.DONE=2;m.error=m.onwritestart=m.onprogress=m.onwrite=m.onabort=m.onerror=m.onwriteend=null;return S}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!==null){define([],function(){return saveAs})}
3 |
--------------------------------------------------------------------------------
/result.html:
--------------------------------------------------------------------------------
1 |
19 |
20 |
21 |
22 | 抓取结果
23 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
90 |
91 |
--------------------------------------------------------------------------------
/js/result.js:
--------------------------------------------------------------------------------
1 | /*
2 | js code for result.html
3 |
4 | Copyright (C) 2013 QI Wen
5 |
6 | This program is free software: you can redistribute it and/or modify
7 | it under the terms of the GNU General Public License as published by
8 | the Free Software Foundation, either version 3 of the License, or
9 | (at your option) any later version.
10 |
11 | This program is distributed in the hope that it will be useful,
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 | GNU General Public License for more details.
15 |
16 | You should have received a copy of the GNU General Public License
17 | along with this program. If not, see .
18 | */
19 |
20 | function wrap_url_tag_to_str(str, url) {
21 | if (url == null || url == '#') {
22 | return str;
23 | }
24 |
25 | return '' + str + '';
26 | }
27 |
28 | function getFullResult() {
29 | var musics = chrome.extension.getBackgroundPage().musics;
30 | var html = '';
31 |
32 | for (var i = 0; i < musics.length; ++i) {
33 | html += '