InstaSynchP Library

Basic function that are needed by several scripts use with @require

2014-10-17 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greasyfork.org/scripts/5647/21675/InstaSynchP%20Library.js

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला 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        InstaSynchP Library
// @namespace   InstaSynchP
// @description Basic function that are needed by several scripts use with @require

// @version     1.0.4
// @author      Zod-
// @source      https://github.com/Zod-/InstaSynchP-Library
// @license     GPL-3.0

// @include     http://*.instasynch.com/*
// @include     http://instasynch.com/*
// @include     http://*.instasync.com/*
// @include     http://instasync.com/*
// @grant       none
// @run-at      document-start
// ==/UserScript==

if (!window.pluginLibrary) {
    //http://joquery.com/2012/string-format-for-javascript
    if (typeof String.prototype.format !== 'function') {
        String.prototype.format = function () {
            // The string containing the format items (e.g. "{0}")
            // will and always has to be the first argument.
            var theString = this,
                i,
                regEx;

            // start with the second argument (i = 1)
            for (i = 0; i < arguments.length; i += 1) {
                // "gm" = RegEx options for Global search (more than one instance)
                // and for Multiline search
                regEx = new RegExp("\\{" + (i) + "\\}", "gm");
                theString = theString.replace(regEx, arguments[i]);
            }
            return theString;
        };
    }
    //http://stackoverflow.com/a/646643
    if (typeof String.prototype.startsWith !== 'function') {
        // see below for better implementation!
        String.prototype.startsWith = function (str) {
            return this.indexOf(str) === 0;
        };
    }

    window.isBlackname = function (username) {
        "use strict";
        if (typeof username !== 'string') {
            return false;
        }
        return username.match(/^([A-Za-z0-9]|([\-_](?![\-_]))){5,16}$/) !== null;
    };

    window.activeVideoIndex = function () {
        "use strict";
        return $('#playlist .active').index();
    };

    window.findUserId = function (id) {
        "use strict";
        var i;
        for (i = 0; i < window.users.length; i += 1) {
            if (id === window.users[i].id) {
                return window.users[i];
            }
        }
        return undefined;
    };
    window.findUserName = function (name) {
        "use strict";
        var i;
        for (i = 0; i < window.users.length; i += 1) {
            if (name === window.users[i].name) {
                return window.users[i];
            }
        }
        return undefined;
    };

    window.videojs = function () {
        "use strict";
        return $('.video-js')[0];
    };

    window.reloadPlayer = function () {
        "use strict";
        if (window.video) {
            window.video.destroy();
        }
        window.global.sendcmd('reload', null);
    };

    window.addSystemMessage = function (message) {
        "use strict";
        window.addMessage({
            username: ""
        }, message, 'system');
    };

    window.addErrorMessage = function (message) {
        "use strict";
        window.addMessage({
            username: ""
        }, message, 'errortext');
    };

    window.videoInfoEquals = function (a, b) {
        "use strict";
        if (!a || !b) {
            return false;
        }
        if (a.provider && a.provider === b.provider &&
            a.mediaType && a.mediaType === b.mediaType &&
            a.id && a.id === b.id) {
            return true;
        }
        return false;
    };
    window.pluginLibrary = true;
}