soup.io_force_working_asset_hosts

Right now soup.io have problem with many image hosts which results in nearly half of the images being not displayed. Here's a workaround - force browser to use known-to-be-working asset hosts.

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

  1. // ==UserScript==
  2. // @name soup.io_force_working_asset_hosts
  3. // @namespace http://animeisouronlysalvationfromthehorrorofexistence.soup.io/
  4. // @include http://*soup.io/*
  5. // @include https://*soup.io/*
  6. // @include http://*soup.universe-factory.net*
  7. // @description Right now soup.io have problem with many image hosts which results in nearly half of the images being not displayed. Here's a workaround - force browser to use known-to-be-working asset hosts.
  8. // @version 5
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12.  
  13. // A list of known to be working asset hosts.
  14. var working_hosts = [ 'asset-0', 'asset-1', 'asset-2', 'asset-3', 'asset-4', 'asset-5' ];
  15. var regex = new RegExp("asset-[^012345]", "g");
  16.  
  17. function force_working_asset_hosts(){
  18. var tags = document.getElementsByTagName('img');
  19. var anchors = document.getElementsByTagName('a');
  20. var links = document.getElementsByTagName('link');
  21.  
  22. for (var i = 0; i < tags.length; i++) {
  23. var rand_host = working_hosts[Math.floor(Math.random()*working_hosts.length)];
  24. tags[i].src = tags[i].src.replace(regex, rand_host);
  25. }
  26.  
  27. for (var i = 0; i < anchors.length; i++) {
  28. var rand_host = working_hosts[Math.floor(Math.random()*working_hosts.length)];
  29. anchors[i].href = anchors[i].href.replace(regex, rand_host);
  30. }
  31.  
  32. for (var i = 0; i < links.length; i++) {
  33. var rand_host = working_hosts[Math.floor(Math.random()*working_hosts.length)];
  34. links[i].href = links[i].href.replace(regex, rand_host);
  35. }
  36. }
  37.  
  38. force_working_asset_hosts();
  39.  
  40. var observer = new MutationObserver(function(mutations) {
  41. force_working_asset_hosts();
  42. });
  43.  
  44. var config = { attributes: true, childList: true, characterData: true };
  45. var target = document.getElementById('more_history');
  46. observer.observe(target, config);
  47.