Add magnet to 115

try to take over the world!

  1. // ==UserScript==
  2. // @name Add magnet to 115
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author Jin Liu
  7. // @match http*://*/*
  8. // @grant GM_xmlhttpRequest
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function add_magnet_to_115(magnet) {
  15. GM_xmlhttpRequest({
  16. method: "POST",
  17. url: "http://localhost:3333/add-magnet-to-115",
  18. data: "param1=" + magnet,
  19. headers: {
  20. "Content-Type": "application/x-www-form-urlencoded"
  21. },
  22. onload: function (response) {
  23. if(response.status == 200) {
  24. alert("Added magnet to 115 successfully.");
  25. } else {
  26. alert(response.responseText);
  27. }
  28. },
  29. onerror: function (response) {
  30. alert(response.responseText);
  31. }
  32. });
  33. }
  34.  
  35. // 有些链接是动态加载的,所以设定了一个延时
  36. setTimeout(function() {
  37. inject();
  38. }, 2000);
  39.  
  40. function inject() {
  41. var links = document.querySelectorAll('a');
  42. Array.prototype.forEach.call(links, function(link) {
  43. var href;
  44. if (link.hasAttribute('href')) {
  45. href = link.getAttribute('href');
  46. if (href.startsWith("magnet:?") || href.startsWith("thunder://") || href.startsWith("ed2k://")) {
  47. var ele = document.createElement('a');
  48. ele.style.cssText = 'background: #2777F8 !important; border-radius: 3px !important; color: white !important; padding: 3px !important; margin: 2px !important; cursor: pointer !important';
  49. ele.innerHTML = '115';
  50. ele.addEventListener('click', function (e) {
  51. add_magnet_to_115(href);
  52. e.stopPropagation();
  53. }, false);
  54. link.parentNode.insertBefore(ele, link);
  55. }
  56. }
  57. });
  58.  
  59. }
  60.  
  61. })();
  62.