VRChat WEB Shorthand

Adds shorthands for web site features. (Quick launch world and invite buttons for friends list)

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         VRChat WEB Shorthand
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds shorthands for web site features. (Quick launch world and invite buttons for friends list)
// @author       slick
// @match        https://www.tampermonkey.net/index.php?version=4.10.6105&ext=fire&updated=true
// @grant        none
// @require http://code.jquery.com/jquery-3.4.1.min.js
// @include      /.*?:\/\/.*?vrchat.*?\..*?(home|launch|api).*?/
// ==/UserScript==

(function() {
    'use strict';

    var limitReshreshMs = 1000;
    var lastRefresh = Date.now();

    $(document).ready(setTimeout(function() {
        addLaunchButton();
        //addRefreshButton();

        setDOMEvent(".friend-container", addLaunchButton);
        setDOMEvent(".location-container", addLaunchButton);
        setDOMEvent(".home-content", addLaunchButton);
    }, 3000));

    function setDOMEvent(element, callback) {
      $("body").on('DOMSubtreeModified', element, function() {
            setTimeout(function() {callback();}, 200);
      });
    }

    function addLaunchButton() {
      if(!canRefresh()) return;

      $( ".launchb" ).remove();
      $('.location-title').each(function( index ) {
            var webLink = $( this ).children()[1].href;
            var link = webLink.substring(webLink.indexOf('=')+1, webLink.lastIndexOf('&'));
            var instanceId = webLink.substring(webLink.lastIndexOf('=')+1);
            var fullLink = link + ":" + instanceId;
            var launchButton = '<div class="launchb"><br><a href="vrchat://launch?ref=vrchat.com&id=' + fullLink + '" class="btn btn-primary launch-btn" style="padding: 2px 2px;">LAUNCH WORLD</a></div>';

            $(this).append(launchButton);
      });
    }

    function addRefreshButton() {
      var refreshButton = '<span id="refreshb" style="margin-left: 5px"><a class="btn btn-secondary" title="Refresh" href="#"><span class="fa fa-sync-alt"></span>&nbsp; Refresh</a></span>';
      $('.navbar-header').append(refreshButton);
      $("#refreshb").click (addLaunchButton);
    }

    function canRefresh() {
      if((Date.now() - lastRefresh) >= limitReshreshMs) {
        lastRefresh = Date.now();
        return true;
      }
      return false;
    }
})();