doubanFM2search

doubanFM searching in other music website

  1. // ==UserScript==
  2. // @name doubanFM2search
  3. // @namespace https://gf.qytechs.cn/zh-CN/scripts/11674-doubanfm2netease
  4. // @version 1.1
  5. // @description doubanFM searching in other music website
  6. // @author xavier skip
  7. // @match *://douban.fm/*
  8. // @match *://fm.douban.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. function addGlobalStyle(css) {
  13. var head, style;
  14. head = document.getElementsByTagName('head')[0];
  15. if (!head) { return; }
  16. style = document.createElement('style');
  17. style.type = 'text/css';
  18. style.innerHTML = css;
  19. head.appendChild(style);
  20. }
  21.  
  22.  
  23. function FM(){
  24. //不知道为什么豆瓣存储的信息song.artist和song.album总是一样的
  25. return{
  26. check: function(){
  27. var e = document.querySelector('.send-song-to-phone');
  28. this.version = e?1:2;
  29. return this.version;
  30. },
  31. v1: function(){
  32. var info = JSON.parse(window.localStorage.getItem('bubbler_song_info'));
  33. return {
  34. song: info.song_name,
  35. album: info.album,
  36. artist: info.artist
  37. };
  38. },
  39. v2: function(){
  40. var info = JSON.parse(window.localStorage.getItem('simpleStorage'))['douradio-player-state'].current_song;
  41. return {
  42. song: info.title,
  43. album: info.albumtitle ,
  44. artist: info.artist
  45. };
  46. },
  47. search_info: function(){
  48. var v = this.check();
  49. var info;
  50. if ( v == 1 ) {
  51. info = this.v1();
  52. }else{
  53. info = this.v2();
  54. }
  55. return this.search_keywords(info);
  56. },
  57. search_keywords: function(info){
  58. var keywords = "";
  59. var separator = " | ";
  60. if(info.song.length>30){
  61. keywords = info.song;
  62. }else if( (info.song.length + info.album.length)>40){
  63. keywords = [info.song, info.album].join(separator);
  64. }else{
  65. keywords = [info.song, info.album, info.artist].join(separator);
  66. }
  67. return keywords;
  68. },
  69. element :function(data){
  70. var that = this; // import
  71. var a = document.createElement('a');
  72. a.target="_blank";
  73. a.innerText = data['title'];
  74. a.addEventListener("click",function(e){
  75. a.href = data['search']+ encodeURIComponent(that.search_info());
  76. e.stopImmediatePropagation();
  77. }, true);
  78. return a;
  79. },
  80. elements: function(){
  81. var div = document.createElement('div');
  82. div.className = "fm2search";
  83. for (var d in search_data){
  84. var p = document.createElement('p');
  85. p.appendChild(this.element(search_data[d][0]));
  86. div.appendChild(p);
  87. }
  88. return div;
  89. }
  90. };
  91. }
  92.  
  93. var search_data = {
  94. 'netease': [{
  95. "title": "网易",
  96. "search": "//music.163.com/#/search/m/?s=",
  97. }],
  98. 'xiami': [{
  99. "title": "虾米",
  100. "search": "//www.xiami.com/search?key=",
  101. }],
  102. 'qq': [{
  103. "title": "QQ",
  104. "search":"//y.qq.com/portal/search.html#&w=",
  105. }],
  106. }
  107.  
  108.  
  109. // set css
  110. addGlobalStyle("\
  111. .fm2search{color:#888;z-index:9999;margin-top: 9px;}\
  112. .fm2search a:hover{background:0;color:#5b9;}\
  113. .fm2search p {display: inline; margin-right:16px;}");
  114.  
  115. // init
  116. var fm = new FM();
  117. var insert_queryname = '.sub-buttons-wrapper';
  118. var again = function(){
  119. var content = document.querySelector(insert_queryname);
  120. if(content){
  121. content.appendChild(fm.elements());
  122. console.log('appendChild', content);
  123. }else{
  124. console.log('again', content);
  125. setTimeout(again, 700);
  126. }
  127. };
  128.  
  129. // main
  130. again();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址