Steam: add Youtube trailer link

Adds a link to search for the trailer on Youtube after the app title

目前为 2015-03-20 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Steam: add Youtube trailer link
  3. // @include http://store.steampowered.com/app/*
  4. // @include https://store.steampowered.com/app/*
  5. // @description Adds a link to search for the trailer on Youtube after the app title
  6. // @version 1.0
  7. // @author wOxxOm
  8. // @namespace wOxxOm.scripts
  9. // @license MIT License
  10. // @grant none
  11. // @run-at document-start
  12. // ==/UserScript==
  13.  
  14. setMutationHandler(document, '.apphub_AppName', function(observer, node) {
  15. var yt = document.createElement('div');
  16. var link = 'https://www.youtube.com/results?search_query=' + node.textContent.replace(' ','+') + '+trailer';
  17. node.parentNode.insertBefore(yt, node);
  18. yt.outerHTML =
  19. '<div class="apphub_OtherSiteInfo" style="margin-right:1em">\
  20. <a class="btnv6_blue_hoverfade btn_medium" href="' + link + '">\
  21. <span>trailer on Youtube</span>\
  22. </a>\
  23. </div>';
  24. observer.disconnect();
  25. return false;
  26. });
  27.  
  28. function setMutationHandler(baseNode, selector, cb) {
  29. var ob = new MutationObserver(function(mutations){
  30. for (var i=0, ml=mutations.length, m; (i<ml) && (m=mutations[i]); i++)
  31. for (var j=0, nodes=m.addedNodes, nl=nodes.length, n; (j<nl) && (n=nodes[j]); j++)
  32. if (n.nodeType == 1)
  33. if (n = n.querySelector(selector))
  34. if (!cb(ob, n))
  35. return;
  36. });
  37. ob.observe(baseNode, {subtree:true, childList:true});
  38. }