DsModDownloader

DS/DST mods directly downloader for tieba & steam

当前为 2016-01-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @author Aq
  3. // @name DsModDownloader
  4. // @namespace https://github.com/aqgithub/steamdl/blob/master/DsModDownloader.user.js
  5. // @description DS/DST mods directly downloader for tieba & steam
  6. // @include *steamcommunity.com/sharedfiles/filedetails/?id=*
  7. // @include *tieba.baidu.com/p/*
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_info
  10. // @require http://code.jquery.com/jquery-1.12.0.min.js
  11. // @supportURL https://github.com/aqgithub/steamdl/issues
  12. // @version 0.0.1
  13. // @license MIT
  14. // ==/UserScript==
  15. // 0.0.2 comming soon
  16. (function (w, d) {
  17. var API_GET_PUBLISHED_FILE_DETAILS = 'http://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v0001/';
  18. var curDomain = - 1; // 1 - tieba, 0 - steam
  19. function getDlUrl(modID, $dlButton) {
  20. GM_xmlhttpRequest({
  21. method: 'POST',
  22. url: API_GET_PUBLISHED_FILE_DETAILS,
  23. data: 'itemcount=1&publishedfileids[0]=' + modID + '&format=json',
  24. headers: {
  25. 'Content-Type': 'application/x-www-form-urlencoded'
  26. },
  27. onload: function (response) {
  28. data = $.parseJSON(response.responseText);
  29. console.log(data);
  30. var fileurl = data.response.publishedfiledetails[0].file_url;
  31. if (curDomain) {
  32. $dlButton.text(fileurl);
  33. }
  34. else {
  35. }
  36. },
  37. onerror: function (reponse) {
  38. //alert('error');
  39. console.log(reponse);
  40. }
  41. });
  42. };
  43. function htmlParser() {
  44. if (d.domain.toLowerCase().indexOf('baidu.com') > 0) {
  45. curDomain = 1;
  46. $(d).on('mouseover', '.d_post_content a,.lzl_content_main a', function (e) {
  47. var linkToAnyls = $(this).text();
  48. var pattern = /steamcommunity.com\D*([0-9]{2,15})/i;
  49. var modID = pattern.exec(linkToAnyls);
  50. modID && $(this).after('<span class="aq_id" style="cursor:default;color:blue;margin-left:3px;margin-right:2px">' + modID[1] + '</span>|<span class="aq_dl" style="cursor:pointer;color:red;margin-left:2px;margin-right:2px;">解析中...</span>|<span class="aq_lnk" style="cursor:pointer;color:blue;margin-left:2px;margin-right:3px">转到steam页面</span>').hide();
  51. getDlUrl(modID[1], $(this).next().next());
  52. });
  53. $(d).on('click', '.aq_dl', function (e) {
  54. window.location.href = $(this).html();
  55. });
  56. $(d).on('click', '.aq_lnk', function (e) {
  57. window.location.href = 'http://steamcommunity.com/sharedfiles/filedetails/?id=' + $(this).prev().prev().text();
  58. });
  59. }
  60. else if (d.domain.toLowerCase().indexOf('steamcommunity.com') > 0) {
  61. //not support yet
  62. curDomain = 0;
  63. }
  64. else {
  65. }
  66. }
  67. htmlParser();
  68. }) (window, document, undefined);