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. // @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.
  7. // @version 5
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11.  
  12. // A list of known to be working asset hosts.
  13. var working_hosts = [ 'asset-0', 'asset-1', 'asset-2', 'asset-3', 'asset-4', 'asset-5' ];
  14. var regex = new RegExp("asset-[^012345]", "g");
  15.  
  16. function force_working_asset_hosts(){
  17. var tags = document.getElementsByTagName('img');
  18. var anchors = document.getElementsByTagName('a');
  19. var links = document.getElementsByTagName('link');
  20.  
  21. for (var i = 0; i < tags.length; i++) {
  22. var rand_host = working_hosts[Math.floor(Math.random()*working_hosts.length)];
  23. tags[i].src = tags[i].src.replace(regex, rand_host);
  24. }
  25.  
  26. for (var i = 0; i < anchors.length; i++) {
  27. var rand_host = working_hosts[Math.floor(Math.random()*working_hosts.length)];
  28. anchors[i].href = anchors[i].href.replace(regex, rand_host);
  29. }
  30.  
  31. for (var i = 0; i < links.length; i++) {
  32. var rand_host = working_hosts[Math.floor(Math.random()*working_hosts.length)];
  33. links[i].href = links[i].href.replace(regex, rand_host);
  34. }
  35. }
  36.  
  37. force_working_asset_hosts();
  38.  
  39. var observer = new MutationObserver(function(mutations) {
  40. force_working_asset_hosts();
  41. });
  42.  
  43. var config = { attributes: true, childList: true, characterData: true };
  44. var target = document.getElementById('more_history');
  45. observer.observe(target, config);
  46.