虾米wiki助手

帮助X友填充资料,目前仅支持deezer的部分自动填写。

  1. // ==UserScript==
  2. // @name 虾米wiki助手
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4.1
  5. // @description 帮助X友填充资料,目前仅支持deezer的部分自动填写。
  6. // @author XMAnon
  7. // @match *://emumo.xiami.com/wiki/addalbum*
  8. // @connect deezer.com
  9. // @grant GM_xmlhttpRequest
  10. // Done:
  11. // wiki页填入资料来源后,点击虾填,将自动填充专辑名,艺人,发行时间信息,公司
  12. // 目前仅支持deezer页面的地址
  13. // Planned:
  14. // BandCamp,MusicBrainz,Discogs,Spotify
  15. // Amazon JP, Download and Select Pic File
  16. //
  17. // ==/UserScript==
  18.  
  19. //虾米填专辑,根据参考资料页,自动填充
  20. (function() {
  21. 'use strict';
  22. //虾填:在添加专辑第一个页面,根据参考资料页面抓取信息
  23.  
  24. var editTime = function (rawTime) {
  25. var time = rawTime.split(' ');
  26. var output;
  27. console.log(time);
  28. var timeMode = [0,1]
  29. const charMM = ['January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
  30. const numMM = ['01','02','03','04','05','06','07','08','09','10','11','12'];
  31. if (charMM.indexOf(time[0]) >-1 ) //MM-DD-YYYY(US) e.g December 18, 1992
  32. {
  33. output = time[2] + '-' + numMM[(charMM.indexOf(time[0]))%12] + '-' + time[1].replace(',','');
  34. //console.log(output);
  35. return output
  36. }
  37. else if (charMM.indexOf(time[1]) >-1 )//DD-MM-YYYY(DE,IT,ES,FR) e.g. 18 December 1992 / 18. December 1992
  38. {
  39. output = time[2] + '-' + numMM[(charMM.indexOf(time[1]))%12] + '-' + time[0].replace('.','');
  40. //console.log((charMM.indexOf(time[1]),(charMM.indexOf(time[1]))%12));
  41. return output;
  42. }
  43. //YYYY/MM/DD (JP) --> YYYY/MM/DD
  44. }
  45. var getPage = '';//Text Page cache
  46. var getInfo = {
  47. title:'',
  48. artists:'',//could be multiple aka contributors
  49. release_date:'',
  50. label:''};//Json obj 专辑名 专辑艺人 发行时间 发行公司
  51. var getStatus;
  52. var getData = function (){
  53. var wikiUrl = document.getElementById("wiki").value;
  54. switch(true){
  55. case (wikiUrl.indexOf('deezer.com') > -1):
  56. //Deezer Album API: https://developers.deezer.com/api/album#infos e.g.https://api.deezer.com/album/xxxxxxxxx
  57. wikiUrl = "https://api.deezer.com/album/" + wikiUrl.split('/album/')[1].split('/')[0]//URL reformed to API
  58. break;
  59. //case (currentUrl.indexOf('bandcamp') > -1):
  60. default:
  61. console.warn('Host not matching');
  62. }
  63. var details = {
  64. method: "GET",
  65. url: wikiUrl,
  66. headers: {
  67. "User-Agent": "Mozilla/5.0", // If not specified, navigator.userAgent will be used.
  68. "Accept": "text/xml" // If not specified, browser defaults will be used.
  69. },
  70. onload: function(response) {
  71. var responseXML = null;
  72. // Inject responseXML into existing Object (only appropriate for XML content).
  73. if (!response.responseXML) {
  74. responseXML = new DOMParser()
  75. .parseFromString(response.responseText, "text/xml");
  76. }
  77. getPage = response.responseText;
  78. getStatus = response.status;
  79. var getJSON = JSON.parse(getPage);
  80. console.log('2 got response');
  81. console.log('response',response);
  82. console.log('getPage' ,getPage);
  83. console.log('getJSON' , getJSON);
  84. console.log('getInfo', getInfo);
  85. if (getStatus === 200) {
  86. switch(true){
  87. // case (wikiUrl.indexOf('amazon') > -1):
  88. // //专辑名 专辑艺人 发行时间 发行公司
  89. // console.log('1');
  90. // document.getElementById("title").value = getPage.split('dmusicProductTitle_feature_div')[1].split('</h1>')[0].split('<h1')[1].split('>')[1].replace(/&#039;/g,"'");//'会被转成ascii码,暂时只遇到了这一个问题,所以直接replace了
  91. // document.getElementById("artist").value = getPage.split('ProductInfoArtistLink')[1].split('</a>')[0].split('>')[1].replace(/ & /g,';').replace(/\n/g,'').replace(' feat. ',';').replace(/, /g,';');//只会feat.一次吧,遇到了再说
  92. // document.getElementById("publishtime").value = editTime(getPage.split('ProductInfoReleaseDate')[1].split('</span>')[0].split('>')[1].replace(/\n/g,''));
  93. // document.getElementById("company").value = getPage.split('productDetailsTable')[1].split('<li>')[2].split('</li>')[0].split('</strong> ')[1];
  94. // console.log('Information aquired!');
  95. // break;
  96. //case (currentUrl.indexOf('bandcamp') > -1):
  97. case (wikiUrl.indexOf('deezer.com') > -1):
  98. //专辑名 专辑艺人 发行时间 发行公司
  99. console.log('3 contents transferred');
  100. getInfo.title = getJSON.title;
  101. getInfo.release_date = getJSON.release_date;
  102. getInfo.label = getJSON.label;
  103. getInfo.artists = getJSON.contributors[0].name;
  104. if(getJSON.contributors.length > 0){
  105. for(let i =1;i<getJSON.contributors.length;i++){
  106. getInfo.artists = getInfo.artists + ';' + getJSON.contributors[i].name;
  107. }
  108. }
  109. document.getElementById("title").value = getInfo.title;//
  110. document.getElementById("artist").value = getInfo.artists;//
  111. document.getElementById("publishtime").value = getInfo.release_date;
  112. document.getElementById("company").value = getInfo.label;
  113. console.log('Information aquired!');
  114. break;
  115. //case (currentUrl.indexOf('bandcamp') > -1):
  116. default:
  117. console.warn('Host not matching');
  118. }
  119. }
  120. else {
  121. console.log('No data fetched!!');
  122. }
  123. }
  124. }
  125. GM_xmlhttpRequest(details);
  126. console.log('1 url fetched');
  127. }
  128. var xmBtn0 = document.createElement("input");
  129. xmBtn0.type = "button";
  130. xmBtn0.value = " 虾填 :P ";
  131. xmBtn0.style.color = "blue";
  132. xmBtn0.title = "点我,根据资料来源自动填充部分相关信息\n\n已支持: deezer";
  133. xmBtn0.onclick = getData;
  134. var wikinode = document.getElementById("wiki").parentNode;
  135. wikinode.appendChild(xmBtn0);
  136. //unsafeWindow.getData = getData;
  137. //虾抓,读取页面信息,生成曲目列表并存储于剪贴板,详见脚本二
  138.  
  139. })();

QingJ © 2025

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