VRChat Web Analytic

Adds viewer to world members

当前为 2019-01-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name VRChat Web Analytic
  3. // @namespace e1on
  4. // @version 1.13
  5. // @description Adds viewer to world members
  6. // @author Loli e1on
  7. // @match https://vrchat.net/*
  8. // @grant https://vrchat.net/*
  9. // @require https://code.jquery.com/jquery-2.2.4.min.js
  10. // ==/UserScript==
  11.  
  12. function getCookie(name) {
  13. var matches = document.cookie.match(new RegExp(
  14. "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  15. ));
  16. return matches ? decodeURIComponent(matches[1]) : undefined;
  17. }
  18.  
  19. var cookieAuth = getCookie("auth");
  20. var xhr = new XMLHttpRequest();
  21.  
  22. if (cookieAuth != 'undefined') {
  23.  
  24. history.pushState = ( f => function pushState(){
  25. var ret = f.apply(this, arguments);
  26. window.dispatchEvent(new Event('pushState'));
  27. window.dispatchEvent(new Event('locationchange'));
  28. return ret;
  29. })(history.pushState);
  30. history.replaceState = ( f => function replaceState(){
  31. var ret = f.apply(this, arguments);
  32. window.dispatchEvent(new Event('replaceState'));
  33. window.dispatchEvent(new Event('locationchange'));
  34. return ret;
  35. })(history.replaceState);
  36. window.addEventListener('popstate',()=>{
  37. window.dispatchEvent(new Event('locationchange'))
  38. });
  39.  
  40. // Смена url
  41. window.addEventListener('locationchange', function(){
  42.  
  43. var path = location.pathname.split('/');
  44.  
  45. // world card
  46. if ((typeof path[2] !== "undefined") && (path[2] == 'world')) {
  47. if ((typeof path[3] !== "undefined")) {
  48.  
  49. var worldData = {};
  50. // get world info
  51. xhr.open("GET", "/api/1/worlds/"+path[3], true);
  52. xhr.onload = function (){
  53. worldData = JSON.parse(xhr.responseText);
  54. getAllUsers(worldData);
  55. }
  56. xhr.send(null);
  57.  
  58. }
  59. }
  60.  
  61. });
  62.  
  63. }
  64.  
  65. var data = {}; // instanceId => users
  66.  
  67. function getAllUsers (worldData) {
  68. if (worldData['instances'] !== 'undefined') {
  69.  
  70. worldData['instances'].forEach(function(item, i, arr) {
  71.  
  72. // get users info
  73. xhr.open("GET", "/api/1/worlds/"+worldData['id']+"/"+item[0], false);
  74. xhr.onload = function (){
  75. data[item[0]] = JSON.parse(xhr.responseText)['users'];
  76. }
  77. xhr.send(null);
  78.  
  79. });
  80.  
  81. render(worldData['id']);
  82.  
  83. }
  84. }
  85.  
  86. // слабонервным не смотреть
  87. function render (worldId) {
  88. $(document).ready(function() {
  89. var BreakException = {};
  90. try {
  91. Object.keys(data).forEach(function (item){
  92. var el = $('a[href="vrchat://launch?ref=vrchat.com&id='+worldId+':'+item+'"]');
  93.  
  94. if (el.length){
  95. data[item].forEach(function (item,i,arr){
  96. el.after('<a href="/home/user/'+item['id']+'" target="_blank" style="display: inline-block;font-size: 12px;width: 130px;text-align: center;background: #333333;border: 1px solid #333333;margin-bottom: 5px;"><img src="'+item['currentAvatarImageUrl']+'">'+item['displayName']+'</a>');
  97. });
  98. } else {
  99. render(worldId);
  100. throw BreakException;
  101. return;
  102. }
  103. });
  104. data={};
  105. } catch (e) {
  106. if (e !== BreakException) throw e;
  107. }
  108. });
  109. }