InstaSynchP Library

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

当前为 2014-10-18 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/5647/21773/InstaSynchP%20Library.js

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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.5
// @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==

//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;
    };
}

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

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

function findUserId(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;
}

function findUserName(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;
}

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

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

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

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

function videoInfoEquals(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;
}