HookAjax Test

ww.soundsnap.com 铃声免费下载

  1. // HookAjax Test! example user script
  2. // version 0.1 BETA!
  3. // 2018-07-02
  4. // Copyright (c) 2018, 安静的猫
  5. // Released under the GPL license
  6. //
  7. // --------------------------------------------------------------------
  8. //
  9. // This is a Greasemonkey user script.
  10. //
  11. // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
  12. // Then restart Firefox and revisit this script.
  13. // Under Tools, there will be a new menu item to "Install User Script".
  14. // Accept the default configuration and install.
  15. //
  16. // To uninstall, go to Tools/Manage User Scripts,
  17. // select "HookAjax Test", and click Uninstall.
  18. //
  19. // --------------------------------------------------------------------
  20. //
  21. // ==UserScript==
  22. // @name HookAjax Test
  23. // @namespace http://diveintogreasemonkey.org/download/
  24. // @description ww.soundsnap.com 铃声免费下载
  25. // @require http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js
  26. // @require https://unpkg.com/ajax-hook/dist/ajaxhook.min.js
  27. // @include *
  28. // @exclude http://diveintogreasemonkey.org/*
  29. // @exclude http://www.diveintogreasemonkey.org/*
  30. // @run-at document-end
  31. // @version 0.1.201807021811
  32. // ==/UserScript==
  33. (function () {
  34. 'use strict';
  35. var regSound = 'www.soundsnap.com';
  36. hookAjax({
  37. onreadystatechange: function(xhr) {
  38. console.log("onreadystatechange called: %O", xhr)
  39. //return true
  40.  
  41. },
  42. onload: function(xhr) {
  43. console.log("onload called: %O", xhr)
  44. xhr.responseText = "hook" + xhr.responseText;
  45. //return true;
  46. },
  47. open: function(arg, xhr) {
  48. console.log("open called: method:%s,url:%s,async:%s", arg[0], arg[1], arg[2], xhr)
  49. // arg[1] += "?hook_tag=1";
  50. //统一添加请求头
  51.  
  52. },
  53. send: function(arg, xhr) {
  54. console.log("send called: %O", arg[0])
  55. xhr.setRequestHeader("_custom_header_", "ajaxhook")
  56. },
  57. setRequestHeader: function(arg, xhr) {
  58. console.log("setRequestHeader called!", arg)
  59. }
  60. });
  61.  
  62. if (location.host === regSound) {
  63. createDownloadAllElement();
  64. var items = document.getElementsByClassName("wave");
  65. var parentsItems = document.getElementsByClassName("ojoo-teaser");
  66. if (items.length > 0) {
  67. for (var i = 0; i < items.length; i++) {
  68. var curChild = getChildrenByName(items[i], 'audio');
  69. if (curChild && curChild.length > 0) {
  70. // var src = curChild[0].getAttribute('src')
  71. var src = curChild[0].src;
  72. var btn = createElement(src);
  73. parentsItems[i].style.position = 'relative';
  74. parentsItems[i].appendChild(btn)
  75. }
  76. }
  77. }
  78. }
  79.  
  80. function getChildrenByName(curEle, tagName) {
  81. var nodeList = curEle.childNodes;
  82. var ary = [],
  83. resultChild = [];
  84. if (/MSIE(6|7|8)/.test(navigator.userAgent)) {
  85. for (var i = 0; i < nodeList.length; i++) {
  86. var curNode = nodeList[i];
  87. if (curNode.nodeType === 1) {
  88. ary[ary.length] = curNode;
  89. }
  90. }
  91. } else {
  92. ary = Array.prototype.slice.call(curEle.children);
  93. }
  94. // 获取指定子元素
  95. if (typeof tagName === "string") {
  96. for (var k = 0; k < ary.length; k++) {
  97. var curTag = ary[k];
  98. if (curTag.nodeName.toLowerCase() === tagName.toLowerCase()) {
  99. resultChild.push(ary[k])
  100. }
  101. }
  102. }
  103. return resultChild;
  104. }
  105.  
  106. function createElement(src) {
  107. var ele = document.createElement("a");
  108. ele.setAttribute("href", src);
  109. ele.setAttribute("target", '_blank');
  110. ele.setAttribute("class", 'download-link');
  111. ele.style.color = "blue";
  112. ele.text = "下载";
  113. ele.style.position = 'absolute';
  114. ele.style.bottom = '44px';
  115. ele.style.left = '0px';
  116. return ele;
  117. }
  118.  
  119. function createDownloadAllElement() {
  120. var button = document.createElement("button");
  121. button.setAttribute("type", "button");
  122. button.setAttribute("class", "my-btn");
  123. button.setAttribute("value", "下载全部");
  124. button.setAttribute("onClick", "var itemsLink = document.getElementsByClassName('download-link'); if (itemsLink && itemsLink.length > 0) { for (var i = 0; i < itemsLink.length; i++) {itemsLink[i].click(); } }");
  125. button.style.width = "60px";
  126. button.style.height = "20px";
  127. button.style.borderRadius = "2px";
  128. button.style.align = "center";
  129. button.style.marginBottom = "4px";
  130. button.style.background = "#b46300";
  131. button.style.border = "1px solid #b46300";
  132. button.style.color = "white";
  133. button.style.position = 'absolute';
  134. button.style.bottom = '0px';
  135. button.style.left = '0px';
  136. button.innerText = '下载全部';
  137. var container = document.getElementsByClassName('search-results');
  138. if (container && container.length > 0) {
  139. container[0].style.position = 'relative';
  140. container[0].appendChild(button);
  141. }
  142. }
  143.  
  144. })();

QingJ © 2025

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