5sing Assist

修改 5sing 歌曲页面下载按钮链接为真实歌曲链接。

  1. // ==UserScript==
  2. // @name 5sing Assist
  3. // @namespace http://example.com
  4. // @description 修改 5sing 歌曲页面下载按钮链接为真实歌曲链接。
  5. // @include http://5sing.kugou.com/yc/*
  6. // @include http://5sing.kugou.com/fc/*
  7. // @include http://5sing.kugou.com/bz/*
  8. // @run-at document-end
  9. // @grant none
  10. // @author xiofee <xiofee@gmail.com>
  11. // @version 0.2
  12. // @copyright 2014-2016,xiofee
  13. // ==/UserScript==
  14. /* History
  15. * 2014-12-18 v0.1 首个版本 | The first version.
  16. * 2016-06-06 v0.2 依然可用,只是改个版本号,刷个存在感。 | Still available, only changed version number.
  17. */
  18. /**
  19. *
  20. * Base64 encode / decode
  21. *
  22. * @author haitao.tu
  23. * @date 2010-04-26
  24. * @email tuhaitao@foxmail.com
  25. *
  26. */
  27. (function() {
  28. function Base64() {
  29. // private property
  30. _keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  31. // public method for decoding
  32. this.decode = function (input) {
  33. var output = '';
  34. var chr1,
  35. chr2,
  36. chr3;
  37. var enc1,
  38. enc2,
  39. enc3,
  40. enc4;
  41. var i = 0;
  42. input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
  43. while (i < input.length) {
  44. enc1 = _keyStr.indexOf(input.charAt(i++));
  45. enc2 = _keyStr.indexOf(input.charAt(i++));
  46. enc3 = _keyStr.indexOf(input.charAt(i++));
  47. enc4 = _keyStr.indexOf(input.charAt(i++));
  48. chr1 = (enc1 << 2) | (enc2 >> 4);
  49. chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
  50. chr3 = ((enc3 & 3) << 6) | enc4;
  51. output = output + String.fromCharCode(chr1);
  52. if (enc3 != 64) {
  53. output = output + String.fromCharCode(chr2);
  54. }
  55. if (enc4 != 64) {
  56. output = output + String.fromCharCode(chr3);
  57. }
  58. }
  59. output = _utf8_decode(output);
  60. return output;
  61. }
  62. // private method for UTF-8 decoding
  63.  
  64. _utf8_decode = function (utftext) {
  65. var string = '';
  66. var i = 0;
  67. var c = c1 = c2 = 0;
  68. while (i < utftext.length) {
  69. c = utftext.charCodeAt(i);
  70. if (c < 128) {
  71. string += String.fromCharCode(c);
  72. i++;
  73. } else if ((c > 191) && (c < 224)) {
  74. c2 = utftext.charCodeAt(i + 1);
  75. string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
  76. i += 2;
  77. } else {
  78. c2 = utftext.charCodeAt(i + 1);
  79. c3 = utftext.charCodeAt(i + 2);
  80. string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
  81. i += 3;
  82. }
  83. }
  84. return string;
  85. }
  86. };
  87. function isListenPage() {
  88. var _isListen = false;
  89. // Listen mode page not use pageOptions.
  90. if ('undefined' == typeof pageOptions) {
  91. _isListen = true;
  92. }
  93. return _isListen;
  94. }
  95. function getEncryptSongInfo() {
  96. var _info;
  97. if (isListenPage()) {
  98. // Listen mode page
  99. _info = globals.ticket;
  100. } else {
  101. // Normal mode page
  102. _info = pageOptions.ticket;
  103. }
  104. var _base64 = new Base64();
  105. var _songObj = eval('(' + _base64.decode(_info) + ')');
  106. return _songObj;
  107. }
  108. function getRealSongUrl() {
  109. var _songInfo = getEncryptSongInfo();
  110. return _songInfo.file;
  111. }
  112. function getDownloadButton() {
  113. var _downBtn;
  114. if (isListenPage()) {
  115. _downBtn = document.getElementById('func_Down');
  116. } else {
  117. _downBtn = document.getElementsByClassName('func_icon3') [0];
  118. _downBtn = _downBtn.getElementsByTagName('a') [0];
  119. }
  120. return _downBtn;
  121. }
  122. var downBtn = getDownloadButton();
  123. downBtn.href = getRealSongUrl();
  124. })();